jdk/src/share/classes/javax/management/MBeanOperationInfo.java
author sjiang
Thu, 31 Jul 2008 15:31:13 +0200
changeset 1004 5ba8217eb504
parent 833 bfa2bef7517c
child 1247 b4c26443dee5
permissions -rw-r--r--
5108776: Add reliable event handling to the JMX API 6218920: API bug - impossible to delete last MBeanServerForwarder on a connector Reviewed-by: emcmanus
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 1999-2006 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
package javax.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.jmx.mbeanserver.Introspector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.annotation.Annotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Describes a management operation exposed by an MBean.  Instances of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * this class are immutable.  Subclasses may be mutable but this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class MBeanOperationInfo extends MBeanFeatureInfo implements Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    static final long serialVersionUID = -6178860474881375330L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static final MBeanOperationInfo[] NO_OPERATIONS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        new MBeanOperationInfo[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /**
833
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    49
     * Indicates that the operation is read-like:
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    50
     * it returns information but does not change any state.
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    51
     * @see Impact#INFO
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static final int INFO = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
833
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    56
     * Indicates that the operation is write-like: it has an effect but does
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    57
     * not return any information from the MBean.
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    58
     * @see Impact#ACTION
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public static final int ACTION = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
833
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    63
     * Indicates that the operation is both read-like and write-like:
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    64
     * it has an effect, and it also returns information from the MBean.
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    65
     * @see Impact#ACTION_INFO
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public static final int ACTION_INFO = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
833
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    70
     * Indicates that the impact of the operation is unknown or cannot be
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    71
     * expressed using one of the other values.
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
    72
     * @see Impact#UNKNOWN
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static final int UNKNOWN = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @serial The method's return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private final String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @serial The signature of the method, that is, the class names
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * of the arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private final MBeanParameterInfo[] signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @serial The impact of the method, one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *         <CODE>INFO</CODE>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *         <CODE>ACTION</CODE>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *         <CODE>ACTION_INFO</CODE>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *         <CODE>UNKNOWN</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private final int impact;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /** @see MBeanInfo#arrayGettersSafe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private final transient boolean arrayGettersSafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Constructs an <CODE>MBeanOperationInfo</CODE> object.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * {@link Descriptor} of the constructed object will include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * fields contributed by any annotations on the {@code Method}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * object that contain the {@link DescriptorKey} meta-annotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param method The <CODE>java.lang.reflect.Method</CODE> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * describing the MBean operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param description A human readable description of the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public MBeanOperationInfo(String description, Method method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this(method.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
             description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
             methodSignature(method),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
             method.getReturnType().getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
             UNKNOWN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
             Introspector.descriptorForElement(method));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Constructs an <CODE>MBeanOperationInfo</CODE> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param name The name of the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param description A human readable description of the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @param signature <CODE>MBeanParameterInfo</CODE> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * describing the parameters(arguments) of the method.  This may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * null with the same effect as a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param type The type of the method's return value.
833
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   128
     * @param impact The impact of the method, one of
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   129
     * {@link #INFO}, {@link #ACTION}, {@link #ACTION_INFO},
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   130
     * {@link #UNKNOWN}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public MBeanOperationInfo(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                              String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                              MBeanParameterInfo[] signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                              String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                              int impact) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        this(name, description, signature, type, impact, (Descriptor) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Constructs an <CODE>MBeanOperationInfo</CODE> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param name The name of the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param description A human readable description of the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param signature <CODE>MBeanParameterInfo</CODE> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * describing the parameters(arguments) of the method.  This may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * null with the same effect as a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @param type The type of the method's return value.
833
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   149
     * @param impact The impact of the method, one of
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   150
     * {@link #INFO}, {@link #ACTION}, {@link #ACTION_INFO},
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   151
     * {@link #UNKNOWN}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param descriptor The descriptor for the operation.  This may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * which is equivalent to an empty descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public MBeanOperationInfo(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                              String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                              MBeanParameterInfo[] signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                              String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                              int impact,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                              Descriptor descriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        super(name, description, descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (signature == null || signature.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            signature = MBeanParameterInfo.NO_PARAMS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            signature = signature.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        this.signature = signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        this.impact = impact;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        this.arrayGettersSafe =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            MBeanInfo.arrayGettersSafe(this.getClass(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                       MBeanOperationInfo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * <p>Returns a shallow clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * The clone is obtained by simply calling <tt>super.clone()</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * thus calling the default native shallow cloning mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * implemented by <tt>Object.clone()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * No deeper cloning of any internal field is made.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * <p>Since this class is immutable, cloning is chiefly of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * to subclasses.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     public Object clone () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
             return super.clone() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
             // should not happen as this class is cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
             return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Returns the type of the method's return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @return the return type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public String getReturnType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * <p>Returns the list of parameters for this operation.  Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * parameter is described by an <CODE>MBeanParameterInfo</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * object.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * <p>The returned array is a shallow copy of the internal array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * which means that it is a copy of the internal array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * references to the <CODE>MBeanParameterInfo</CODE> objects but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * that each referenced <CODE>MBeanParameterInfo</CODE> object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * not copied.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @return  An array of <CODE>MBeanParameterInfo</CODE> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public MBeanParameterInfo[] getSignature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        // If MBeanOperationInfo was created in our implementation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        // signature cannot be null - because our constructors replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        // null with MBeanParameterInfo.NO_PARAMS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        // However, signature could be null if an  MBeanOperationInfo is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        // deserialized from a byte array produced by another implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        // This is not very likely but possible, since the serial form says
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        // nothing against it. (see 6373150)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (signature == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            // if signature is null simply return an empty array .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            return MBeanParameterInfo.NO_PARAMS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        else if (signature.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            return signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            return signature.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    private MBeanParameterInfo[] fastGetSignature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (arrayGettersSafe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            // if signature is null simply return an empty array .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            // see getSignature() above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            if (signature == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                return MBeanParameterInfo.NO_PARAMS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            else return signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        } else return getSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Returns the impact of the method, one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * <CODE>INFO</CODE>, <CODE>ACTION</CODE>, <CODE>ACTION_INFO</CODE>, <CODE>UNKNOWN</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @return the impact code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public int getImpact() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return impact;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        String impactString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        switch (getImpact()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        case ACTION: impactString = "action"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        case ACTION_INFO: impactString = "action/info"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        case INFO: impactString = "info"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        case UNKNOWN: impactString = "unknown"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        default: impactString = "(" + getImpact() + ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        return getClass().getName() + "[" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            "description=" + getDescription() + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            "name=" + getName() + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            "returnType=" + getReturnType() + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            "signature=" + Arrays.asList(fastGetSignature()) + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            "impact=" + impactString + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            "descriptor=" + getDescriptor() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Compare this MBeanOperationInfo to another.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @param o the object to compare to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @return true if and only if <code>o</code> is an MBeanOperationInfo such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * that its {@link #getName()}, {@link #getReturnType()}, {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * #getDescription()}, {@link #getImpact()}, {@link #getDescriptor()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * and {@link #getSignature()} values are equal (not necessarily identical)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * to those of this MBeanConstructorInfo.  Two signature arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * are equal if their elements are pairwise equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (o == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (!(o instanceof MBeanOperationInfo))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        MBeanOperationInfo p = (MBeanOperationInfo) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return (p.getName().equals(getName()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                p.getReturnType().equals(getReturnType()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                p.getDescription().equals(getDescription()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                p.getImpact() == getImpact() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                Arrays.equals(p.fastGetSignature(), fastGetSignature()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                p.getDescriptor().equals(getDescriptor()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /* We do not include everything in the hashcode.  We assume that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
       if two operations are different they'll probably have different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
       names or types.  The penalty we pay when this assumption is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
       wrong should be less than the penalty we would pay if it were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
       right and we needlessly hashed in the description and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
       parameter array.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return getName().hashCode() ^ getReturnType().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    private static MBeanParameterInfo[] methodSignature(Method method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        final Class[] classes = method.getParameterTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        final Annotation[][] annots = method.getParameterAnnotations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        return parameters(classes, annots);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    static MBeanParameterInfo[] parameters(Class[] classes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                                           Annotation[][] annots) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        final MBeanParameterInfo[] params =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            new MBeanParameterInfo[classes.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        assert(classes.length == annots.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        for (int i = 0; i < classes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            Descriptor d = Introspector.descriptorForAnnotations(annots[i]);
833
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   329
            String description = Introspector.descriptionForParameter(annots[i]);
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   330
            if (description == null)
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   331
                description = "";
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   332
            String name = Introspector.nameForParameter(annots[i]);
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   333
            if (name == null)
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   334
                name = "p" + (i + 1);
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   335
            params[i] = new MBeanParameterInfo(
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 2
diff changeset
   336
                    name, classes[i].getName(), description, d);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
}