jdk/src/share/classes/javax/management/MBeanOperationInfo.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 833 bfa2bef7517c
permissions -rw-r--r--
Initial load
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * Indicates that the operation is read-like,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * it basically returns information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static final int INFO = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Indicates that the operation is a write-like,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * and would modify the MBean in some way, typically by writing some value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * or changing a configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public static final int ACTION = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Indicates that the operation is both read-like and write-like.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public static final int ACTION_INFO = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Indicates that the operation has an "unknown" nature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public static final int UNKNOWN = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @serial The method's return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private final String type;
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 signature of the method, that is, the class names
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * of the arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private final MBeanParameterInfo[] signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @serial The impact of the method, one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *         <CODE>INFO</CODE>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *         <CODE>ACTION</CODE>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *         <CODE>ACTION_INFO</CODE>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *         <CODE>UNKNOWN</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private final int impact;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /** @see MBeanInfo#arrayGettersSafe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private final transient boolean arrayGettersSafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Constructs an <CODE>MBeanOperationInfo</CODE> object.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * {@link Descriptor} of the constructed object will include
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * fields contributed by any annotations on the {@code Method}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * object that contain the {@link DescriptorKey} meta-annotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param method The <CODE>java.lang.reflect.Method</CODE> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * describing the MBean operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param description A human readable description of the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public MBeanOperationInfo(String description, Method method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        this(method.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
             description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
             methodSignature(method),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
             method.getReturnType().getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
             UNKNOWN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
             Introspector.descriptorForElement(method));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Constructs an <CODE>MBeanOperationInfo</CODE> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param name The name of the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param description A human readable description of the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @param signature <CODE>MBeanParameterInfo</CODE> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * describing the parameters(arguments) of the method.  This may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * null with the same effect as a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param type The type of the method's return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param impact The impact of the method, one of <CODE>INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * ACTION, ACTION_INFO, UNKNOWN</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public MBeanOperationInfo(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                              String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                              MBeanParameterInfo[] signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                              String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                              int impact) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        this(name, description, signature, type, impact, (Descriptor) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Constructs an <CODE>MBeanOperationInfo</CODE> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @param name The name of the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param description A human readable description of the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @param signature <CODE>MBeanParameterInfo</CODE> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * describing the parameters(arguments) of the method.  This may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * null with the same effect as a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param type The type of the method's return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param impact The impact of the method, one of <CODE>INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * ACTION, ACTION_INFO, UNKNOWN</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param descriptor The descriptor for the operation.  This may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * which is equivalent to an empty descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public MBeanOperationInfo(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                              String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                              MBeanParameterInfo[] signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                              String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                              int impact,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                              Descriptor descriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        super(name, description, descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (signature == null || signature.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            signature = MBeanParameterInfo.NO_PARAMS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            signature = signature.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        this.signature = signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        this.impact = impact;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        this.arrayGettersSafe =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            MBeanInfo.arrayGettersSafe(this.getClass(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                       MBeanOperationInfo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * <p>Returns a shallow clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * The clone is obtained by simply calling <tt>super.clone()</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * thus calling the default native shallow cloning mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * implemented by <tt>Object.clone()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * No deeper cloning of any internal field is made.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * <p>Since this class is immutable, cloning is chiefly of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * to subclasses.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     public Object clone () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
             return super.clone() ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
             // should not happen as this class is cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
             return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Returns the type of the method's return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @return the return type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public String getReturnType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * <p>Returns the list of parameters for this operation.  Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * parameter is described by an <CODE>MBeanParameterInfo</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * object.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * <p>The returned array is a shallow copy of the internal array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * which means that it is a copy of the internal array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * references to the <CODE>MBeanParameterInfo</CODE> objects but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * that each referenced <CODE>MBeanParameterInfo</CODE> object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * not copied.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @return  An array of <CODE>MBeanParameterInfo</CODE> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public MBeanParameterInfo[] getSignature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        // If MBeanOperationInfo was created in our implementation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        // signature cannot be null - because our constructors replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        // null with MBeanParameterInfo.NO_PARAMS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        // However, signature could be null if an  MBeanOperationInfo is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        // deserialized from a byte array produced by another implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        // This is not very likely but possible, since the serial form says
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        // nothing against it. (see 6373150)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if (signature == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            // if signature is null simply return an empty array .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            return MBeanParameterInfo.NO_PARAMS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        else if (signature.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            return signature.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    private MBeanParameterInfo[] fastGetSignature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (arrayGettersSafe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            // if signature is null simply return an empty array .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            // see getSignature() above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            if (signature == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                return MBeanParameterInfo.NO_PARAMS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            else return signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        } else return getSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Returns the impact of the method, one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * <CODE>INFO</CODE>, <CODE>ACTION</CODE>, <CODE>ACTION_INFO</CODE>, <CODE>UNKNOWN</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @return the impact code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public int getImpact() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return impact;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        String impactString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        switch (getImpact()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        case ACTION: impactString = "action"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        case ACTION_INFO: impactString = "action/info"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        case INFO: impactString = "info"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        case UNKNOWN: impactString = "unknown"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        default: impactString = "(" + getImpact() + ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return 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
            "returnType=" + getReturnType() + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            "signature=" + Arrays.asList(fastGetSignature()) + ", " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            "impact=" + impactString + ", " +
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 MBeanOperationInfo 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
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @return true if and only if <code>o</code> is an MBeanOperationInfo such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * that its {@link #getName()}, {@link #getReturnType()}, {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * #getDescription()}, {@link #getImpact()}, {@link #getDescriptor()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * and {@link #getSignature()} values are equal (not necessarily identical)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * to those of this MBeanConstructorInfo.  Two signature arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * are equal if their elements are pairwise equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if (o == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (!(o instanceof MBeanOperationInfo))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        MBeanOperationInfo p = (MBeanOperationInfo) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return (p.getName().equals(getName()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                p.getReturnType().equals(getReturnType()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                p.getDescription().equals(getDescription()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                p.getImpact() == getImpact() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                Arrays.equals(p.fastGetSignature(), fastGetSignature()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                p.getDescriptor().equals(getDescriptor()));
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 the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
       parameter array.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        return getName().hashCode() ^ getReturnType().hashCode();
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 MBeanParameterInfo[] methodSignature(Method method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        final Class[] classes = method.getParameterTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        final Annotation[][] annots = method.getParameterAnnotations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return parameters(classes, annots);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    static MBeanParameterInfo[] parameters(Class[] classes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                                           Annotation[][] annots) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        final MBeanParameterInfo[] params =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            new MBeanParameterInfo[classes.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        assert(classes.length == annots.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        for (int i = 0; i < classes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            Descriptor d = Introspector.descriptorForAnnotations(annots[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            final String pn = "p" + (i + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            params[i] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                new MBeanParameterInfo(pn, classes[i].getName(), "", d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
}