jdk/src/share/classes/javax/management/MBeanNotificationInfo.java
author jbachorik
Mon, 29 Jul 2013 04:43:41 -0700
changeset 20830 bf6aed23937e
parent 20809 b5e0612d60b9
child 20851 9f284cf7836b
permissions -rw-r--r--
8021577: JCK test api/javax_management/jmx_serial/modelmbean/ModelMBeanNotificationInfo/serial/index.html#Input has failed since jdk 7u45 b01 Reviewed-by: alanb, dfuchs, ahgross
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1999, 2006, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
    28
import java.io.IOException;
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
    29
import java.io.InvalidObjectException;
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
    30
import java.io.ObjectInputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <p>The <CODE>MBeanNotificationInfo</CODE> class is used to describe the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * characteristics of the different notification instances
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * emitted by an MBean, for a given Java class of notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * If an MBean emits notifications that can be instances of different Java classes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * then the metadata for that MBean should provide an <CODE>MBeanNotificationInfo</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * object for each of these notification Java classes.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>Instances of this class are immutable.  Subclasses may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * mutable but this is not recommended.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>This class extends <CODE>javax.management.MBeanFeatureInfo</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * and thus provides <CODE>name</CODE> and <CODE>description</CODE> fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * The <CODE>name</CODE> field should be the fully qualified Java class name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the notification objects described by this class.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>The <CODE>getNotifTypes</CODE> method returns an array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * strings containing the notification types that the MBean may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * emit. The notification type is a dot-notation string which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * describes what the emitted notification is about, not the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * class of the notification.  A single generic notification class can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * be used to send notifications of several types.  All of these types
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * are returned in the string array result of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <CODE>getNotifTypes</CODE> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class MBeanNotificationInfo extends MBeanFeatureInfo implements Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    static final long serialVersionUID = -3888371564530107064L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static final String[] NO_TYPES = new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    static final MBeanNotificationInfo[] NO_NOTIFICATIONS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        new MBeanNotificationInfo[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @serial The different types of the notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
    73
    private String[] types;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /** @see MBeanInfo#arrayGettersSafe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private final transient boolean arrayGettersSafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Constructs an <CODE>MBeanNotificationInfo</CODE> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param notifTypes The array of strings (in dot notation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * containing the notification types that the MBean may emit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * This may be null with the same effect as a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param name The fully qualified Java class name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * described notifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param description A human readable description of the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public MBeanNotificationInfo(String[] notifTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                 String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                 String description) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        this(notifTypes, name, description, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Constructs an <CODE>MBeanNotificationInfo</CODE> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param notifTypes The array of strings (in dot notation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * containing the notification types that the MBean may emit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * This may be null with the same effect as a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param name The fully qualified Java class name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * described notifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param description A human readable description of the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param descriptor The descriptor for the notifications.  This may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * which is equivalent to an empty descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public MBeanNotificationInfo(String[] notifTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                 String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                 String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                                 Descriptor descriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        super(name, description, descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        /* We do not validate the notifTypes, since the spec just says
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
           they are dot-separated, not that they must look like Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
           classes.  E.g. the spec doesn't forbid "sun.prob.25" as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
           notifType, though it doesn't explicitly allow it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
           either.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   120
        this.types = (notifTypes != null && notifTypes.length > 0) ?
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   121
                        notifTypes.clone() : NO_TYPES;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this.arrayGettersSafe =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            MBeanInfo.arrayGettersSafe(this.getClass(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                                       MBeanNotificationInfo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Returns a shallow clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * The clone is obtained by simply calling <tt>super.clone()</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * thus calling the default native shallow cloning mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * implemented by <tt>Object.clone()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * No deeper cloning of any internal field is made.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     public Object clone () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
             return super.clone() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
         } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
             // should not happen as this class is cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
             return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Returns the array of strings (in dot notation) containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * notification types that the MBean may emit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @return the array of strings.  Changing the returned array has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * effect on this MBeanNotificationInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public String[] getNotifTypes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (types.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            return NO_TYPES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            return types.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    private String[] fastGetNotifTypes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (arrayGettersSafe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            return types;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            return getNotifTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            getClass().getName() + "[" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            "description=" + getDescription() + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            "name=" + getName() + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            "notifTypes=" + Arrays.asList(fastGetNotifTypes()) + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            "descriptor=" + getDescriptor() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Compare this MBeanNotificationInfo to another.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param o the object to compare to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @return true if and only if <code>o</code> is an MBeanNotificationInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * such that its {@link #getName()}, {@link #getDescription()},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * {@link #getDescriptor()},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * and {@link #getNotifTypes()} values are equal (not necessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * identical) to those of this MBeanNotificationInfo.  Two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * notification type arrays are equal if their corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * elements are equal.  They are not equal if they have the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * elements but in a different order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (o == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (!(o instanceof MBeanNotificationInfo))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        MBeanNotificationInfo p = (MBeanNotificationInfo) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return (p.getName().equals(getName()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                p.getDescription().equals(getDescription()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                p.getDescriptor().equals(getDescriptor()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                Arrays.equals(p.fastGetNotifTypes(), fastGetNotifTypes()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        int hash = getName().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        for (int i = 0; i < types.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            hash ^= types[i].hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   208
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   209
    private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   210
        ObjectInputStream.GetField gf = ois.readFields();
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   211
        String[] t = (String[])gf.get("types", null);
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   212
20830
bf6aed23937e 8021577: JCK test api/javax_management/jmx_serial/modelmbean/ModelMBeanNotificationInfo/serial/index.html#Input has failed since jdk 7u45 b01
jbachorik
parents: 20809
diff changeset
   213
        types = (t != null && t.length != 0) ? t.clone() : NO_TYPES;
20809
b5e0612d60b9 8014085: Better serialization support in JMX classes
jbachorik
parents: 5506
diff changeset
   214
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
}