src/java.management/share/classes/javax/management/MBeanAttributeInfo.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
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 20174
diff changeset
     2
 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
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: 4156
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: 4156
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
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
package javax.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.jmx.mbeanserver.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.jmx.mbeanserver.Introspector;
19852
f8e5a6c5d379 8023669: MBean*Info.hashCode : NPE
sjiang
parents: 5506
diff changeset
    33
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Describes an MBean attribute exposed for management.  Instances of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * this class are immutable.  Subclasses may be mutable but this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
@SuppressWarnings("serial")  // serialVersionUID not constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public class MBeanAttributeInfo extends MBeanFeatureInfo implements Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static final long serialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        /* For complicated reasons, the serialVersionUID changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
           between JMX 1.0 and JMX 1.1, even though JMX 1.1 did not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
           have compatibility code for this class.  So the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
           serialization produced by this class with JMX 1.2 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
           jmx.serial.form=1.0 is not the same as that produced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
           this class with JMX 1.1 and jmx.serial.form=1.0.  However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
           the serialization without that property is the same, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
           that is the only form required by JMX 1.2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        long uid = 8644704819898565848L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            String form = AccessController.doPrivileged(act);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            if ("1.0".equals(form))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                uid = 7043855487133450673L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            // OK: exception means no compat with 1.0, too bad
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        serialVersionUID = uid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    static final MBeanAttributeInfo[] NO_ATTRIBUTES =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        new MBeanAttributeInfo[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @serial The actual attribute type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private final String attributeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @serial The attribute write right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private final boolean isWrite;
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 attribute read right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private final boolean isRead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @serial Indicates if this method is a "is"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private final boolean is;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
    95
     * Constructs an {@code MBeanAttributeInfo} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param name The name of the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param type The type or class name of the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param description A human readable description of the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param isReadable True if the attribute has a getter method, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param isWritable True if the attribute has a setter method, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param isIs True if this attribute has an "is" getter, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @throws IllegalArgumentException if {@code isIs} is true but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * {@code isReadable} is not, or if {@code isIs} is true and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * {@code type} is not {@code boolean} or {@code java.lang.Boolean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * (New code should always use {@code boolean} rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * {@code java.lang.Boolean}.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public MBeanAttributeInfo(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                              String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                              String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                              boolean isReadable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                              boolean isWritable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                              boolean isIs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        this(name, type, description, isReadable, isWritable, isIs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
             (Descriptor) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   121
     * Constructs an {@code MBeanAttributeInfo} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param name The name of the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @param type The type or class name of the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param description A human readable description of the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @param isReadable True if the attribute has a getter method, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param isWritable True if the attribute has a setter method, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param isIs True if this attribute has an "is" getter, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @param descriptor The descriptor for the attribute.  This may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * which is equivalent to an empty descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @throws IllegalArgumentException if {@code isIs} is true but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * {@code isReadable} is not, or if {@code isIs} is true and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * {@code type} is not {@code boolean} or {@code java.lang.Boolean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * (New code should always use {@code boolean} rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * {@code java.lang.Boolean}.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public MBeanAttributeInfo(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                              String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                              String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                              boolean isReadable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                              boolean isWritable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                              boolean isIs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                              Descriptor descriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        super(name, description, descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        this.attributeType = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        this.isRead = isReadable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        this.isWrite = isWritable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (isIs && !isReadable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            throw new IllegalArgumentException("Cannot have an \"is\" getter " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                               "for a non-readable attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (isIs && !type.equals("java.lang.Boolean") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                !type.equals("boolean")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            throw new IllegalArgumentException("Cannot have an \"is\" getter " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                               "for a non-boolean attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        this.is = isIs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * <p>This constructor takes the name of a simple attribute, and Method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * objects for reading and writing the attribute.  The {@link Descriptor}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * of the constructed object will include fields contributed by any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * annotations on the {@code Method} objects that contain the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * {@link DescriptorKey} meta-annotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @param name The programmatic name of the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param description A human readable description of the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @param getter The method used for reading the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *          May be null if the property is write-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param setter The method used for writing the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *          May be null if the attribute is read-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @exception IntrospectionException There is a consistency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * problem in the definition of this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public MBeanAttributeInfo(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                              String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                              Method getter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                              Method setter) throws IntrospectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        this(name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
             attributeType(getter, setter),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
             description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
             (getter != null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
             (setter != null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
             isIs(getter),
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1714
diff changeset
   190
             ImmutableDescriptor.union(Introspector.descriptorForElement(getter),
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1714
diff changeset
   191
                                   Introspector.descriptorForElement(setter)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * <p>Returns a shallow clone of this instance.
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   196
     * The clone is obtained by simply calling {@code super.clone()},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * thus calling the default native shallow cloning mechanism
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   198
     * implemented by {@code Object.clone()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * No deeper cloning of any internal field is made.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * <p>Since this class is immutable, cloning is chiefly of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * interest to subclasses.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     public Object clone () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
             return super.clone() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
         } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
             // should not happen as this class is cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
             return 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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Returns the class name of the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @return the class name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return attributeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Whether the value of the attribute can be read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @return True if the attribute can be read, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public boolean isReadable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return isRead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Whether new values can be written to the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @return True if the attribute can be written to, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public boolean isWritable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return isWrite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Indicates if this attribute has an "is" getter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @return true if this attribute has an "is" getter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public boolean isIs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return is;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        String access;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (isReadable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            if (isWritable())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                access = "read/write";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                access = "read-only";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        } else if (isWritable())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            access = "write-only";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            access = "no-access";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            getClass().getName() + "[" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            "description=" + getDescription() + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            "name=" + getName() + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            "type=" + getType() + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            access + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            (isIs() ? "isIs, " : "") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            "descriptor=" + getDescriptor() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Compare this MBeanAttributeInfo to another.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @param o the object to compare to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   277
     * @return true if and only if {@code o} is an MBeanAttributeInfo such
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * that its {@link #getName()}, {@link #getType()}, {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * #getDescription()}, {@link #isReadable()}, {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * #isWritable()}, and {@link #isIs()} values are equal (not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * necessarily identical) to those of this MBeanAttributeInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (o == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (!(o instanceof MBeanAttributeInfo))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        MBeanAttributeInfo p = (MBeanAttributeInfo) o;
20174
360791181f66 8023954: MBean*Info.equals: throw NPE
sjiang
parents: 19852
diff changeset
   289
        return (Objects.equals(p.getName(), getName()) &&
360791181f66 8023954: MBean*Info.equals: throw NPE
sjiang
parents: 19852
diff changeset
   290
                Objects.equals(p.getType(), getType()) &&
360791181f66 8023954: MBean*Info.equals: throw NPE
sjiang
parents: 19852
diff changeset
   291
                Objects.equals(p.getDescription(), getDescription()) &&
360791181f66 8023954: MBean*Info.equals: throw NPE
sjiang
parents: 19852
diff changeset
   292
                Objects.equals(p.getDescriptor(), getDescriptor()) &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                p.isReadable() == isReadable() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                p.isWritable() == isWritable() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                p.isIs() == isIs());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /* We do not include everything in the hashcode.  We assume that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
       if two operations are different they'll probably have different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
       names or types.  The penalty we pay when this assumption is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
       wrong should be less than the penalty we would pay if it were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
       right and we needlessly hashed in the description and parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
       array.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public int hashCode() {
19852
f8e5a6c5d379 8023669: MBean*Info.hashCode : NPE
sjiang
parents: 5506
diff changeset
   305
        return Objects.hash(getName(), getType());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    private static boolean isIs(Method getter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        return (getter != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                getter.getName().startsWith("is") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                (getter.getReturnType().equals(Boolean.TYPE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                 getter.getReturnType().equals(Boolean.class)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * Finds the type of the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    private static String attributeType(Method getter, Method setter)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            throws IntrospectionException {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   320
        Class<?> type = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if (getter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            if (getter.getParameterTypes().length != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                throw new IntrospectionException("bad getter arg count");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            type = getter.getReturnType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            if (type == Void.TYPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                throw new IntrospectionException("getter " + getter.getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                                                 " returns void");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (setter != null) {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   334
            Class<?> params[] = setter.getParameterTypes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            if (params.length != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                throw new IntrospectionException("bad setter arg count");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            if (type == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                type = params[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            else if (type != params[0]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                throw new IntrospectionException("type mismatch between " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                                                 "getter and setter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if (type == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            throw new IntrospectionException("getter and setter cannot " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                                             "both be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        return type.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
}