jdk/src/share/classes/javax/management/modelmbean/ModelMBeanOperationInfo.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 526 61ba2d5ea9da
child 1513 d09513aaa9da
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 526
diff changeset
     2
 * Portions Copyright 2000-2008 Sun Microsystems, Inc.  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
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
 * @author    IBM Corp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * Copyright IBM Corp. 1999-2000.  All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
package javax.management.modelmbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import static com.sun.jmx.defaults.JmxProperties.MODELMBEAN_LOGGER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.jmx.mbeanserver.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.ObjectStreamField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.logging.Level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.Descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.management.DescriptorAccess;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.management.DescriptorKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.management.MBeanOperationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.management.MBeanParameterInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.management.RuntimeOperationsException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * The ModelMBeanOperationInfo object describes a management operation of the ModelMBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * It is a subclass of MBeanOperationInfo with the addition of an associated Descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * and an implementation of the DescriptorAccess interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * The fields in the descriptor are defined, but not limited to, the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * name           : operation name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * descriptorType : must be "operation"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * class          : class where method is defined (fully qualified)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * role           : must be "operation", "getter", or "setter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * targetObject   : object on which to execute this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * targetType     : type of object reference for targetObject. Can be:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *                  ObjectReference | Handle | EJBHandle | IOR | RMIReference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * value          : cached value for operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * currencyTimeLimit : how long cached value is valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * lastUpdatedTimeStamp : when cached value was set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * visibility            : 1-4 where 1: always visible 4: rarely visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * presentationString :  xml formatted string to describe how to present operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * The default descriptor will have name, descriptorType, displayName and role fields set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * The default value of the name and displayName fields is the operation name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <p><b>Note:</b> because of inconsistencies in previous versions of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * this specification, it is recommended not to use negative or zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * values for <code>currencyTimeLimit</code>.  To indicate that a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * cached value is never valid, omit the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <code>currencyTimeLimit</code> field.  To indicate that it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * always valid, use a very large number for this field.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <p>The <b>serialVersionUID</b> of this class is <code>6532732096650090465L</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
@SuppressWarnings("serial")  // serialVersionUID is not constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
public class ModelMBeanOperationInfo extends MBeanOperationInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         implements DescriptorAccess
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // Serialization compatibility stuff:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    // Two serial forms are supported in this class. The selected form depends
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    // on system property "jmx.serial.form":
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    //  - "1.0" for JMX 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    //  - any other value for JMX 1.1 and higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    // Serial version for old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static final long oldSerialVersionUID = 9087646304346171239L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    // Serial version for new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private static final long newSerialVersionUID = 6532732096650090465L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    // Serializable fields in old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private static final ObjectStreamField[] oldSerialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
      new ObjectStreamField("operationDescriptor", Descriptor.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
      new ObjectStreamField("currClass", String.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    // Serializable fields in new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private static final ObjectStreamField[] newSerialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
      new ObjectStreamField("operationDescriptor", Descriptor.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    // Actual serial version and serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private static final long serialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @serialField operationDescriptor Descriptor The descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * containing the appropriate metadata for this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private static final ObjectStreamField[] serialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private static boolean compat = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            String form = AccessController.doPrivileged(act);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            compat = (form != null && form.equals("1.0"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            // OK: No compat with 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (compat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            serialPersistentFields = oldSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            serialVersionUID = oldSerialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            serialPersistentFields = newSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            serialVersionUID = newSerialVersionUID;
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
    // END Serialization compatibility stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         * @serial The descriptor containing the appropriate metadata for this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        private Descriptor operationDescriptor = validDescriptor(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        private static final String currClass = "ModelMBeanOperationInfo";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         * Constructs a ModelMBeanOperationInfo object with a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
         * descriptor. The {@link Descriptor} of the constructed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
         * object will include fields contributed by any annotations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         * on the {@code Method} object that contain the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
         * DescriptorKey} meta-annotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
         * @param operationMethod The java.lang.reflect.Method object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
         * describing the MBean operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
         * @param description A human readable description of the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        public ModelMBeanOperationInfo(String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                                       Method operationMethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                super(description, operationMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                // create default descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                            ModelMBeanOperationInfo.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                            "ModelMBeanOperationInfo(String,Method)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                            "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                operationDescriptor = validDescriptor(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
         * Constructs a ModelMBeanOperationInfo object. The {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
         * Descriptor} of the constructed object will include fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
         * contributed by any annotations on the {@code Method} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
         * that contain the {@link DescriptorKey} meta-annotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         * @param operationMethod The java.lang.reflect.Method object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         * describing the MBean operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         * @param description A human readable description of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
         * operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
         * @param descriptor An instance of Descriptor containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
         * appropriate metadata for this instance of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
         * ModelMBeanOperationInfo.  If it is null a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
         * descriptor will be created. If the descriptor does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
         * contain all the fields "name", "descriptorType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         * "displayName", and "role", the missing ones are added with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
         * their default values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
         * @exception RuntimeOperationsException Wraps an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         * IllegalArgumentException. The descriptor is invalid; or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
         * descriptor field "name" is present but not equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
         * operation name; or descriptor field "DescriptorType" is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         * present but not equal to "operation"; or descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         * optional field "role" is not equal to "operation",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
         * "getter", or "setter".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        public ModelMBeanOperationInfo(String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                                       Method operationMethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                                       Descriptor descriptor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                super(description, operationMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                            ModelMBeanOperationInfo.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                            "ModelMBeanOperationInfo(String,Method,Descriptor)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                            "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                operationDescriptor = validDescriptor(descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        * Constructs a ModelMBeanOperationInfo object with a default descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        * @param name The name of the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        * @param description A human readable description of the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        * @param signature MBeanParameterInfo objects describing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        * parameters(arguments) of the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        * @param type The type of the method's return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        * @param impact The impact of the method, one of INFO, ACTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        * ACTION_INFO, UNKNOWN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        public ModelMBeanOperationInfo(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                                       String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                                       MBeanParameterInfo[] signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                                       String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                                       int impact)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                super(name, description, signature, type, impact);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                // create default descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                            ModelMBeanOperationInfo.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                            "ModelMBeanOperationInfo(" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                            "String,String,MBeanParameterInfo[],String,int)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                            "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                operationDescriptor = validDescriptor(null);
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
        * Constructs a ModelMBeanOperationInfo object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        * @param name The name of the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        * @param description A human readable description of the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        * @param signature MBeanParameterInfo objects describing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        * parameters(arguments) of the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        * @param type The type of the method's return value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        * @param impact The impact of the method, one of INFO, ACTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        * ACTION_INFO, UNKNOWN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        * @param descriptor An instance of Descriptor containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        * appropriate metadata for this instance of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        * MBeanOperationInfo. If it is null then a default descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        * will be created.  If the descriptor does not contain all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        * fields "name", "descriptorType", "displayName", and "role",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        * the missing ones are added with their default values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        * @exception RuntimeOperationsException Wraps an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        * IllegalArgumentException. The descriptor is invalid; or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        * descriptor field "name" is present but not equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        * operation name; or descriptor field "DescriptorType" is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        * present but not equal to "operation"; or descriptor optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        * field "role" is not equal to "operation", "getter", or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        * "setter".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        public ModelMBeanOperationInfo(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                                       String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                                       MBeanParameterInfo[] signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                                       String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                                       int impact,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                                       Descriptor descriptor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                super(name, description, signature, type, impact);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                            ModelMBeanOperationInfo.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                            "ModelMBeanOperationInfo(String,String," +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                            "MBeanParameterInfo[],String,int,Descriptor)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                            "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                operationDescriptor = validDescriptor(descriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
         * Constructs a new ModelMBeanOperationInfo object from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
         * ModelMBeanOperation Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
         * @param inInfo the ModelMBeanOperationInfo to be duplicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        public ModelMBeanOperationInfo(ModelMBeanOperationInfo inInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                super(inInfo.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                          inInfo.getDescription(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                          inInfo.getSignature(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                          inInfo.getReturnType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                          inInfo.getImpact());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                            ModelMBeanOperationInfo.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                            "ModelMBeanOperationInfo(ModelMBeanOperationInfo)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                            "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                Descriptor newDesc = inInfo.getDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                operationDescriptor = validDescriptor(newDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        * Creates and returns a new ModelMBeanOperationInfo which is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        * duplicate of this ModelMBeanOperationInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        public Object clone ()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                        ModelMBeanOperationInfo.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                        "clone()", "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                return(new ModelMBeanOperationInfo(this)) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
         * Returns a copy of the associated Descriptor of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
         * ModelMBeanOperationInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
         * @return Descriptor associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
         * ModelMBeanOperationInfo object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
         * @see #setDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        public Descriptor getDescriptor()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                        ModelMBeanOperationInfo.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                        "getDescriptor()", "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            if (operationDescriptor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                operationDescriptor = validDescriptor(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            return((Descriptor) operationDescriptor.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
         * Sets associated Descriptor (full replace) for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
         * ModelMBeanOperationInfo If the new Descriptor is null, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
         * the associated Descriptor reverts to a default descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
         * The Descriptor is validated before it is assigned.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
         * new Descriptor is invalid, then a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
         * RuntimeOperationsException wrapping an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
         * IllegalArgumentException is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
         * @param inDescriptor replaces the Descriptor associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
         * ModelMBeanOperation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
         * @exception RuntimeOperationsException Wraps an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
         * IllegalArgumentException for invalid Descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
         * @see #getDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        public void setDescriptor(Descriptor inDescriptor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                        ModelMBeanOperationInfo.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                        "setDescriptor(Descriptor)", "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            operationDescriptor = validDescriptor(inDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        * Returns a string containing the entire contents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        * ModelMBeanOperationInfo in human readable form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        public String toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                        ModelMBeanOperationInfo.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                        "toString()", "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                String retStr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                    "ModelMBeanOperationInfo: " + this.getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                    " ; Description: " + this.getDescription() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                    " ; Descriptor: " + this.getDescriptor() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    " ; ReturnType: " + this.getReturnType() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    " ; Signature: ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                MBeanParameterInfo[] pTypes = this.getSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                for (int i=0; i < pTypes.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                        retStr = retStr.concat((pTypes[i]).getType() + ", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                return retStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
         * Clones the passed in Descriptor, sets default values, and checks for validity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
         * If the Descriptor is invalid (for instance by having the wrong "name"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
         * this indicates programming error and a RuntimeOperationsException will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
         * The following fields will be defaulted if they are not already set:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
         * displayName=this.getName(),name=this.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
         * descriptorType="operation", role="operation"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
         * @param in Descriptor to be checked, or null which is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
         * an empty Descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
         * @exception RuntimeOperationsException if Descriptor is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        private Descriptor validDescriptor(final Descriptor in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        throws RuntimeOperationsException {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   427
            Descriptor clone;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            if (in == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                clone = new DescriptorSupport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                MODELMBEAN_LOGGER.finer("Null Descriptor, creating new.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                clone = (Descriptor) in.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            //Setting defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            if (clone.getFieldValue("name")==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                clone.setField("name", this.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                MODELMBEAN_LOGGER.finer("Defaulting Descriptor name to " + this.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            if (clone.getFieldValue("descriptorType")==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                clone.setField("descriptorType", "operation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                MODELMBEAN_LOGGER.finer("Defaulting descriptorType to \"operation\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            if (clone.getFieldValue("displayName") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                clone.setField("displayName",this.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                MODELMBEAN_LOGGER.finer("Defaulting Descriptor displayName to " + this.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            if (clone.getFieldValue("role") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                clone.setField("role","operation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                MODELMBEAN_LOGGER.finer("Defaulting Descriptor role field to \"operation\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            //Checking validity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            if (!clone.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                 throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    "The isValid() method of the Descriptor object itself returned false,"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    "one or more required fields are invalid. Descriptor:" + clone.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            if (! ((String)clone.getFieldValue("name")).equalsIgnoreCase(this.getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                    throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    "The Descriptor \"name\" field does not match the object described. " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                     " Expected: "+ this.getName() + " , was: " + clone.getFieldValue("name"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            if (! ((String)clone.getFieldValue("descriptorType")).equalsIgnoreCase("operation")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                     throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    "The Descriptor \"descriptorType\" field does not match the object described. " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                     " Expected: \"attribute\" ," + " was: " + clone.getFieldValue("descriptorType"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            final String role = (String)clone.getFieldValue("role");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            if (!(role.equalsIgnoreCase("operation") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                  role.equalsIgnoreCase("setter") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                  role.equalsIgnoreCase("getter"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                     throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                    "The Descriptor \"role\" field does not match the object described. " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                     " Expected: \"operation\", \"setter\", or \"getter\" ," + " was: " + clone.getFieldValue("role"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            final Object targetValue = clone.getFieldValue("targetType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            if (targetValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                if (!(targetValue instanceof java.lang.String)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                    throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    "The Descriptor field \"targetValue\" is invalid class. " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                     " Expected: java.lang.String, " + " was: " + targetValue.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            return clone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * Deserializes a {@link ModelMBeanOperationInfo} from an {@link ObjectInputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    private void readObject(ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
      // New serial form ignores extra field "currClass"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
      in.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * Serializes a {@link ModelMBeanOperationInfo} to an {@link ObjectOutputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    private void writeObject(ObjectOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
      if (compat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        // Serializes this instance in the old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        ObjectOutputStream.PutField fields = out.putFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        fields.put("operationDescriptor", operationDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        fields.put("currClass", currClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        out.writeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        // Serializes this instance in the new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        out.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
}