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