jdk/src/java.management/share/classes/javax/management/openmbean/OpenMBeanInfoSupport.java
author uvangapally
Tue, 01 Aug 2017 10:33:47 +0530
changeset 46050 f51c14dc540f
parent 25859 3317bb8137f4
permissions -rw-r--r--
8181895: javax management docs contain links to technotes Summary: Edited links to point to Alternate paths Reviewed-by: rriggs Contributed-by: ujwal.vangapally@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 19845
diff changeset
     2
 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
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;
19845
6f149007b02c 8023529: OpenMBeanInfoSupport.equals/hashCode throw NPE
sjiang
parents: 5506
diff changeset
    34
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.management.Descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.MBeanAttributeInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.management.MBeanConstructorInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.management.MBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.management.MBeanNotificationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.MBeanOperationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The {@code OpenMBeanInfoSupport} class describes the management
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * information of an <i>open MBean</i>: it is a subclass of {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * javax.management.MBeanInfo}, and it implements the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * OpenMBeanInfo} interface.  Note that an <i>open MBean</i> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * recognized as such if its {@code getMBeanInfo()} method returns an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * instance of a class which implements the OpenMBeanInfo interface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * typically {@code OpenMBeanInfoSupport}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class OpenMBeanInfoSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    extends MBeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    implements OpenMBeanInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    static final long serialVersionUID = 4349395935420511492L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    // As this instance is immutable, these two values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // need only be calculated once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private transient Integer myHashCode = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private transient String  myToString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * <p>Constructs an {@code OpenMBeanInfoSupport} instance, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * describes a class of open MBeans with the specified {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * className}, {@code description}, {@code openAttributes}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * openConstructors} , {@code openOperations} and {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * notifications}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * <p>The {@code openAttributes}, {@code openConstructors},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * {@code openOperations} and {@code notifications}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * array parameters are internally copied, so that subsequent changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * to the arrays referenced by these parameters have no effect on this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param className The fully qualified Java class name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * open MBean described by this <CODE>OpenMBeanInfoSupport</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param description A human readable description of the open
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * MBean described by this <CODE>OpenMBeanInfoSupport</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @param openAttributes The list of exposed attributes of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * described open MBean; Must be an array of instances of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * subclass of {@code MBeanAttributeInfo}, typically {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * OpenMBeanAttributeInfoSupport}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param openConstructors The list of exposed public constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * of the described open MBean; Must be an array of instances of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * subclass of {@code MBeanConstructorInfo}, typically {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * OpenMBeanConstructorInfoSupport}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param openOperations The list of exposed operations of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * described open MBean.  Must be an array of instances of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * subclass of {@code MBeanOperationInfo}, typically {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * OpenMBeanOperationInfoSupport}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param notifications The list of notifications emitted by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * described open MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @throws ArrayStoreException If {@code openAttributes}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * openConstructors} or {@code openOperations} is not an array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * instances of a subclass of {@code MBeanAttributeInfo}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * MBeanConstructorInfo} or {@code MBeanOperationInfo}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public OpenMBeanInfoSupport(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                OpenMBeanAttributeInfo[] openAttributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                OpenMBeanConstructorInfo[] openConstructors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                OpenMBeanOperationInfo[] openOperations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                MBeanNotificationInfo[] notifications) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        this(className, description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
             openAttributes, openConstructors, openOperations, notifications,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
             (Descriptor) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * <p>Constructs an {@code OpenMBeanInfoSupport} instance, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * describes a class of open MBeans with the specified {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * className}, {@code description}, {@code openAttributes}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * openConstructors} , {@code openOperations}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * notifications}, and {@code descriptor}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * <p>The {@code openAttributes}, {@code openConstructors}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * openOperations} and {@code notifications} array parameters are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * internally copied, so that subsequent changes to the arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * referenced by these parameters have no effect on this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @param className The fully qualified Java class name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * open MBean described by this <CODE>OpenMBeanInfoSupport</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param description A human readable description of the open
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * MBean described by this <CODE>OpenMBeanInfoSupport</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param openAttributes The list of exposed attributes of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * described open MBean; Must be an array of instances of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * subclass of {@code MBeanAttributeInfo}, typically {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * OpenMBeanAttributeInfoSupport}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @param openConstructors The list of exposed public constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * of the described open MBean; Must be an array of instances of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * subclass of {@code MBeanConstructorInfo}, typically {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * OpenMBeanConstructorInfoSupport}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param openOperations The list of exposed operations of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * described open MBean.  Must be an array of instances of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * subclass of {@code MBeanOperationInfo}, typically {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * OpenMBeanOperationInfoSupport}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @param notifications The list of notifications emitted by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * described open MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param descriptor The descriptor for the MBean.  This may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * which is equivalent to an empty descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @throws ArrayStoreException If {@code openAttributes}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * openConstructors} or {@code openOperations} is not an array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * instances of a subclass of {@code MBeanAttributeInfo}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * MBeanConstructorInfo} or {@code MBeanOperationInfo}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public OpenMBeanInfoSupport(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                OpenMBeanAttributeInfo[] openAttributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                OpenMBeanConstructorInfo[] openConstructors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                OpenMBeanOperationInfo[] openOperations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                MBeanNotificationInfo[] notifications,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                Descriptor descriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        super(className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
              description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
              attributeArray(openAttributes),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
              constructorArray(openConstructors),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
              operationArray(openOperations),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
              (notifications == null) ? null : notifications.clone(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
              descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    private static MBeanAttributeInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            attributeArray(OpenMBeanAttributeInfo[] src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (src == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        MBeanAttributeInfo[] dst = new MBeanAttributeInfo[src.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        System.arraycopy(src, 0, dst, 0, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // may throw an ArrayStoreException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private static MBeanConstructorInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            constructorArray(OpenMBeanConstructorInfo[] src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (src == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        MBeanConstructorInfo[] dst = new MBeanConstructorInfo[src.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        System.arraycopy(src, 0, dst, 0, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        // may throw an ArrayStoreException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        return dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    private static MBeanOperationInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            operationArray(OpenMBeanOperationInfo[] src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        if (src == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        MBeanOperationInfo[] dst = new MBeanOperationInfo[src.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        System.arraycopy(src, 0, dst, 0, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return dst;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /* ***  Commodity methods from java.lang.Object  *** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * <p>Compares the specified {@code obj} parameter with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * {@code OpenMBeanInfoSupport} instance for equality.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * <p>Returns {@code true} if and only if all of the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * statements are true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * <li>{@code obj} is non null,</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * <li>{@code obj} also implements the {@code OpenMBeanInfo}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * interface,</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * <li>their class names are equal</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * <li>their infos on attributes, constructors, operations and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * notifications are equal</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * This ensures that this {@code equals} method works properly for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * {@code obj} parameters which are different implementations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * the {@code OpenMBeanInfo} interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @param obj the object to be compared for equality with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * {@code OpenMBeanInfoSupport} instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @return {@code true} if the specified object is equal to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * {@code OpenMBeanInfoSupport} instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        // if obj is null, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (obj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        // if obj is not a OpenMBeanInfo, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        OpenMBeanInfo other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            other = (OpenMBeanInfo) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        // Now, really test for equality between this OpenMBeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        // implementation and the other:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        // their MBean className should be equal
19845
6f149007b02c 8023529: OpenMBeanInfoSupport.equals/hashCode throw NPE
sjiang
parents: 5506
diff changeset
   273
        if (!Objects.equals(this.getClassName(), other.getClassName())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return false;
19845
6f149007b02c 8023529: OpenMBeanInfoSupport.equals/hashCode throw NPE
sjiang
parents: 5506
diff changeset
   275
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        // their infos on attributes should be equal (order not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        // significant => equality between sets, not arrays or lists)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (!sameArrayContents(this.getAttributes(), other.getAttributes()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        // their infos on constructors should be equal (order not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        // significant => equality between sets, not arrays or lists)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (!sameArrayContents(this.getConstructors(), other.getConstructors()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        // their infos on operations should be equal (order not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        // significant => equality between sets, not arrays or lists)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (!sameArrayContents(this.getOperations(), other.getOperations()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        // their infos on notifications should be equal (order not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        // significant => equality between sets, not arrays or lists)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (!sameArrayContents(this.getNotifications(), other.getNotifications()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // All tests for equality were successful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    private static <T> boolean sameArrayContents(T[] a1, T[] a2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return (new HashSet<T>(Arrays.asList(a1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                .equals(new HashSet<T>(Arrays.asList(a2))));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * <p>Returns the hash code value for this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * OpenMBeanInfoSupport} instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * <p>The hash code of an {@code OpenMBeanInfoSupport} instance is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * the sum of the hash codes of all elements of information used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * in {@code equals} comparisons (ie: its class name, and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * infos on attributes, constructors, operations and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * notifications, where the hashCode of each of these arrays is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * calculated by a call to {@code new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * java.util.HashSet(java.util.Arrays.asList(this.getSignature)).hashCode()}).</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * <p>This ensures that {@code t1.equals(t2)} implies that {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * t1.hashCode()==t2.hashCode()} for any two {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * OpenMBeanInfoSupport} instances {@code t1} and {@code t2}, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * required by the general contract of the method {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Object#hashCode() Object.hashCode()}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * <p>However, note that another instance of a class implementing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * the {@code OpenMBeanInfo} interface may be equal to this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * OpenMBeanInfoSupport} instance as defined by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * #equals(java.lang.Object)}, but may have a different hash code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * if it is calculated differently.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * <p>As {@code OpenMBeanInfoSupport} instances are immutable, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * hash code for this instance is calculated once, on the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * call to {@code hashCode}, and then the same value is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * for subsequent calls.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @return the hash code value for this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * OpenMBeanInfoSupport} instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        // Calculate the hash code value if it has not yet been done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        // (ie 1st call to hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (myHashCode == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            int value = 0;
19845
6f149007b02c 8023529: OpenMBeanInfoSupport.equals/hashCode throw NPE
sjiang
parents: 5506
diff changeset
   347
            if (this.getClassName() != null) {
6f149007b02c 8023529: OpenMBeanInfoSupport.equals/hashCode throw NPE
sjiang
parents: 5506
diff changeset
   348
                value += this.getClassName().hashCode();
6f149007b02c 8023529: OpenMBeanInfoSupport.equals/hashCode throw NPE
sjiang
parents: 5506
diff changeset
   349
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            value += arraySetHash(this.getAttributes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            value += arraySetHash(this.getConstructors());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            value += arraySetHash(this.getOperations());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            value += arraySetHash(this.getNotifications());
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   354
            myHashCode = Integer.valueOf(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        // return always the same hash code for this instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return myHashCode.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    private static <T> int arraySetHash(T[] a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        return new HashSet<T>(Arrays.asList(a)).hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * <p>Returns a string representation of this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * OpenMBeanInfoSupport} instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * <p>The string representation consists of the name of this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * (ie {@code javax.management.openmbean.OpenMBeanInfoSupport}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * the MBean class name, the string representation of infos on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * attributes, constructors, operations and notifications of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * described MBean and the string representation of the descriptor.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * <p>As {@code OpenMBeanInfoSupport} instances are immutable, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * string representation for this instance is calculated once, on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * the first call to {@code toString}, and then the same value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * returned for subsequent calls.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @return a string representation of this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * OpenMBeanInfoSupport} instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        // Calculate the string value if it has not yet been done (ie
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        // 1st call to toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        if (myToString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            myToString = new StringBuilder()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                .append(this.getClass().getName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                .append("(mbean_class_name=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                .append(this.getClassName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                .append(",attributes=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                .append(Arrays.asList(this.getAttributes()).toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                .append(",constructors=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                .append(Arrays.asList(this.getConstructors()).toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                .append(",operations=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                .append(Arrays.asList(this.getOperations()).toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                .append(",notifications=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                .append(Arrays.asList(this.getNotifications()).toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                .append(",descriptor=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                .append(this.getDescriptor())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                .append(")")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                .toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        // return always the same string representation for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        // instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        return myToString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
}