jdk/src/share/classes/javax/management/MBeanInfo.java
author emcmanus
Mon, 27 Oct 2008 14:02:40 +0100
changeset 1510 e747d3193ef2
parent 2 90ce3da70b43
child 1513 d09513aaa9da
permissions -rw-r--r--
6763639: Remove "rawtypes" warnings from JMX code Reviewed-by: dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
package javax.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.StreamCorruptedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.WeakHashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import static javax.management.ImmutableDescriptor.nonNullDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>Describes the management interface exposed by an MBean; that is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * the set of attributes and operations which are available for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * management operations.  Instances of this class are immutable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Subclasses may be mutable but this is not recommended.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>The contents of the <code>MBeanInfo</code> for a Dynamic MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * are determined by its {@link DynamicMBean#getMBeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * getMBeanInfo()} method.  This includes Open MBeans and Model
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * MBeans, which are kinds of Dynamic MBeans.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>The contents of the <code>MBeanInfo</code> for a Standard MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * are determined by the MBean server as follows:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <li>{@link #getClassName()} returns the Java class name of the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <li>{@link #getConstructors()} returns the list of all public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * constructors in that object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <li>{@link #getAttributes()} returns the list of all attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * whose existence is deduced from the presence in the MBean interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * of a <code>get<i>Name</i></code>, <code>is<i>Name</i></code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <code>set<i>Name</i></code> method that conforms to the conventions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * for Standard MBeans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <li>{@link #getOperations()} returns the list of all methods in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * the MBean interface that do not represent attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <li>{@link #getNotifications()} returns an empty array if the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * does not implement the {@link NotificationBroadcaster} interface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * otherwise the result of calling {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * NotificationBroadcaster#getNotificationInfo()} on it;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <li>{@link #getDescriptor()} returns a descriptor containing the contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * of any descriptor annotations in the MBean interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <p>The description returned by {@link #getDescription()} and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * descriptions of the contained attributes and operations are determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * by the corresponding <!-- link here --> Description annotations if any;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * otherwise their contents are not specified.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <p>The remaining details of the <code>MBeanInfo</code> for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * Standard MBean are not specified.  This includes the description of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * any contained constructors, and notifications; the names
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * of parameters to constructors and operations; and the descriptions of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * constructor parameters.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
public class MBeanInfo implements Cloneable, Serializable, DescriptorRead {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    static final long serialVersionUID = -6451021435135161911L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @serial The Descriptor for the MBean.  This field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * can be null, which is equivalent to an empty Descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private transient Descriptor descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @serial The human readable description of the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private final String description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @serial The MBean qualified name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private final String className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @serial The MBean attribute descriptors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private final MBeanAttributeInfo[] attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @serial The MBean operation descriptors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private final MBeanOperationInfo[] operations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @serial The MBean constructor descriptors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private final MBeanConstructorInfo[] constructors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @serial The MBean notification descriptors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    private final MBeanNotificationInfo[] notifications;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private transient int hashCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * <p>True if this class is known not to override the array-valued
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * getters of MBeanInfo.  Obviously true for MBeanInfo itself, and true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * for a subclass where we succeed in reflecting on the methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * and discover they are not overridden.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * <p>The purpose of this variable is to avoid cloning the arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * when doing operations like {@link #equals} where we know they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * will not be changed.  If a subclass overrides a getter, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * cannot access the corresponding array directly.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private final transient boolean arrayGettersSafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Constructs an <CODE>MBeanInfo</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param className The name of the Java class of the MBean described
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * by this <CODE>MBeanInfo</CODE>.  This value may be any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * syntactically legal Java class name.  It does not have to be a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Java class known to the MBean server or to the MBean's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * ClassLoader.  If it is a Java class known to the MBean's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * ClassLoader, it is recommended but not required that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * class's public methods include those that would appear in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Standard MBean implementing the attributes and operations in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * this MBeanInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @param description A human readable description of the MBean (optional).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @param attributes The list of exposed attributes of the MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * This may be null with the same effect as a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @param constructors The list of public constructors of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * MBean.  This may be null with the same effect as a zero-length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @param operations The list of operations of the MBean.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * may be null with the same effect as a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param notifications The list of notifications emitted.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * may be null with the same effect as a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public MBeanInfo(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                     String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                     MBeanAttributeInfo[] attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                     MBeanConstructorInfo[] constructors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                     MBeanOperationInfo[] operations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                     MBeanNotificationInfo[] notifications)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        this(className, description, attributes, constructors, operations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
             notifications, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Constructs an <CODE>MBeanInfo</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @param className The name of the Java class of the MBean described
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * by this <CODE>MBeanInfo</CODE>.  This value may be any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * syntactically legal Java class name.  It does not have to be a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Java class known to the MBean server or to the MBean's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * ClassLoader.  If it is a Java class known to the MBean's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * ClassLoader, it is recommended but not required that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * class's public methods include those that would appear in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Standard MBean implementing the attributes and operations in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * this MBeanInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param description A human readable description of the MBean (optional).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param attributes The list of exposed attributes of the MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * This may be null with the same effect as a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param constructors The list of public constructors of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * MBean.  This may be null with the same effect as a zero-length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @param operations The list of operations of the MBean.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * may be null with the same effect as a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @param notifications The list of notifications emitted.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * may be null with the same effect as a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @param descriptor The descriptor for the MBean.  This may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * which is equivalent to an empty descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public MBeanInfo(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                     String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                     MBeanAttributeInfo[] attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                     MBeanConstructorInfo[] constructors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                     MBeanOperationInfo[] operations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                     MBeanNotificationInfo[] notifications,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                     Descriptor descriptor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        this.className = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        this.description = description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (attributes == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            attributes = MBeanAttributeInfo.NO_ATTRIBUTES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        this.attributes = attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        if (operations == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            operations = MBeanOperationInfo.NO_OPERATIONS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        this.operations = operations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (constructors == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            constructors = MBeanConstructorInfo.NO_CONSTRUCTORS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        this.constructors = constructors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (notifications == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            notifications = MBeanNotificationInfo.NO_NOTIFICATIONS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        this.notifications = notifications;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (descriptor == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        this.descriptor = descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        this.arrayGettersSafe =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                arrayGettersSafe(this.getClass(), MBeanInfo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <p>Returns a shallow clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * The clone is obtained by simply calling <tt>super.clone()</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * thus calling the default native shallow cloning mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * implemented by <tt>Object.clone()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * No deeper cloning of any internal field is made.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * <p>Since this class is immutable, the clone method is chiefly of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * interest to subclasses.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     public Object clone () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
             return super.clone() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
         } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
             // should not happen as this class is cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
             return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Returns the name of the Java class of the MBean described by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * this <CODE>MBeanInfo</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @return the class name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public String getClassName()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        return className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Returns a human readable description of the MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @return the description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public String getDescription()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Returns the list of attributes exposed for management.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * Each attribute is described by an <CODE>MBeanAttributeInfo</CODE> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * The returned array is a shallow copy of the internal array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * which means that it is a copy of the internal array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * references to the <CODE>MBeanAttributeInfo</CODE> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * but that each referenced <CODE>MBeanAttributeInfo</CODE> object is not copied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @return  An array of <CODE>MBeanAttributeInfo</CODE> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    public MBeanAttributeInfo[] getAttributes()   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        MBeanAttributeInfo[] as = nonNullAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        if (as.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            return as;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            return as.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    private MBeanAttributeInfo[] fastGetAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (arrayGettersSafe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            return nonNullAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            return getAttributes();
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
     * Return the value of the attributes field, or an empty array if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * the field is null.  This can't happen with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * normally-constructed instance of this class, but can if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * instance was deserialized from another implementation that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * allows the field to be null.  It would be simpler if we enforced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * the class invariant that these fields cannot be null by writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * a readObject() method, but that would require us to define the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * various array fields as non-final, which is annoying because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * conceptually they are indeed final.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    private MBeanAttributeInfo[] nonNullAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return (attributes == null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            MBeanAttributeInfo.NO_ATTRIBUTES : attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * Returns the list of operations  of the MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * Each operation is described by an <CODE>MBeanOperationInfo</CODE> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * The returned array is a shallow copy of the internal array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * which means that it is a copy of the internal array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * references to the <CODE>MBeanOperationInfo</CODE> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * but that each referenced <CODE>MBeanOperationInfo</CODE> object is not copied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @return  An array of <CODE>MBeanOperationInfo</CODE> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    public MBeanOperationInfo[] getOperations()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        MBeanOperationInfo[] os = nonNullOperations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (os.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            return os;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            return os.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    private MBeanOperationInfo[] fastGetOperations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        if (arrayGettersSafe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            return nonNullOperations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            return getOperations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    private MBeanOperationInfo[] nonNullOperations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return (operations == null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            MBeanOperationInfo.NO_OPERATIONS : operations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * <p>Returns the list of the public constructors of the MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * Each constructor is described by an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * <CODE>MBeanConstructorInfo</CODE> object.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * <p>The returned array is a shallow copy of the internal array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * which means that it is a copy of the internal array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * references to the <CODE>MBeanConstructorInfo</CODE> objects but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * that each referenced <CODE>MBeanConstructorInfo</CODE> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * is not copied.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * <p>The returned list is not necessarily exhaustive.  That is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * the MBean may have a public constructor that is not in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * list.  In this case, the MBean server can construct another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * instance of this MBean's class using that constructor, even
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * though it is not listed here.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @return  An array of <CODE>MBeanConstructorInfo</CODE> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public MBeanConstructorInfo[] getConstructors()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        MBeanConstructorInfo[] cs = nonNullConstructors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if (cs.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            return cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            return cs.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    private MBeanConstructorInfo[] fastGetConstructors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (arrayGettersSafe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            return nonNullConstructors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            return getConstructors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    private MBeanConstructorInfo[] nonNullConstructors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return (constructors == null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            MBeanConstructorInfo.NO_CONSTRUCTORS : constructors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * Returns the list of the notifications emitted by the MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * Each notification is described by an <CODE>MBeanNotificationInfo</CODE> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * The returned array is a shallow copy of the internal array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * which means that it is a copy of the internal array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * references to the <CODE>MBeanNotificationInfo</CODE> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * but that each referenced <CODE>MBeanNotificationInfo</CODE> object is not copied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @return  An array of <CODE>MBeanNotificationInfo</CODE> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    public MBeanNotificationInfo[] getNotifications()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        MBeanNotificationInfo[] ns = nonNullNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (ns.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return ns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            return ns.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    private MBeanNotificationInfo[] fastGetNotifications() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        if (arrayGettersSafe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            return nonNullNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            return getNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    private MBeanNotificationInfo[] nonNullNotifications() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        return (notifications == null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            MBeanNotificationInfo.NO_NOTIFICATIONS : notifications;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * Get the descriptor of this MBeanInfo.  Changing the returned value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * will have no affect on the original descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @return a descriptor that is either immutable or a copy of the original.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public Descriptor getDescriptor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        return (Descriptor) nonNullDescriptor(descriptor).clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            getClass().getName() + "[" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            "description=" + getDescription() + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            "attributes=" + Arrays.asList(fastGetAttributes()) + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            "constructors=" + Arrays.asList(fastGetConstructors()) + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            "operations=" + Arrays.asList(fastGetOperations()) + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            "notifications=" + Arrays.asList(fastGetNotifications()) + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            "descriptor=" + getDescriptor() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * <p>Compare this MBeanInfo to another.  Two MBeanInfo objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * are equal if and only if they return equal values for {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * #getClassName()}, for {@link #getDescription()}, and for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * {@link #getDescriptor()}, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * arrays returned by the two objects for {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * #getAttributes()}, {@link #getOperations()}, {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * #getConstructors()}, and {@link #getNotifications()} are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * pairwise equal.  Here "equal" means {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * Object#equals(Object)}, not identity.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * <p>If two MBeanInfo objects return the same values in one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * their arrays but in a different order then they are not equal.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @param o the object to compare to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @return true if and only if <code>o</code> is an MBeanInfo that is equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * to this one according to the rules above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        if (o == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        if (!(o instanceof MBeanInfo))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        MBeanInfo p = (MBeanInfo) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        if (!isEqual(getClassName(),  p.getClassName()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                !isEqual(getDescription(), p.getDescription()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                !getDescriptor().equals(p.getDescriptor())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            (Arrays.equals(p.fastGetAttributes(), fastGetAttributes()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
             Arrays.equals(p.fastGetOperations(), fastGetOperations()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
             Arrays.equals(p.fastGetConstructors(), fastGetConstructors()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
             Arrays.equals(p.fastGetNotifications(), fastGetNotifications()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        /* Since computing the hashCode is quite expensive, we cache it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
           If by some terrible misfortune the computed value is 0, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
           caching won't work and we will recompute it every time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
           We don't bother synchronizing, because, at worst, n different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
           threads will compute the same hashCode at the same time.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        if (hashCode != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            return hashCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        hashCode =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            getClassName().hashCode() ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            getDescriptor().hashCode() ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            arrayHashCode(fastGetAttributes()) ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            arrayHashCode(fastGetOperations()) ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            arrayHashCode(fastGetConstructors()) ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            arrayHashCode(fastGetNotifications());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        return hashCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    private static int arrayHashCode(Object[] array) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        int hash = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        for (int i = 0; i < array.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            hash ^= array[i].hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * Cached results of previous calls to arrayGettersSafe.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * a WeakHashMap so that we don't prevent a class from being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * garbage collected just because we know whether it's immutable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     */
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   527
    private static final Map<Class<?>, Boolean> arrayGettersSafeMap =
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   528
        new WeakHashMap<Class<?>, Boolean>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * Return true if <code>subclass</code> is known to preserve the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * immutability of <code>immutableClass</code>.  The class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * <code>immutableClass</code> is a reference class that is known
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * to be immutable.  The subclass <code>subclass</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * considered immutable if it does not override any public method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * of <code>immutableClass</code> whose name begins with "get".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * This is obviously not an infallible test for immutability,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * but it works for the public interfaces of the MBean*Info classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    */
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   540
    static boolean arrayGettersSafe(Class<?> subclass, Class<?> immutableClass) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        if (subclass == immutableClass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        synchronized (arrayGettersSafeMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            Boolean safe = arrayGettersSafeMap.get(subclass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            if (safe == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    ArrayGettersSafeAction action =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                        new ArrayGettersSafeAction(subclass, immutableClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    safe = AccessController.doPrivileged(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                } catch (Exception e) { // e.g. SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                    /* We don't know, so we assume it isn't.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    safe = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                arrayGettersSafeMap.put(subclass, safe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            return safe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * The PrivilegedAction stuff is probably overkill.  We can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * pretty sure the caller does have the required privileges -- a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * JMX user that can't do reflection can't even use Standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * MBeans!  But there's probably a performance gain by not having
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * to check the whole call stack.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    private static class ArrayGettersSafeAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            implements PrivilegedAction<Boolean> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        private final Class<?> subclass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        private final Class<?> immutableClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        ArrayGettersSafeAction(Class<?> subclass, Class<?> immutableClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            this.subclass = subclass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            this.immutableClass = immutableClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        public Boolean run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            Method[] methods = immutableClass.getMethods();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            for (int i = 0; i < methods.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                Method method = methods[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                String methodName = method.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                if (methodName.startsWith("get") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                        method.getParameterTypes().length == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                        method.getReturnType().isArray()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                        Method submethod =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                            subclass.getMethod(methodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                        if (!submethod.equals(method))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                    } catch (NoSuchMethodException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    private static boolean isEqual(String s1, String s2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        boolean ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        if (s1 == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            ret = (s2 == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            ret = s1.equals(s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * Serializes an {@link MBeanInfo} to an {@link ObjectOutputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @serialData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * For compatibility reasons, an object of this class is serialized as follows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * The method {@link ObjectOutputStream#defaultWriteObject defaultWriteObject()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * is called first to serialize the object except the field {@code descriptor}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * which is declared as transient. The field {@code descriptor} is serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     *     <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     *     <li> If {@code descriptor} is an instance of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     *        {@link ImmutableDescriptor}, the method {@link ObjectOutputStream#write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     *        write(int val)} is called to write a byte with the value {@code 1},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *        then the method {@link ObjectOutputStream#writeObject writeObject(Object obj)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     *        is called twice to serialize the field names and the field values of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     *        {@code descriptor}, respectively as a {@code String[]} and an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     *        {@code Object[]};</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     *     <li> Otherwise, the method {@link ObjectOutputStream#write write(int val)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     *        is called to write a byte with the value {@code 0}, then the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     *        {@link ObjectOutputStream#writeObject writeObject(Object obj)} is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     *        to serialize the field {@code descriptor} directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     *     </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    private void writeObject(ObjectOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        out.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        if (descriptor.getClass() == ImmutableDescriptor.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            out.write(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            final String[] names = descriptor.getFieldNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            out.writeObject(names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            out.writeObject(descriptor.getFieldValues(names));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            out.write(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            out.writeObject(descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * Deserializes an {@link MBeanInfo} from an {@link ObjectInputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * @serialData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * For compatibility reasons, an object of this class is deserialized as follows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * The method {@link ObjectInputStream#defaultReadObject defaultReadObject()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * is called first to deserialize the object except the field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * {@code descriptor}, which is not serialized in the default way. Then the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * {@link ObjectInputStream#read read()} is called to read a byte, the field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * {@code descriptor} is deserialized according to the value of the byte value:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *    <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     *    <li>1. The method {@link ObjectInputStream#readObject readObject()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     *       is called twice to obtain the field names (a {@code String[]}) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     *       the field values (a {@code Object[]}) of the {@code descriptor}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     *       The two obtained values then are used to construct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     *       an {@link ImmutableDescriptor} instance for the field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     *       {@code descriptor};</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     *    <li>0. The value for the field {@code descriptor} is obtained directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     *       by calling the method {@link ObjectInputStream#readObject readObject()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     *       If the obtained value is null, the field {@code descriptor} is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     *       {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR};</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     *    <li>-1. This means that there is no byte to read and that the object is from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     *       an earlier version of the JMX API. The field {@code descriptor} is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     *       {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     *    <li>Any other value. A {@link StreamCorruptedException} is thrown.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     *    </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    private void readObject(ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        in.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        switch (in.read()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        case 1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            final String[] names = (String[])in.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            if (names.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                final Object[] values = (Object[])in.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                descriptor = new ImmutableDescriptor(names, values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        case 0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            descriptor = (Descriptor)in.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            if (descriptor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        case -1: // from an earlier version of the JMX API
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            throw new StreamCorruptedException("Got unexpected byte.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
}