jdk/src/share/classes/javax/management/modelmbean/ModelMBeanNotificationInfo.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 526 61ba2d5ea9da
child 1513 d09513aaa9da
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 526
diff changeset
     2
 * Portions Copyright 2000-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @author    IBM Corp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * Copyright IBM Corp. 1999-2000.  All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
package javax.management.modelmbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import static com.sun.jmx.defaults.JmxProperties.MODELMBEAN_LOGGER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.jmx.mbeanserver.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.ObjectStreamField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.logging.Level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.Descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.DescriptorAccess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.management.MBeanNotificationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.management.RuntimeOperationsException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * The ModelMBeanNotificationInfo object describes a notification emitted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * by a ModelMBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * It is a subclass of MBeanNotificationInfo with the addition of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * associated Descriptor and an implementation of the Descriptor interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * The fields in the descriptor are defined, but not limited to,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * name           : notification name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * descriptorType : must be "notification"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * severity       : 0-6 where 0: unknown; 1: non-recoverable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *                  2: critical, failure; 3: major, severe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *                  4: minor, marginal, error; 5: warning;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *                  6: normal, cleared, informative
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * messageID      : unique key for message text (to allow translation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *                  analysis)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * messageText    : text of notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * log            : T - log message F - do not log message
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * logfile        : string fully qualified file name appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *                  operating system
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * visibility     : 1-4 where 1: always visible 4: rarely visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * presentationString : xml formatted string to allow presentation of data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * The default descriptor contains the name, descriptorType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * displayName and severity(=6) fields.  The default value of the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * and displayName fields is the name of the Notification class (as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * specified by the <code>name</code> parameter of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * ModelMBeanNotificationInfo constructor).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <p>The <b>serialVersionUID</b> of this class is <code>-7445681389570207141L</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
// Sun Microsystems, Sept. 2002: Revisited for JMX 1.2 (DF)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
@SuppressWarnings("serial")  // serialVersionUID is not constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
public class ModelMBeanNotificationInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    extends MBeanNotificationInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    implements DescriptorAccess {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // Serialization compatibility stuff:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // Two serial forms are supported in this class. The selected form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    // depends on system property "jmx.serial.form":
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    //  - "1.0" for JMX 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    //  - any other value for JMX 1.1 and higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    // Serial version for old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private static final long oldSerialVersionUID = -5211564525059047097L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    // Serial version for new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private static final long newSerialVersionUID = -7445681389570207141L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    // Serializable fields in old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private static final ObjectStreamField[] oldSerialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
      new ObjectStreamField("notificationDescriptor", Descriptor.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
      new ObjectStreamField("currClass", String.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    // Serializable fields in new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private static final ObjectStreamField[] newSerialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
      new ObjectStreamField("notificationDescriptor", Descriptor.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    // Actual serial version and serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private static final long serialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @serialField notificationDescriptor Descriptor The descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *   containing the appropriate metadata for this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private static final ObjectStreamField[] serialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private static boolean compat = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            String form = AccessController.doPrivileged(act);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            compat = (form != null && form.equals("1.0"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            // OK: No compat with 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        if (compat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            serialPersistentFields = oldSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            serialVersionUID = oldSerialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            serialPersistentFields = newSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            serialVersionUID = newSerialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    // END Serialization compatibility stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @serial The descriptor containing the appropriate metadata for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *         this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private Descriptor notificationDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private static final String currClass = "ModelMBeanNotificationInfo";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Constructs a ModelMBeanNotificationInfo object with a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param notifTypes The array of strings (in dot notation) containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *     the notification types that may be emitted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param name The name of the Notification class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param description A human readable description of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *     Notification. Optional.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public ModelMBeanNotificationInfo(String[] notifTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                      String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                      String description) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        this(notifTypes,name,description,null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Constructs a ModelMBeanNotificationInfo object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @param notifTypes The array of strings (in dot notation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *        containing the notification types that may be emitted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @param name The name of the Notification class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param description A human readable description of the Notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *        Optional.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @param descriptor An instance of Descriptor containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *        appropriate metadata for this instance of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *        MBeanNotificationInfo. If it is null a default descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *        will be created. If the descriptor does not contain all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *        fields "name", "descriptorType", "displayName" and "severity",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *        the missing ones are added with their default values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @exception RuntimeOperationsException Wraps an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *    {@link IllegalArgumentException}. The descriptor is invalid, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *    descriptor field "name" is present but not equal to parameter name, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *    descriptor field "descriptorType" is present but not equal to "notification".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public ModelMBeanNotificationInfo(String[] notifTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                                      String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                      String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                                      Descriptor descriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        super(notifTypes, name, description);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    ModelMBeanNotificationInfo.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    "ModelMBeanNotificationInfo", "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        notificationDescriptor = validDescriptor(descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Constructs a new ModelMBeanNotificationInfo object from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * ModelMBeanNotfication Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @param inInfo the ModelMBeanNotificationInfo to be duplicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public ModelMBeanNotificationInfo(ModelMBeanNotificationInfo inInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        this(inInfo.getNotifTypes(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
             inInfo.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
             inInfo.getDescription(),inInfo.getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Creates and returns a new ModelMBeanNotificationInfo which is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * duplicate of this ModelMBeanNotificationInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public Object clone () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    ModelMBeanNotificationInfo.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    "clone()", "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return(new ModelMBeanNotificationInfo(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Returns a copy of the associated Descriptor for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * ModelMBeanNotificationInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @return Descriptor associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * ModelMBeanNotificationInfo object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see #setDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public Descriptor getDescriptor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    ModelMBeanNotificationInfo.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    "getDescriptor()", "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (notificationDescriptor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            // Dead code. Should never happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                        ModelMBeanNotificationInfo.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                        "getDescriptor()", "Descriptor value is null, " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                        "setting descriptor to default values");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            notificationDescriptor = validDescriptor(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return((Descriptor)notificationDescriptor.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Sets associated Descriptor (full replace) for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * ModelMBeanNotificationInfo If the new Descriptor is null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * then the associated Descriptor reverts to a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * descriptor.  The Descriptor is validated before it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * assigned.  If the new Descriptor is invalid, then a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * RuntimeOperationsException wrapping an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * IllegalArgumentException is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @param inDescriptor replaces the Descriptor associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * ModelMBeanNotification interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @exception RuntimeOperationsException Wraps an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * {@link IllegalArgumentException} for invalid Descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @see #getDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public void setDescriptor(Descriptor inDescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    ModelMBeanNotificationInfo.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                    "setDescriptor(Descriptor)", "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        notificationDescriptor = validDescriptor(inDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Returns a human readable string containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * ModelMBeanNotificationInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @return a string describing this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                    ModelMBeanNotificationInfo.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    "toString()", "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        final StringBuilder retStr = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        retStr.append("ModelMBeanNotificationInfo: ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            .append(this.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        retStr.append(" ; Description: ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            .append(this.getDescription());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        retStr.append(" ; Descriptor: ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            .append(this.getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        retStr.append(" ; Types: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        String[] nTypes = this.getNotifTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        for (int i=0; i < nTypes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            if (i > 0) retStr.append(", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            retStr.append(nTypes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return retStr.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Clones the passed in Descriptor, sets default values, and checks for validity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * If the Descriptor is invalid (for instance by having the wrong "name"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * this indicates programming error and a RuntimeOperationsException will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * The following fields will be defaulted if they are not already set:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * descriptorType="notification",displayName=this.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * name=this.getName(),severity="6"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @param in Descriptor to be checked, or null which is equivalent to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * empty Descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @exception RuntimeOperationsException if Descriptor is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    private Descriptor validDescriptor(final Descriptor in) throws RuntimeOperationsException {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   331
        Descriptor clone;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (in == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            clone = new DescriptorSupport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            MODELMBEAN_LOGGER.finer("Null Descriptor, creating new.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            clone = (Descriptor) in.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        //Setting defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        if (clone.getFieldValue("name")==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            clone.setField("name", this.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            MODELMBEAN_LOGGER.finer("Defaulting Descriptor name to " + this.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (clone.getFieldValue("descriptorType")==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            clone.setField("descriptorType", "notification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            MODELMBEAN_LOGGER.finer("Defaulting descriptorType to \"notification\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (clone.getFieldValue("displayName") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            clone.setField("displayName",this.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            MODELMBEAN_LOGGER.finer("Defaulting Descriptor displayName to " + this.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (clone.getFieldValue("severity") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            clone.setField("severity", "6");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            MODELMBEAN_LOGGER.finer("Defaulting Descriptor severity field to 6");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        //Checking validity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (!clone.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
             throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                "The isValid() method of the Descriptor object itself returned false,"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                "one or more required fields are invalid. Descriptor:" + clone.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if (! ((String)clone.getFieldValue("name")).equalsIgnoreCase(this.getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                "The Descriptor \"name\" field does not match the object described. " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                 " Expected: "+ this.getName() + " , was: " + clone.getFieldValue("name"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        if (! ((String)clone.getFieldValue("descriptorType")).equalsIgnoreCase("notification")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                 throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                "The Descriptor \"descriptorType\" field does not match the object described. " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                 " Expected: \"notification\" ," + " was: " + clone.getFieldValue("descriptorType"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return clone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Deserializes a {@link ModelMBeanNotificationInfo} from an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * {@link ObjectInputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    private void readObject(ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        // New serial form ignores extra field "currClass"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        in.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Serializes a {@link ModelMBeanNotificationInfo} to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * {@link ObjectOutputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    private void writeObject(ObjectOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        if (compat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            // Serializes this instance in the old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            ObjectOutputStream.PutField fields = out.putFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            fields.put("notificationDescriptor", notificationDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            fields.put("currClass", currClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            out.writeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            // Serializes this instance in the new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            out.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
}