jdk/src/share/classes/javax/management/openmbean/OpenMBeanInfoSupport.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 526 61ba2d5ea9da
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 526
diff changeset
     2
 * Copyright 2000-2008 Sun Microsystems, Inc.  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
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package javax.management.openmbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
// java import
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.management.Descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.management.MBeanAttributeInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.MBeanConstructorInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.management.MBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.management.MBeanNotificationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.management.MBeanOperationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * The {@code OpenMBeanInfoSupport} class describes the management
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * information of an <i>open MBean</i>: it is a subclass of {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * javax.management.MBeanInfo}, and it implements the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * OpenMBeanInfo} interface.  Note that an <i>open MBean</i> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * recognized as such if its {@code getMBeanInfo()} method returns an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * instance of a class which implements the OpenMBeanInfo interface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * typically {@code OpenMBeanInfoSupport}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public class OpenMBeanInfoSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    extends MBeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    implements OpenMBeanInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static final long serialVersionUID = 4349395935420511492L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    // As this instance is immutable, these two values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    // need only be calculated once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private transient Integer myHashCode = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private transient String  myToString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * <p>Constructs an {@code OpenMBeanInfoSupport} instance, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * describes a class of open MBeans with the specified {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * className}, {@code description}, {@code openAttributes}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * openConstructors} , {@code openOperations} and {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * notifications}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <p>The {@code openAttributes}, {@code openConstructors},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * {@code openOperations} and {@code notifications}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * array parameters are internally copied, so that subsequent changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * to the arrays referenced by these parameters have no effect on this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param className The fully qualified Java class name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * open MBean described by this <CODE>OpenMBeanInfoSupport</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param description A human readable description of the open
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * MBean described by this <CODE>OpenMBeanInfoSupport</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param openAttributes The list of exposed attributes of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * described open MBean; Must be an array of instances of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * subclass of {@code MBeanAttributeInfo}, typically {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * OpenMBeanAttributeInfoSupport}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param openConstructors The list of exposed public constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * of the described open MBean; Must be an array of instances of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * subclass of {@code MBeanConstructorInfo}, typically {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * OpenMBeanConstructorInfoSupport}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param openOperations The list of exposed operations of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * described open MBean.  Must be an array of instances of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * subclass of {@code MBeanOperationInfo}, typically {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * OpenMBeanOperationInfoSupport}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param notifications The list of notifications emitted by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * described open MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @throws ArrayStoreException If {@code openAttributes}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * openConstructors} or {@code openOperations} is not an array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * instances of a subclass of {@code MBeanAttributeInfo}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * MBeanConstructorInfo} or {@code MBeanOperationInfo}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public OpenMBeanInfoSupport(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                OpenMBeanAttributeInfo[] openAttributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                OpenMBeanConstructorInfo[] openConstructors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                OpenMBeanOperationInfo[] openOperations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                MBeanNotificationInfo[] notifications) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        this(className, description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
             openAttributes, openConstructors, openOperations, notifications,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
             (Descriptor) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <p>Constructs an {@code OpenMBeanInfoSupport} instance, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * describes a class of open MBeans with the specified {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * className}, {@code description}, {@code openAttributes}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * openConstructors} , {@code openOperations}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * notifications}, and {@code descriptor}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * <p>The {@code openAttributes}, {@code openConstructors}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * openOperations} and {@code notifications} array parameters are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * internally copied, so that subsequent changes to the arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * referenced by these parameters have no effect on this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @param className The fully qualified Java class name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * open MBean described by this <CODE>OpenMBeanInfoSupport</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param description A human readable description of the open
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * MBean described by this <CODE>OpenMBeanInfoSupport</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param openAttributes The list of exposed attributes of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * described open MBean; Must be an array of instances of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * subclass of {@code MBeanAttributeInfo}, typically {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * OpenMBeanAttributeInfoSupport}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param openConstructors The list of exposed public constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * of the described open MBean; Must be an array of instances of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * subclass of {@code MBeanConstructorInfo}, typically {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * OpenMBeanConstructorInfoSupport}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param openOperations The list of exposed operations of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * described open MBean.  Must be an array of instances of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * subclass of {@code MBeanOperationInfo}, typically {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * OpenMBeanOperationInfoSupport}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param notifications The list of notifications emitted by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * described open MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @param descriptor The descriptor for the MBean.  This may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * which is equivalent to an empty descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @throws ArrayStoreException If {@code openAttributes}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * openConstructors} or {@code openOperations} is not an array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * instances of a subclass of {@code MBeanAttributeInfo}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * MBeanConstructorInfo} or {@code MBeanOperationInfo}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public OpenMBeanInfoSupport(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                OpenMBeanAttributeInfo[] openAttributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                OpenMBeanConstructorInfo[] openConstructors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                OpenMBeanOperationInfo[] openOperations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                MBeanNotificationInfo[] notifications,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                Descriptor descriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        super(className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
              description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
              attributeArray(openAttributes),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
              constructorArray(openConstructors),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
              operationArray(openOperations),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
              (notifications == null) ? null : notifications.clone(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
              descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private static MBeanAttributeInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            attributeArray(OpenMBeanAttributeInfo[] src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (src == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        MBeanAttributeInfo[] dst = new MBeanAttributeInfo[src.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        System.arraycopy(src, 0, dst, 0, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        // may throw an ArrayStoreException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    private static MBeanConstructorInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            constructorArray(OpenMBeanConstructorInfo[] src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (src == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        MBeanConstructorInfo[] dst = new MBeanConstructorInfo[src.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        System.arraycopy(src, 0, dst, 0, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        // may throw an ArrayStoreException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    private static MBeanOperationInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            operationArray(OpenMBeanOperationInfo[] src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (src == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        MBeanOperationInfo[] dst = new MBeanOperationInfo[src.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        System.arraycopy(src, 0, dst, 0, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return dst;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /* ***  Commodity methods from java.lang.Object  *** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * <p>Compares the specified {@code obj} parameter with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * {@code OpenMBeanInfoSupport} instance for equality.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <p>Returns {@code true} if and only if all of the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * statements are true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * <li>{@code obj} is non null,</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * <li>{@code obj} also implements the {@code OpenMBeanInfo}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * interface,</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * <li>their class names are equal</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * <li>their infos on attributes, constructors, operations and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * notifications are equal</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * This ensures that this {@code equals} method works properly for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * {@code obj} parameters which are different implementations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * the {@code OpenMBeanInfo} interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @param obj the object to be compared for equality with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * {@code OpenMBeanInfoSupport} instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @return {@code true} if the specified object is equal to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * {@code OpenMBeanInfoSupport} instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        // if obj is null, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (obj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        // if obj is not a OpenMBeanInfo, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        OpenMBeanInfo other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            other = (OpenMBeanInfo) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        // Now, really test for equality between this OpenMBeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        // implementation and the other:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        // their MBean className should be equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if ( ! this.getClassName().equals(other.getClassName()) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        // their infos on attributes should be equal (order not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        // significant => equality between sets, not arrays or lists)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (!sameArrayContents(this.getAttributes(), other.getAttributes()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        // their infos on constructors should be equal (order not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        // significant => equality between sets, not arrays or lists)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (!sameArrayContents(this.getConstructors(), other.getConstructors()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        // their infos on operations should be equal (order not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        // significant => equality between sets, not arrays or lists)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (!sameArrayContents(this.getOperations(), other.getOperations()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        // their infos on notifications should be equal (order not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        // significant => equality between sets, not arrays or lists)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (!sameArrayContents(this.getNotifications(), other.getNotifications()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        // All tests for equality were successful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    private static <T> boolean sameArrayContents(T[] a1, T[] a2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return (new HashSet<T>(Arrays.asList(a1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                .equals(new HashSet<T>(Arrays.asList(a2))));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * <p>Returns the hash code value for this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * OpenMBeanInfoSupport} instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * <p>The hash code of an {@code OpenMBeanInfoSupport} instance is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * the sum of the hash codes of all elements of information used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * in {@code equals} comparisons (ie: its class name, and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * infos on attributes, constructors, operations and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * notifications, where the hashCode of each of these arrays is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * calculated by a call to {@code new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * java.util.HashSet(java.util.Arrays.asList(this.getSignature)).hashCode()}).</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * <p>This ensures that {@code t1.equals(t2)} implies that {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * t1.hashCode()==t2.hashCode()} for any two {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * OpenMBeanInfoSupport} instances {@code t1} and {@code t2}, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * required by the general contract of the method {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Object#hashCode() Object.hashCode()}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * <p>However, note that another instance of a class implementing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * the {@code OpenMBeanInfo} interface may be equal to this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * OpenMBeanInfoSupport} instance as defined by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * #equals(java.lang.Object)}, but may have a different hash code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * if it is calculated differently.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * <p>As {@code OpenMBeanInfoSupport} instances are immutable, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * hash code for this instance is calculated once, on the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * call to {@code hashCode}, and then the same value is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * for subsequent calls.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @return the hash code value for this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * OpenMBeanInfoSupport} instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        // Calculate the hash code value if it has not yet been done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        // (ie 1st call to hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        if (myHashCode == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            int value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            value += this.getClassName().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            value += arraySetHash(this.getAttributes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            value += arraySetHash(this.getConstructors());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            value += arraySetHash(this.getOperations());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            value += arraySetHash(this.getNotifications());
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   350
            myHashCode = Integer.valueOf(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        // return always the same hash code for this instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return myHashCode.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    private static <T> int arraySetHash(T[] a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return new HashSet<T>(Arrays.asList(a)).hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * <p>Returns a string representation of this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * OpenMBeanInfoSupport} instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * <p>The string representation consists of the name of this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * (ie {@code javax.management.openmbean.OpenMBeanInfoSupport}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * the MBean class name, the string representation of infos on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * attributes, constructors, operations and notifications of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * described MBean and the string representation of the descriptor.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * <p>As {@code OpenMBeanInfoSupport} instances are immutable, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * string representation for this instance is calculated once, on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * the first call to {@code toString}, and then the same value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * returned for subsequent calls.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @return a string representation of this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * OpenMBeanInfoSupport} instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        // Calculate the string value if it has not yet been done (ie
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        // 1st call to toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (myToString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            myToString = new StringBuilder()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                .append(this.getClass().getName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                .append("(mbean_class_name=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                .append(this.getClassName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                .append(",attributes=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                .append(Arrays.asList(this.getAttributes()).toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                .append(",constructors=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                .append(Arrays.asList(this.getConstructors()).toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                .append(",operations=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                .append(Arrays.asList(this.getOperations()).toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                .append(",notifications=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                .append(Arrays.asList(this.getNotifications()).toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                .append(",descriptor=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                .append(this.getDescriptor())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                .append(")")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                .toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        // return always the same string representation for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        // instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        return myToString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
}