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