src/java.management/share/classes/javax/management/openmbean/OpenMBeanOperationInfoSupport.java
author rriggs
Fri, 07 Dec 2018 11:51:17 -0500
changeset 52902 e3398b2e1ab0
parent 47216 71c04702a3d5
permissions -rw-r--r--
8214971: Replace use of string.equals("") with isEmpty() Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     2
 * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.management.Descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.management.ImmutableDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.management.MBeanOperationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.management.MBeanParameterInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Describes an operation of an Open MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class OpenMBeanOperationInfoSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    extends MBeanOperationInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    implements OpenMBeanOperationInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static final long serialVersionUID = 4996859732565369366L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * @serial The <i>open type</i> of the values returned by the operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     *         described by this {@link OpenMBeanOperationInfo} instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private OpenType<?> returnOpenType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    // As this instance is immutable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    // these two values 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 OpenMBeanOperationInfoSupport}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * instance, which describes the operation of a class of open
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * MBeans, with the specified {@code name}, {@code description},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * {@code signature}, {@code returnOpenType} and {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * impact}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <p>The {@code signature} array parameter is internally copied,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * so that subsequent changes to the array referenced by {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * signature} have no effect on this instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param name cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param description cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @param signature can be null or empty if there are no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * parameters to describe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param returnOpenType cannot be null: use {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * SimpleType.VOID} for operations that return nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param impact must be one of {@code ACTION}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * ACTION_INFO}, {@code INFO}, or {@code UNKNOWN}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @throws IllegalArgumentException if {@code name} or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * description} are null or empty string, or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * returnOpenType} is null, or {@code impact} is not one of {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * ACTION}, {@code ACTION_INFO}, {@code INFO}, or {@code UNKNOWN}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @throws ArrayStoreException If {@code signature} is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * array of instances of a subclass of {@code MBeanParameterInfo}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public OpenMBeanOperationInfoSupport(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                         String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                         OpenMBeanParameterInfo[] signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                                         OpenType<?> returnOpenType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                                         int impact) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        this(name, description, signature, returnOpenType, impact,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
             (Descriptor) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * <p>Constructs an {@code OpenMBeanOperationInfoSupport}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * instance, which describes the operation of a class of open
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * MBeans, with the specified {@code name}, {@code description},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * {@code signature}, {@code returnOpenType}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * impact}, and {@code descriptor}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * <p>The {@code signature} array parameter is internally copied,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * so that subsequent changes to the array referenced by {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * signature} have no effect on this instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @param name cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param description cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param signature can be null or empty if there are no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * parameters to describe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @param returnOpenType cannot be null: use {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * SimpleType.VOID} for operations that return nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @param impact must be one of {@code ACTION}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * ACTION_INFO}, {@code INFO}, or {@code UNKNOWN}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param descriptor The descriptor for the operation.  This may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * be null, which is equivalent to an empty descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @throws IllegalArgumentException if {@code name} or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * description} are null or empty string, or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * returnOpenType} is null, or {@code impact} is not one of {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * ACTION}, {@code ACTION_INFO}, {@code INFO}, or {@code UNKNOWN}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @throws ArrayStoreException If {@code signature} is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * array of instances of a subclass of {@code MBeanParameterInfo}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public OpenMBeanOperationInfoSupport(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                                         String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                         OpenMBeanParameterInfo[] signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                                         OpenType<?> returnOpenType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                         int impact,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                         Descriptor descriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        super(name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
              description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
              arrayCopyCast(signature),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
              // must prevent NPE here - we will throw IAE later on if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
              // returnOpenType is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
              (returnOpenType == null) ? null : returnOpenType.getClassName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
              impact,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
              ImmutableDescriptor.union(descriptor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                // must prevent NPE here - we will throw IAE later on if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                // returnOpenType is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                (returnOpenType==null) ? null :returnOpenType.getDescriptor()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        // check parameters that should not be null or empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        // (unfortunately it is not done in superclass :-( ! )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        //
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
   166
        if (name == null || name.trim().isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            throw new IllegalArgumentException("Argument name cannot " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                               "be null or empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
   170
        if (description == null || description.trim().isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            throw new IllegalArgumentException("Argument description cannot " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                               "be null or empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (returnOpenType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            throw new IllegalArgumentException("Argument returnOpenType " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                               "cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (impact != ACTION && impact != ACTION_INFO && impact != INFO &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                impact != UNKNOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            throw new IllegalArgumentException("Argument impact can only be " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                               "one of ACTION, ACTION_INFO, " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                               "INFO, or UNKNOWN: " + impact);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        this.returnOpenType = returnOpenType;
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
    // Converts an array of OpenMBeanParameterInfo objects extending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    // MBeanParameterInfo into an array of MBeanParameterInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private static MBeanParameterInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            arrayCopyCast(OpenMBeanParameterInfo[] src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (src == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        MBeanParameterInfo[] dst = new MBeanParameterInfo[src.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        System.arraycopy(src, 0, dst, 0, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        // may throw an ArrayStoreException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    // Converts an array of MBeanParameterInfo objects implementing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    // OpenMBeanParameterInfo into an array of OpenMBeanParameterInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    private static OpenMBeanParameterInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            arrayCopyCast(MBeanParameterInfo[] src) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (src == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        OpenMBeanParameterInfo[] dst = new OpenMBeanParameterInfo[src.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        System.arraycopy(src, 0, dst, 0, src.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        // may throw an ArrayStoreException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    // [JF]: should we add constructor with java.lang.reflect.Method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    // method parameter ?  would need to add consistency check between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    // OpenType<?> returnOpenType and method.getReturnType().
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
     * Returns the <i>open type</i> of the values returned by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * operation described by this {@code OpenMBeanOperationInfo}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public OpenType<?> getReturnOpenType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return returnOpenType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /* ***  Commodity methods from java.lang.Object  *** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * <p>Compares the specified {@code obj} parameter with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * {@code OpenMBeanOperationInfoSupport} instance for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * equality.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * <p>Returns {@code true} if and only if all of the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * statements are true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * <li>{@code obj} is non null,</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * <li>{@code obj} also implements the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * OpenMBeanOperationInfo} interface,</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <li>their names are equal</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * <li>their signatures are equal</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * <li>their return open types are equal</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * <li>their impacts are equal</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * This ensures that this {@code equals} method works properly for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * {@code obj} parameters which are different implementations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * the {@code OpenMBeanOperationInfo} interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @param obj the object to be compared for equality with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * {@code OpenMBeanOperationInfoSupport} instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @return {@code true} if the specified object is equal to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * {@code OpenMBeanOperationInfoSupport} instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        // if obj is null, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if (obj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        // if obj is not a OpenMBeanOperationInfo, return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        OpenMBeanOperationInfo other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            other = (OpenMBeanOperationInfo) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        // Now, really test for equality between this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        // OpenMBeanOperationInfo implementation and the other:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        // their Name should be equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if ( ! this.getName().equals(other.getName()) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        // their Signatures should be equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if ( ! Arrays.equals(this.getSignature(), other.getSignature()) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // their return open types should be equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if ( ! this.getReturnOpenType().equals(other.getReturnOpenType()) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        // their impacts should be equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if ( this.getImpact() != other.getImpact() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        // All tests for equality were successfull
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        return true;
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
     * <p>Returns the hash code value for this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * OpenMBeanOperationInfoSupport} instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * <p>The hash code of an {@code OpenMBeanOperationInfoSupport}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * instance is the sum of the hash codes of all elements of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * information used in {@code equals} comparisons (ie: its name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * return open type, impact and signature, where the signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * hashCode is calculated by a call to {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * java.util.Arrays.asList(this.getSignature).hashCode()}).</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * <p>This ensures that {@code t1.equals(t2) } implies that {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * t1.hashCode()==t2.hashCode() } for any two {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * OpenMBeanOperationInfoSupport} instances {@code t1} and {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * t2}, as required by the general contract of the method {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Object#hashCode() Object.hashCode()}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * <p>However, note that another instance of a class implementing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * the {@code OpenMBeanOperationInfo} interface may be equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * this {@code OpenMBeanOperationInfoSupport} instance as defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * by {@link #equals(java.lang.Object)}, but may have a different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * hash code if it is calculated differently.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * <p>As {@code OpenMBeanOperationInfoSupport} instances are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * immutable, the hash code for this instance is calculated once,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * on the first call to {@code hashCode}, and then the same value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * is returned for subsequent calls.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @return the hash code value for this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * OpenMBeanOperationInfoSupport} instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        // Calculate the hash code value if it has not yet been done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        // (ie 1st call to hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if (myHashCode == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            int value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            value += this.getName().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            value += Arrays.asList(this.getSignature()).hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            value += this.getReturnOpenType().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            value += this.getImpact();
527
a33264d48a84 6703552: Missing files from changeset for 6701459
emcmanus
parents: 2
diff changeset
   355
            myHashCode = Integer.valueOf(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        // return always the same hash code for this instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        return myHashCode.intValue();
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
     * <p>Returns a string representation of this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * OpenMBeanOperationInfoSupport} instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * <p>The string representation consists of the name of this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * (ie {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * javax.management.openmbean.OpenMBeanOperationInfoSupport}), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * the name, signature, return open type and impact of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * described operation and the string representation of its descriptor.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * <p>As {@code OpenMBeanOperationInfoSupport} instances are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * immutable, the string representation for this instance is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * calculated once, on the first call to {@code toString}, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * then the same value is returned for subsequent calls.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @return a string representation of this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * OpenMBeanOperationInfoSupport} instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        // Calculate the hash code value if it has not yet been done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        // (ie 1st call to toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if (myToString == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            myToString = new StringBuilder()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                .append(this.getClass().getName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                .append("(name=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                .append(this.getName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                .append(",signature=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                .append(Arrays.asList(this.getSignature()).toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                .append(",return=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                .append(this.getReturnOpenType().toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                .append(",impact=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                .append(this.getImpact())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                .append(",descriptor=")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                .append(this.getDescriptor())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                .append(")")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                .toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        // return always the same string representation for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        // instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        return myToString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * An object serialized in a version of the API before Descriptors were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * added to this class will have an empty or null Descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * For consistency with our
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * behavior in this version, we must replace the object with one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * where the Descriptors reflect the same value of returned openType.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    private Object readResolve() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        if (getDescriptor().getFieldNames().length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            // This constructor will construct the expected default Descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            return new OpenMBeanOperationInfoSupport(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    name, description, arrayCopyCast(getSignature()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                    returnOpenType, getImpact());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
}