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