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