src/java.management/share/classes/javax/management/openmbean/OpenMBeanParameterInfoSupport.java
author darcy
Wed, 23 Oct 2019 13:01:40 -0700
changeset 58766 54ffb15c4839
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.* Reviewed-by: rriggs, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58766
54ffb15c4839 8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.*
darcy
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 2019, 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: 1639
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: 1639
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: 1639
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
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.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.management.Descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.management.DescriptorRead;  // for Javadoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.management.ImmutableDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.management.MBeanParameterInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
// OpenMBeanAttributeInfoSupport and this class are very similar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
// but can't easily be refactored because there's no multiple inheritance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
// The best we can do for refactoring is to put a bunch of static methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
// in OpenMBeanAttributeInfoSupport and import them here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import static javax.management.openmbean.OpenMBeanAttributeInfoSupport.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Describes a parameter used in one or more operations or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * constructors of an open MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public class OpenMBeanParameterInfoSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    extends MBeanParameterInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    implements OpenMBeanParameterInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static final long serialVersionUID = -7235016873758443122L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * @serial The open mbean parameter's <i>open type</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
58766
54ffb15c4839 8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.*
darcy
parents: 47216
diff changeset
    61
    @SuppressWarnings("serial") // Not statically typed as Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private OpenType<?>    openType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @serial The open mbean parameter's default value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
58766
54ffb15c4839 8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.*
darcy
parents: 47216
diff changeset
    67
    @SuppressWarnings("serial") // Not statically typed as Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private Object      defaultValue    = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @serial The open mbean parameter's legal values. This {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Set} is unmodifiable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
58766
54ffb15c4839 8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.*
darcy
parents: 47216
diff changeset
    74
    @SuppressWarnings("serial") // Conditionally serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private Set<?> legalValues     = null;  // to be constructed unmodifiable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @serial The open mbean parameter's min value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
58766
54ffb15c4839 8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.*
darcy
parents: 47216
diff changeset
    80
    @SuppressWarnings("serial") // Conditionally serializable
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
    81
    private Comparable<?> minValue        = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @serial The open mbean parameter's max value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
58766
54ffb15c4839 8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.*
darcy
parents: 47216
diff changeset
    86
    @SuppressWarnings("serial") // Conditionally serializable
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
    87
    private Comparable<?> maxValue        = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // As this instance is immutable, these two values need only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // be calculated once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private transient Integer myHashCode = null;        // As this instance is immutable, these two values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private transient String  myToString = null;        // need only be calculated once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Constructs an {@code OpenMBeanParameterInfoSupport} instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * which describes the parameter used in one or more operations or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * constructors of a class of open MBeans, with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * {@code name}, {@code openType} and {@code description}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param name  cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param description  cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param openType  cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @throws IllegalArgumentException if {@code name} or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * description} are null or empty string, or {@code openType} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public OpenMBeanParameterInfoSupport(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                         String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                         OpenType<?> openType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        this(name, description, openType, (Descriptor) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   119
     * Constructs an {@code OpenMBeanParameterInfoSupport} instance,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * which describes the parameter used in one or more operations or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * constructors of a class of open MBeans, with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * {@code name}, {@code openType}, {@code description},
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   123
     * and {@code descriptor}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * <p>The {@code descriptor} can contain entries that will define
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * the values returned by certain methods of this class, as
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   127
     * explained in the <a href="package-summary.html#constraints">
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   128
     * package description</a>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @param name  cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param description  cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @param openType  cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @param descriptor The descriptor for the parameter.  This may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * which is equivalent to an empty descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @throws IllegalArgumentException if {@code name} or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * description} are null or empty string, or {@code openType} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * null, or the descriptor entries are invalid as described in the
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   142
     * <a href="package-summary.html#constraints">package
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
   143
     * description</a>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public OpenMBeanParameterInfoSupport(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                                         String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                         OpenType<?> openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                         Descriptor descriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        // Construct parent's state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        super(name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
              (openType==null) ? null : openType.getClassName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
              description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
              ImmutableDescriptor.union(descriptor,(openType==null)?null:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                openType.getDescriptor()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        // Initialize this instance's specific state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        this.openType = openType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        descriptor = getDescriptor();  // replace null by empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        this.defaultValue = valueFrom(descriptor, "defaultValue", openType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        this.legalValues = valuesFrom(descriptor, "legalValues", openType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        this.minValue = comparableValueFrom(descriptor, "minValue", openType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        this.maxValue = comparableValueFrom(descriptor, "maxValue", openType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            check(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        } catch (OpenDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            throw new IllegalArgumentException(e.getMessage(), e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Constructs an {@code OpenMBeanParameterInfoSupport} instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * which describes the parameter used in one or more operations or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * constructors of a class of open MBeans, with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * {@code name}, {@code openType}, {@code description} and {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * defaultValue}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @param name  cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @param description  cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @param openType  cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param defaultValue must be a valid value for the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * openType} specified for this parameter; default value not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * supported for {@code ArrayType} and {@code TabularType}; can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * null, in which case it means that no default value is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param <T> allows the compiler to check that the {@code defaultValue},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * if non-null, has the correct Java type for the given {@code openType}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @throws IllegalArgumentException if {@code name} or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * description} are null or empty string, or {@code openType} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @throws OpenDataException if {@code defaultValue} is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * valid value for the specified {@code openType}, or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * defaultValue} is non null and {@code openType} is an {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * ArrayType} or a {@code TabularType}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public <T> OpenMBeanParameterInfoSupport(String   name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                             String   description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                                             OpenType<T> openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                             T        defaultValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            throws OpenDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        this(name, description, openType, defaultValue, (T[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * <p>Constructs an {@code OpenMBeanParameterInfoSupport} instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * which describes the parameter used in one or more operations or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * constructors of a class of open MBeans, with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * {@code name}, {@code openType}, {@code description}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * defaultValue} and {@code legalValues}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * <p>The contents of {@code legalValues} are copied, so subsequent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * modifications of the array referenced by {@code legalValues}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * have no impact on this {@code OpenMBeanParameterInfoSupport}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @param name  cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @param description  cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param openType  cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param defaultValue must be a valid value for the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * openType} specified for this parameter; default value not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * supported for {@code ArrayType} and {@code TabularType}; can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * null, in which case it means that no default value is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @param legalValues each contained value must be valid for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * {@code openType} specified for this parameter; legal values not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * supported for {@code ArrayType} and {@code TabularType}; can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * null or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @param <T> allows the compiler to check that the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * defaultValue} and {@code legalValues}, if non-null, have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * correct Java type for the given {@code openType}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @throws IllegalArgumentException if {@code name} or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * description} are null or empty string, or {@code openType} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @throws OpenDataException if {@code defaultValue} is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * valid value for the specified {@code openType}, or one value in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * {@code legalValues} is not valid for the specified {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * openType}, or {@code defaultValue} is non null and {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * openType} is an {@code ArrayType} or a {@code TabularType}, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * {@code legalValues} is non null and non empty and {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * openType} is an {@code ArrayType} or a {@code TabularType}, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * {@code legalValues} is non null and non empty and {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * defaultValue} is not contained in {@code legalValues}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public <T> OpenMBeanParameterInfoSupport(String   name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                                             String   description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                                             OpenType<T> openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                                             T        defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                                             T[]      legalValues)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            throws OpenDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        this(name, description, openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
             defaultValue, legalValues, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * Constructs an {@code OpenMBeanParameterInfoSupport} instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * which describes the parameter used in one or more operations or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * constructors of a class of open MBeans, with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * {@code name}, {@code openType}, {@code description}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * defaultValue}, {@code minValue} and {@code maxValue}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * It is possible to specify minimal and maximal values only for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * an open type whose values are {@code Comparable}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @param name  cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @param description  cannot be a null or empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @param openType  cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @param defaultValue must be a valid value for the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * openType} specified for this parameter; default value not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * supported for {@code ArrayType} and {@code TabularType}; can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * null, in which case it means that no default value is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @param minValue must be valid for the {@code openType}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * specified for this parameter; can be null, in which case it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * means that no minimal value is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @param maxValue must be valid for the {@code openType}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * specified for this parameter; can be null, in which case it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * means that no maximal value is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param <T> allows the compiler to check that the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * defaultValue}, {@code minValue}, and {@code maxValue}, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * non-null, have the correct Java type for the given {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * openType}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @throws IllegalArgumentException if {@code name} or {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * description} are null or empty string, or {@code openType} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @throws OpenDataException if {@code defaultValue}, {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * minValue} or {@code maxValue} is not a valid value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * specified {@code openType}, or {@code defaultValue} is non null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * and {@code openType} is an {@code ArrayType} or a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * TabularType}, or both {@code minValue} and {@code maxValue} are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * non-null and {@code minValue.compareTo(maxValue) > 0} is {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * true}, or both {@code defaultValue} and {@code minValue} are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * non-null and {@code minValue.compareTo(defaultValue) > 0} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * {@code true}, or both {@code defaultValue} and {@code maxValue}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * are non-null and {@code defaultValue.compareTo(maxValue) > 0}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * is {@code true}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public <T> OpenMBeanParameterInfoSupport(String     name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                             String     description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                                             OpenType<T>   openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                                             T          defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                                             Comparable<T> minValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                                             Comparable<T> maxValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            throws OpenDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        this(name, description, openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
             defaultValue, null, minValue, maxValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    private <T> OpenMBeanParameterInfoSupport(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                                              String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                                              OpenType<T> openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                                              T defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                                              T[] legalValues,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                                              Comparable<T> minValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                              Comparable<T> maxValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            throws OpenDataException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        super(name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
              (openType == null) ? null : openType.getClassName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
              description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
              makeDescriptor(openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                             defaultValue, legalValues, minValue, maxValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        this.openType = openType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        Descriptor d = getDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        this.defaultValue = defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        this.minValue = minValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        this.maxValue = maxValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        // We already converted the array into an unmodifiable Set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        // in the descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        this.legalValues = (Set<?>) d.getFieldValue("legalValues");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        check(this);
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
     * An object serialized in a version of the API before Descriptors were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * added to this class will have an empty or null Descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * For consistency with our
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * behavior in this version, we must replace the object with one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * where the Descriptors reflect the same values of openType, defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    private Object readResolve() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        if (getDescriptor().getFieldNames().length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            // This noise allows us to avoid "unchecked" warnings without
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            // having to suppress them explicitly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            OpenType<Object> xopenType = cast(openType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            Set<Object> xlegalValues = cast(legalValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            Comparable<Object> xminValue = cast(minValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            Comparable<Object> xmaxValue = cast(maxValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            return new OpenMBeanParameterInfoSupport(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    name, description, openType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                    makeDescriptor(xopenType, defaultValue, xlegalValues,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                                   xminValue, xmaxValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * Returns the open type for the values of the parameter described
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * by this {@code OpenMBeanParameterInfoSupport} instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    public OpenType<?> getOpenType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        return openType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * Returns the default value for the parameter described by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * {@code OpenMBeanParameterInfoSupport} instance, if specified,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * or {@code null} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    public Object getDefaultValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        // Special case for ArrayType and TabularType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        // [JF] TODO: clone it so that it cannot be altered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        // [JF] TODO: if we decide to support defaultValue as an array itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        // [JF] As of today (oct 2000) it is not supported so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        // defaultValue is null for arrays. Nothing to do.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Returns an unmodifiable Set of legal values for the parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * described by this {@code OpenMBeanParameterInfoSupport}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * instance, if specified, or {@code null} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    public Set<?> getLegalValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        // Special case for ArrayType and TabularType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        // [JF] TODO: clone values so that they cannot be altered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        // [JF] TODO: if we decide to support LegalValues as an array itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        // [JF] As of today (oct 2000) it is not supported so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        // legalValues is null for arrays. Nothing to do.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        // Returns our legalValues Set (set was constructed unmodifiable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        return (legalValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * Returns the minimal value for the parameter described by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * {@code OpenMBeanParameterInfoSupport} instance, if specified,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * or {@code null} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public Comparable<?> getMinValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        // Note: only comparable values have a minValue, so that's not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        // the case of arrays and tabulars (always null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        return minValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * Returns the maximal value for the parameter described by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * {@code OpenMBeanParameterInfoSupport} instance, if specified,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * or {@code null} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    public Comparable<?> getMaxValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        // Note: only comparable values have a maxValue, so that's not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        // the case of arrays and tabulars (always null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        return maxValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * Returns {@code true} if this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * OpenMBeanParameterInfoSupport} instance specifies a non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * default value for the described parameter, {@code false}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    public boolean hasDefaultValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return (defaultValue != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * Returns {@code true} if this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * OpenMBeanParameterInfoSupport} instance specifies a non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * set of legal values for the described parameter, {@code false}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    public boolean hasLegalValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        return (legalValues != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * Returns {@code true} if this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * OpenMBeanParameterInfoSupport} instance specifies a non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * minimal value for the described parameter, {@code false}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    public boolean hasMinValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return (minValue != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * Returns {@code true} if this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * OpenMBeanParameterInfoSupport} instance specifies a non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * maximal value for the described parameter, {@code false}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    public boolean hasMaxValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        return (maxValue != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * Tests whether {@code obj} is a valid value for the parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * described by this {@code OpenMBeanParameterInfo} instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @param obj the object to be tested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @return {@code true} if {@code obj} is a valid value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * for the parameter described by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * {@code OpenMBeanParameterInfo} instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    public boolean isValue(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        return OpenMBeanAttributeInfoSupport.isValue(this, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        // compiler bug? should be able to omit class name here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        // also below in toString and hashCode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    /* ***  Commodity methods from java.lang.Object  *** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * <p>Compares the specified {@code obj} parameter with this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * OpenMBeanParameterInfoSupport} instance for equality.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * <p>Returns {@code true} if and only if all of the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * statements are true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * <li>{@code obj} is non null,</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * <li>{@code obj} also implements the {@code OpenMBeanParameterInfo}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * interface,</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * <li>their names are equal</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * <li>their open types are equal</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * <li>their default, min, max and legal values are equal.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * This ensures that this {@code equals} method works properly for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * {@code obj} parameters which are different implementations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * the {@code OpenMBeanParameterInfo} interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * <p>If {@code obj} also implements {@link DescriptorRead}, then its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * {@link DescriptorRead#getDescriptor() getDescriptor()} method must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * also return the same value as for this object.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * @param obj the object to be compared for equality with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * {@code OpenMBeanParameterInfoSupport} instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * @return {@code true} if the specified object is equal to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * {@code OpenMBeanParameterInfoSupport} instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        if (!(obj instanceof OpenMBeanParameterInfo))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        OpenMBeanParameterInfo other = (OpenMBeanParameterInfo) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        return equal(this, other);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * <p>Returns the hash code value for this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * OpenMBeanParameterInfoSupport} instance.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * <p>The hash code of an {@code OpenMBeanParameterInfoSupport}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * instance is the sum of the hash codes of all elements of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * information used in {@code equals} comparisons (ie: its name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * its <i>open type</i>, its default, min, max and legal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * values, and its Descriptor).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * <p>This ensures that {@code t1.equals(t2)} implies that {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * t1.hashCode()==t2.hashCode()} for any two {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * OpenMBeanParameterInfoSupport} instances {@code t1} and {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * t2}, as required by the general contract of the method {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * Object#hashCode() Object.hashCode()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * <p>However, note that another instance of a class implementing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * the {@code OpenMBeanParameterInfo} interface may be equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * this {@code OpenMBeanParameterInfoSupport} instance as defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * by {@link #equals(java.lang.Object)}, but may have a different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * hash code if it is calculated differently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * <p>As {@code OpenMBeanParameterInfoSupport} instances are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * immutable, the hash code for this instance is calculated once,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * on the first call to {@code hashCode}, and then the same value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * is returned for subsequent calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @return the hash code value for this {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * OpenMBeanParameterInfoSupport} instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        // Calculate the hash code value if it has not yet been done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        // (ie 1st call to hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        if (myHashCode == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            myHashCode = OpenMBeanAttributeInfoSupport.hashCode(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        // return always the same hash code for this instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        return myHashCode.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * Returns a string representation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * {@code OpenMBeanParameterInfoSupport} instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * The string representation consists of the name of this class (i.e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * {@code javax.management.openmbean.OpenMBeanParameterInfoSupport}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * the string representation of the name and open type of the described
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * parameter, the string representation of its default, min, max and legal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * values and the string representation of its descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * As {@code OpenMBeanParameterInfoSupport} instances are immutable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * the string representation for this instance is calculated once,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * on the first call to {@code toString}, and then the same value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * is returned for subsequent calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * @return a string representation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * {@code OpenMBeanParameterInfoSupport} instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        // Calculate the string value if it has not yet been done (ie
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        // 1st call to toString())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        if (myToString == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            myToString = OpenMBeanAttributeInfoSupport.toString(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        // return always the same string representation for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        // instance (immutable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        return myToString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
}