jdk/src/java.management/share/classes/javax/management/modelmbean/ModelMBeanInfoSupport.java
author dfuchs
Fri, 20 Jan 2017 18:41:12 +0000
changeset 43235 da1786d695b6
parent 25859 3317bb8137f4
permissions -rw-r--r--
8172971: java.management could use System.Logger Summary: java.management is updated to use System.Logger instead of java.util.logging.Logger. Reviewed-by: mchung, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
     2
 * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @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.security.AccessController;
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
    41
import java.lang.System.Logger.Level;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.Descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.MBeanAttributeInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.management.MBeanConstructorInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.management.MBeanException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.management.MBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.management.MBeanNotificationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.management.MBeanOperationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.management.RuntimeOperationsException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * This class represents the meta data for ModelMBeans.  Descriptors have been
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * added on the meta data objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Java resources wishing to be manageable instantiate the ModelMBean using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * MBeanServer's createMBean method.  The resource then sets the ModelMBeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * and Descriptors for the ModelMBean instance. The attributes and operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * exposed via the ModelMBeanInfo for the ModelMBean are accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * from MBeans, connectors/adaptors like other MBeans. Through the Descriptors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * values and methods in the managed application can be defined and mapped to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * attributes and operations of the ModelMBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * This mapping can be defined during development in a file or dynamically and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * programmatically at runtime.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * Every ModelMBean which is instantiated in the MBeanServer becomes manageable:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * its attributes and operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * become remotely accessible through the connectors/adaptors connected to that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * MBeanServer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * A Java object cannot be registered in the MBeanServer unless it is a JMX
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * compliant MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * By instantiating a ModelMBean, resources are guaranteed that the MBean is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * MBeanException and RuntimeOperationsException must be thrown on every public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * method.  This allows for wrapping exceptions from distributed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * communications (RMI, EJB, etc.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <p>The <b>serialVersionUID</b> of this class is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <code>-1935722590756516193L</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
public class ModelMBeanInfoSupport extends MBeanInfo implements ModelMBeanInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    // Serialization compatibility stuff:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    // Two serial forms are supported in this class. The selected form depends
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    // on system property "jmx.serial.form":
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    //  - "1.0" for JMX 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    //  - any other value for JMX 1.1 and higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    // Serial version for old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private static final long oldSerialVersionUID = -3944083498453227709L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    // Serial version for new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private static final long newSerialVersionUID = -1935722590756516193L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    // Serializable fields in old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private static final ObjectStreamField[] oldSerialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        new ObjectStreamField("modelMBeanDescriptor", Descriptor.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                new ObjectStreamField("mmbAttributes", MBeanAttributeInfo[].class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                new ObjectStreamField("mmbConstructors", MBeanConstructorInfo[].class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                new ObjectStreamField("mmbNotifications", MBeanNotificationInfo[].class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                new ObjectStreamField("mmbOperations", MBeanOperationInfo[].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("modelMBeanDescriptor", Descriptor.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                new ObjectStreamField("modelMBeanAttributes", MBeanAttributeInfo[].class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                new ObjectStreamField("modelMBeanConstructors", MBeanConstructorInfo[].class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                new ObjectStreamField("modelMBeanNotifications", MBeanNotificationInfo[].class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                new ObjectStreamField("modelMBeanOperations", MBeanOperationInfo[].class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    // Actual serial version and serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private static final long serialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @serialField modelMBeanDescriptor Descriptor The descriptor containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *              MBean wide policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @serialField modelMBeanAttributes ModelMBeanAttributeInfo[] The array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *              {@link ModelMBeanAttributeInfo} objects which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *              have descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @serialField modelMBeanConstructors MBeanConstructorInfo[] The array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *              {@link ModelMBeanConstructorInfo} objects which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *              have descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @serialField modelMBeanNotifications MBeanNotificationInfo[] The array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *              {@link ModelMBeanNotificationInfo} objects which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *              have descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @serialField modelMBeanOperations MBeanOperationInfo[] The array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *              {@link ModelMBeanOperationInfo} objects which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *              have descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private static final ObjectStreamField[] serialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private static boolean compat = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            String form = AccessController.doPrivileged(act);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            compat = (form != null && form.equals("1.0"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            // OK: No compat with 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        if (compat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            serialPersistentFields = oldSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            serialVersionUID = oldSerialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            serialPersistentFields = newSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            serialVersionUID = newSerialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    // END Serialization compatibility stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @serial The descriptor containing MBean wide policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    private Descriptor modelMBeanDescriptor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /* The following fields always have the same values as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
       fields inherited from MBeanInfo and are retained only for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
       compatibility.  By rewriting the serialization code we could
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
       get rid of them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
       These fields can't be final because they are assigned to by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
       readObject().  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @serial The array of {@link ModelMBeanAttributeInfo} objects which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *         have descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private MBeanAttributeInfo[] modelMBeanAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @serial The array of {@link ModelMBeanConstructorInfo} objects which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *         have descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    private MBeanConstructorInfo[] modelMBeanConstructors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @serial The array of {@link ModelMBeanNotificationInfo} objects which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *         have descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    private MBeanNotificationInfo[] modelMBeanNotifications;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @serial The array of {@link ModelMBeanOperationInfo} objects which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *         have descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    private MBeanOperationInfo[] modelMBeanOperations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    private static final String ATTR = "attribute";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    private static final String OPER = "operation";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    private static final String NOTF = "notification";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    private static final String CONS = "constructor";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    private static final String MMB = "mbean";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private static final String ALL = "all";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    private static final String currClass = "ModelMBeanInfoSupport";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Constructs a ModelMBeanInfoSupport which is a duplicate of the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * ModelMBeanInfo.  The returned object is a shallow copy of the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * object.  Neither the Descriptor nor the contained arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * ({@code ModelMBeanAttributeInfo[]} etc) are cloned.  This method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * chiefly of interest to modify the Descriptor of the returned instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * via {@link #setDescriptor setDescriptor} without affecting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Descriptor of the original object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @param mbi the ModelMBeanInfo instance from which the ModelMBeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * being created is initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public ModelMBeanInfoSupport(ModelMBeanInfo  mbi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        super(mbi.getClassName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                mbi.getDescription(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                mbi.getAttributes(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                mbi.getConstructors(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                mbi.getOperations(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                mbi.getNotifications());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        modelMBeanAttributes = mbi.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        modelMBeanConstructors = mbi.getConstructors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        modelMBeanOperations = mbi.getOperations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        modelMBeanNotifications = mbi.getNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            Descriptor mbeandescriptor = mbi.getMBeanDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            modelMBeanDescriptor = validDescriptor(mbeandescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        } catch (MBeanException mbe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            modelMBeanDescriptor = validDescriptor(null);
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   234
            if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   235
                MODELMBEAN_LOGGER.log(Level.TRACE,
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   236
                        "ModelMBeanInfo(ModelMBeanInfo) " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                        "Could not get a valid modelMBeanDescriptor, " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                        "setting a default Descriptor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   242
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   243
            MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Creates a ModelMBeanInfoSupport with the provided information,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * but the descriptor is a default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * The default descriptor is: name=className, descriptorType="mbean",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * displayName=className, persistPolicy="never", log="F", visibility="1"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @param className classname of the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @param description human readable description of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * ModelMBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @param attributes array of ModelMBeanAttributeInfo objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * which have descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @param constructors array of ModelMBeanConstructorInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * objects which have descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @param operations array of ModelMBeanOperationInfo objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * which have descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @param notifications array of ModelMBeanNotificationInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * objects which have descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public ModelMBeanInfoSupport(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            ModelMBeanAttributeInfo[] attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            ModelMBeanConstructorInfo[] constructors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            ModelMBeanOperationInfo[] operations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            ModelMBeanNotificationInfo[] notifications) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        this(className, description, attributes, constructors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                operations, notifications, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Creates a ModelMBeanInfoSupport with the provided information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * and the descriptor given in parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param className classname of the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param description human readable description of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * ModelMBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @param attributes array of ModelMBeanAttributeInfo objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * which have descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @param constructors array of ModelMBeanConstructorInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * objects which have descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @param operations array of ModelMBeanOperationInfo objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * which have descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @param notifications array of ModelMBeanNotificationInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * objects which have descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @param mbeandescriptor descriptor to be used as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * MBeanDescriptor containing MBean wide policy. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * descriptor is null, a default descriptor will be constructed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * The default descriptor is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * name=className, descriptorType="mbean", displayName=className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * persistPolicy="never", log="F", visibility="1".  If the descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * does not contain all of these fields, the missing ones are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * added with these default values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @exception RuntimeOperationsException Wraps an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * IllegalArgumentException for invalid descriptor passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * parameter.  (see {@link #getMBeanDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * getMBeanDescriptor} for the definition of a valid MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * descriptor.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public ModelMBeanInfoSupport(String    className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            ModelMBeanAttributeInfo[] attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            ModelMBeanConstructorInfo[] constructors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            ModelMBeanOperationInfo[] operations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            ModelMBeanNotificationInfo[] notifications,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            Descriptor mbeandescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        super(className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                (attributes != null) ? attributes : NO_ATTRIBUTES,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                (constructors != null) ? constructors : NO_CONSTRUCTORS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                (operations != null) ? operations : NO_OPERATIONS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                (notifications != null) ? notifications : NO_NOTIFICATIONS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        /* The values saved here are possibly null, but we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
           check this everywhere they are referenced.  If at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
           some stage we replace null with an empty array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
           here, as we do in the superclass constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
           parameters, then we must also do this in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
           readObject().  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        modelMBeanAttributes = attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        modelMBeanConstructors = constructors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        modelMBeanOperations = operations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        modelMBeanNotifications = notifications;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        modelMBeanDescriptor = validDescriptor(mbeandescriptor);
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   330
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   331
            MODELMBEAN_LOGGER.log(Level.TRACE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                    "ModelMBeanInfoSupport(String,String,ModelMBeanAttributeInfo[]," +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    "ModelMBeanConstructorInfo[],ModelMBeanOperationInfo[]," +
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   334
                    "ModelMBeanNotificationInfo[],Descriptor) " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    "Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    private static final ModelMBeanAttributeInfo[] NO_ATTRIBUTES =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            new ModelMBeanAttributeInfo[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    private static final ModelMBeanConstructorInfo[] NO_CONSTRUCTORS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            new ModelMBeanConstructorInfo[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    private static final ModelMBeanNotificationInfo[] NO_NOTIFICATIONS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            new ModelMBeanNotificationInfo[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    private static final ModelMBeanOperationInfo[] NO_OPERATIONS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            new ModelMBeanOperationInfo[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    // Java doc inherited from MOdelMBeanInfo interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * Returns a shallow clone of this instance.  Neither the Descriptor nor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * the contained arrays ({@code ModelMBeanAttributeInfo[]} etc) are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * cloned.  This method is chiefly of interest to modify the Descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * of the clone via {@link #setDescriptor setDescriptor} without affecting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * the Descriptor of the original object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @return a shallow clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        return(new ModelMBeanInfoSupport(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public Descriptor[] getDescriptors(String inDescriptorType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    throws MBeanException, RuntimeOperationsException {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   366
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   367
            MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
   370
        if ((inDescriptorType == null) || (inDescriptorType.equals(""))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            inDescriptorType = "all";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        // if no descriptors of that type, will return empty array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        final Descriptor[] retList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if (inDescriptorType.equalsIgnoreCase(MMB)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            retList = new Descriptor[] {modelMBeanDescriptor};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        } else if (inDescriptorType.equalsIgnoreCase(ATTR)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            final MBeanAttributeInfo[] attrList = modelMBeanAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            int numAttrs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            if (attrList != null) numAttrs = attrList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            retList = new Descriptor[numAttrs];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            for (int i=0; i < numAttrs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                retList[i] = (((ModelMBeanAttributeInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    attrList[i]).getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        } else if (inDescriptorType.equalsIgnoreCase(OPER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            final MBeanOperationInfo[] operList = modelMBeanOperations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            int numOpers = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            if (operList != null) numOpers = operList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            retList = new Descriptor[numOpers];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            for (int i=0; i < numOpers; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                retList[i] = (((ModelMBeanOperationInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                    operList[i]).getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        } else if (inDescriptorType.equalsIgnoreCase(CONS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            final MBeanConstructorInfo[] consList =  modelMBeanConstructors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            int numCons = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            if (consList != null) numCons = consList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            retList = new Descriptor[numCons];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            for (int i=0; i < numCons; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                retList[i] = (((ModelMBeanConstructorInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                    consList[i]).getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        } else if (inDescriptorType.equalsIgnoreCase(NOTF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            final MBeanNotificationInfo[] notifList = modelMBeanNotifications;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            int numNotifs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            if (notifList != null) numNotifs = notifList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            retList = new Descriptor[numNotifs];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            for (int i=0; i < numNotifs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                retList[i] = (((ModelMBeanNotificationInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    notifList[i]).getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        } else if (inDescriptorType.equalsIgnoreCase(ALL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            final MBeanAttributeInfo[] attrList = modelMBeanAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            int numAttrs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            if (attrList != null) numAttrs = attrList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            final MBeanOperationInfo[] operList = modelMBeanOperations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            int numOpers = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            if (operList != null) numOpers = operList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            final MBeanConstructorInfo[] consList = modelMBeanConstructors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            int numCons = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            if (consList != null) numCons = consList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            final MBeanNotificationInfo[] notifList = modelMBeanNotifications;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            int numNotifs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            if (notifList != null) numNotifs = notifList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            int count = numAttrs + numCons + numOpers + numNotifs + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            retList = new Descriptor[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            retList[count-1] = modelMBeanDescriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            int j=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            for (int i=0; i < numAttrs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                retList[j] = (((ModelMBeanAttributeInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    attrList[i]).getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                j++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            for (int i=0; i < numCons; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                retList[j] = (((ModelMBeanConstructorInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                    consList[i]).getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                j++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            for (int i=0; i < numOpers; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                retList[j] = (((ModelMBeanOperationInfo)operList[i]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                        getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                j++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            for (int i=0; i < numNotifs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                retList[j] = (((ModelMBeanNotificationInfo)notifList[i]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                        getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                j++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            final IllegalArgumentException iae =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    new IllegalArgumentException("Descriptor Type is invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            final String msg = "Exception occurred trying to find"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    " the descriptors of the MBean";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            throw new RuntimeOperationsException(iae,msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   471
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   472
            MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        return retList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    public void setDescriptors(Descriptor[] inDescriptors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    throws MBeanException, RuntimeOperationsException {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   481
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   482
            MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (inDescriptors==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            // throw RuntimeOperationsException - invalid descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            throw new RuntimeOperationsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                    new IllegalArgumentException("Descriptor list is invalid"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    "Exception occurred trying to set the descriptors " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    "of the MBeanInfo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        if (inDescriptors.length == 0) { // empty list, no-op
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        for (int j=0; j < inDescriptors.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            setDescriptor(inDescriptors[j],null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   497
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   498
            MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * Returns a Descriptor requested by name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @param inDescriptorName The name of the descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * @return Descriptor containing a descriptor for the ModelMBean with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *         same name. If no descriptor is found, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * @exception MBeanException Wraps a distributed communication Exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @exception RuntimeOperationsException Wraps an IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *            for null name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @see #setDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    public Descriptor getDescriptor(String inDescriptorName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    throws MBeanException, RuntimeOperationsException {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   521
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   522
            MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        return(getDescriptor(inDescriptorName, null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    public Descriptor getDescriptor(String inDescriptorName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            String inDescriptorType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            throws MBeanException, RuntimeOperationsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        if (inDescriptorName==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            // throw RuntimeOperationsException - invalid descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            throw new RuntimeOperationsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                    new IllegalArgumentException("Descriptor is invalid"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    "Exception occurred trying to set the descriptors of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                    "the MBeanInfo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        if (MMB.equalsIgnoreCase(inDescriptorType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            return (Descriptor) modelMBeanDescriptor.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            /* The logic here is a bit convoluted, because we are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
               dealing with two possible cases, depending on whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
               inDescriptorType is null.  If it's not null, then only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
               one of the following ifs will run, and it will either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
               return a descriptor or null.  If inDescriptorType is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
               null, then all of the following ifs will run until one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
               of them finds a descriptor.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        if (ATTR.equalsIgnoreCase(inDescriptorType) || inDescriptorType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            ModelMBeanAttributeInfo attr = getAttribute(inDescriptorName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            if (attr != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                return attr.getDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            if (inDescriptorType != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        if (OPER.equalsIgnoreCase(inDescriptorType) || inDescriptorType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            ModelMBeanOperationInfo oper = getOperation(inDescriptorName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            if (oper != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                return oper.getDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            if (inDescriptorType != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        if (CONS.equalsIgnoreCase(inDescriptorType) || inDescriptorType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            ModelMBeanConstructorInfo oper =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                    getConstructor(inDescriptorName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            if (oper != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                return oper.getDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            if (inDescriptorType != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        if (NOTF.equalsIgnoreCase(inDescriptorType) || inDescriptorType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            ModelMBeanNotificationInfo notif =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    getNotification(inDescriptorName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            if (notif != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                return notif.getDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            if (inDescriptorType != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        if (inDescriptorType == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        throw new RuntimeOperationsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                new IllegalArgumentException("Descriptor Type is invalid"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                "Exception occurred trying to find the descriptors of the MBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    public void setDescriptor(Descriptor inDescriptor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            String inDescriptorType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            throws MBeanException, RuntimeOperationsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        final String excMsg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                "Exception occurred trying to set the descriptors of the MBean";
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   595
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   596
            MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        if (inDescriptor==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            inDescriptor = new DescriptorSupport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
   603
        if ((inDescriptorType == null) || (inDescriptorType.equals(""))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            inDescriptorType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                    (String) inDescriptor.getFieldValue("descriptorType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            if (inDescriptorType == null) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   608
                   MODELMBEAN_LOGGER.log(Level.TRACE,
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   609
                                "descriptorType null in both String parameter " +
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   610
                                "and Descriptor, defaulting to "+ MMB);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                inDescriptorType = MMB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        String inDescriptorName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                (String) inDescriptor.getFieldValue("name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        if (inDescriptorName == null) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   618
            MODELMBEAN_LOGGER.log(Level.TRACE,
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   619
                                "descriptor name null, defaulting to " +
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   620
                                this.getClassName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            inDescriptorName = this.getClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        if (inDescriptorType.equalsIgnoreCase(MMB)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            setMBeanDescriptor(inDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        } else if (inDescriptorType.equalsIgnoreCase(ATTR)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            MBeanAttributeInfo[] attrList =  modelMBeanAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            int numAttrs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            if (attrList != null) numAttrs = attrList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            for (int i=0; i < numAttrs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                if (inDescriptorName.equals(attrList[i].getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                    found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                    ModelMBeanAttributeInfo mmbai =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                            (ModelMBeanAttributeInfo) attrList[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                    mmbai.setDescriptor(inDescriptor);
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   638
                    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                        StringBuilder strb = new StringBuilder()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                        .append("Setting descriptor to ").append(inDescriptor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                        .append("\t\n local: AttributeInfo descriptor is ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                        .append(mmbai.getDescriptor())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                        .append("\t\n modelMBeanInfo: AttributeInfo descriptor is ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                        .append(this.getDescriptor(inDescriptorName,"attribute"));
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   645
                        MODELMBEAN_LOGGER.log(Level.TRACE, strb::toString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        } else if (inDescriptorType.equalsIgnoreCase(OPER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            MBeanOperationInfo[] operList =  modelMBeanOperations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            int numOpers = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            if (operList != null) numOpers = operList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            for (int i=0; i < numOpers; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                if (inDescriptorName.equals(operList[i].getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                    found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                    ModelMBeanOperationInfo mmboi =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                            (ModelMBeanOperationInfo) operList[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                    mmboi.setDescriptor(inDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        } else if (inDescriptorType.equalsIgnoreCase(CONS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            MBeanConstructorInfo[] consList =  modelMBeanConstructors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            int numCons = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            if (consList != null) numCons = consList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            for (int i=0; i < numCons; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                if (inDescriptorName.equals(consList[i].getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                    found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                    ModelMBeanConstructorInfo mmbci =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                            (ModelMBeanConstructorInfo) consList[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                    mmbci.setDescriptor(inDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        } else if (inDescriptorType.equalsIgnoreCase(NOTF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            MBeanNotificationInfo[] notifList =  modelMBeanNotifications;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            int numNotifs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            if (notifList != null) numNotifs = notifList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            for (int i=0; i < numNotifs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                if (inDescriptorName.equals(notifList[i].getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                    found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                    ModelMBeanNotificationInfo mmbni =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                            (ModelMBeanNotificationInfo) notifList[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                    mmbni.setDescriptor(inDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            RuntimeException iae =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                    new IllegalArgumentException("Invalid descriptor type: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                    inDescriptorType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            throw new RuntimeOperationsException(iae, excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        if (!found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            RuntimeException iae =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                    new IllegalArgumentException("Descriptor name is invalid: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                    "type=" + inDescriptorType +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                    "; name=" + inDescriptorName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            throw new RuntimeOperationsException(iae, excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   702
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   703
            MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    public ModelMBeanAttributeInfo getAttribute(String inName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    throws MBeanException, RuntimeOperationsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        ModelMBeanAttributeInfo retInfo = null;
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   712
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   713
            MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        if (inName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            throw new RuntimeOperationsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                    new IllegalArgumentException("Attribute Name is null"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                    "Exception occurred trying to get the " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                    "ModelMBeanAttributeInfo of the MBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        MBeanAttributeInfo[] attrList = modelMBeanAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        int numAttrs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        if (attrList != null) numAttrs = attrList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        for (int i=0; (i < numAttrs) && (retInfo == null); i++) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   726
            if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                final StringBuilder strb = new StringBuilder()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                .append("\t\n this.getAttributes() MBeanAttributeInfo Array ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                .append(i).append(":")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                .append(((ModelMBeanAttributeInfo)attrList[i]).getDescriptor())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                .append("\t\n this.modelMBeanAttributes MBeanAttributeInfo Array ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                .append(i).append(":")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                .append(((ModelMBeanAttributeInfo)modelMBeanAttributes[i]).getDescriptor());
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   734
                MODELMBEAN_LOGGER.log(Level.TRACE, strb::toString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            if (inName.equals(attrList[i].getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                retInfo = ((ModelMBeanAttributeInfo)attrList[i].clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        }
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   740
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   741
            MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        return retInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    public ModelMBeanOperationInfo getOperation(String inName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    throws MBeanException, RuntimeOperationsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        ModelMBeanOperationInfo retInfo = null;
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   752
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   753
            MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        if (inName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            throw new RuntimeOperationsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                    new IllegalArgumentException("inName is null"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                    "Exception occurred trying to get the " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                    "ModelMBeanOperationInfo of the MBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        MBeanOperationInfo[] operList = modelMBeanOperations; //this.getOperations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        int numOpers = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        if (operList != null) numOpers = operList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        for (int i=0; (i < numOpers) && (retInfo == null); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            if (inName.equals(operList[i].getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                retInfo = ((ModelMBeanOperationInfo) operList[i].clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        }
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   770
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   771
            MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        return retInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * Returns the ModelMBeanConstructorInfo requested by name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * If no ModelMBeanConstructorInfo exists for this name null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * @param inName the name of the constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * @return the constructor info for the named constructor, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * if there is none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * @exception MBeanException Wraps a distributed communication Exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * @exception RuntimeOperationsException Wraps an IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     *            for a null constructor name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    public ModelMBeanConstructorInfo getConstructor(String inName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    throws MBeanException, RuntimeOperationsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        ModelMBeanConstructorInfo retInfo = null;
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   794
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   795
            MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        if (inName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            throw new RuntimeOperationsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                    new IllegalArgumentException("Constructor name is null"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                    "Exception occurred trying to get the " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                    "ModelMBeanConstructorInfo of the MBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        MBeanConstructorInfo[] consList = modelMBeanConstructors; //this.getConstructors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        int numCons = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        if (consList != null) numCons = consList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        for (int i=0; (i < numCons) && (retInfo == null); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            if (inName.equals(consList[i].getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                retInfo = ((ModelMBeanConstructorInfo) consList[i].clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        }
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   812
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   813
            MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        return retInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    public ModelMBeanNotificationInfo getNotification(String inName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    throws MBeanException, RuntimeOperationsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        ModelMBeanNotificationInfo retInfo = null;
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   823
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   824
            MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        if (inName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            throw new RuntimeOperationsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                    new IllegalArgumentException("Notification name is null"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                    "Exception occurred trying to get the " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                    "ModelMBeanNotificationInfo of the MBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        MBeanNotificationInfo[] notifList = modelMBeanNotifications; //this.getNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        int numNotifs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        if (notifList != null) numNotifs = notifList.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        for (int i=0; (i < numNotifs) && (retInfo == null); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            if (inName.equals(notifList[i].getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                retInfo = ((ModelMBeanNotificationInfo) notifList[i].clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        }
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   841
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   842
            MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        return retInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    /* We override MBeanInfo.getDescriptor() to return our descriptor. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    public Descriptor getDescriptor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        return getMBeanDescriptorNoException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    public Descriptor getMBeanDescriptor() throws MBeanException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        return getMBeanDescriptorNoException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    private Descriptor getMBeanDescriptorNoException() {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   863
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   864
            MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        if (modelMBeanDescriptor == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            modelMBeanDescriptor = validDescriptor(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   870
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   871
            MODELMBEAN_LOGGER.log(Level.TRACE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                    "Exit, returning: " + modelMBeanDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        return (Descriptor) modelMBeanDescriptor.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    public void setMBeanDescriptor(Descriptor inMBeanDescriptor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    throws MBeanException, RuntimeOperationsException {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   879
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   880
            MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        modelMBeanDescriptor = validDescriptor(inMBeanDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * Clones the passed in Descriptor, sets default values, and checks for validity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * If the Descriptor is invalid (for instance by having the wrong "name"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * this indicates programming error and a RuntimeOperationsException will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * The following fields will be defaulted if they are not already set:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * displayName=className,name=className,descriptorType="mbean",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * persistPolicy="never", log="F", visibility="1"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * @param in Descriptor to be checked, or null which is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * an empty Descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * @exception RuntimeOperationsException if Descriptor is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    private Descriptor validDescriptor(final Descriptor in) throws RuntimeOperationsException {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   900
        Descriptor clone;
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1004
diff changeset
   901
        boolean defaulted = (in == null);
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1004
diff changeset
   902
        if (defaulted) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            clone = new DescriptorSupport();
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   904
            MODELMBEAN_LOGGER.log(Level.TRACE, "Null Descriptor, creating new.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            clone = (Descriptor) in.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        //Setting defaults.
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1004
diff changeset
   910
        if (defaulted && clone.getFieldValue("name")==null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            clone.setField("name", this.getClassName());
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   912
            MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting Descriptor name to " + this.getClassName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        }
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1004
diff changeset
   914
        if (defaulted && clone.getFieldValue("descriptorType")==null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            clone.setField("descriptorType", MMB);
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   916
            MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting descriptorType to \"" + MMB + "\"");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        if (clone.getFieldValue("displayName") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            clone.setField("displayName",this.getClassName());
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   920
            MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting Descriptor displayName to " + this.getClassName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        if (clone.getFieldValue("persistPolicy") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            clone.setField("persistPolicy","never");
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   924
            MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting Descriptor persistPolicy to \"never\"");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        if (clone.getFieldValue("log") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            clone.setField("log","F");
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   928
            MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting Descriptor \"log\" field to \"F\"");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        if (clone.getFieldValue("visibility") == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            clone.setField("visibility","1");
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   932
            MODELMBEAN_LOGGER.log(Level.TRACE, "Defaulting Descriptor visibility to 1");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        //Checking validity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        if (!clone.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
             throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                "The isValid() method of the Descriptor object itself returned false,"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                "one or more required fields are invalid. Descriptor:" + clone.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        if (! ((String)clone.getFieldValue("descriptorType")).equalsIgnoreCase(MMB)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                 throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                "The Descriptor \"descriptorType\" field does not match the object described. " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                 " Expected: "+ MMB + " , was: " + clone.getFieldValue("descriptorType"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        return clone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * Deserializes a {@link ModelMBeanInfoSupport} from an {@link ObjectInputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    private void readObject(ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        if (compat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            // Read an object serialized in the old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            ObjectInputStream.GetField fields = in.readFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            modelMBeanDescriptor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                    (Descriptor) fields.get("modelMBeanDescriptor", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            if (fields.defaulted("modelMBeanDescriptor")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                throw new NullPointerException("modelMBeanDescriptor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            modelMBeanAttributes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                    (MBeanAttributeInfo[]) fields.get("mmbAttributes", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            if (fields.defaulted("mmbAttributes")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                throw new NullPointerException("mmbAttributes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            modelMBeanConstructors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                    (MBeanConstructorInfo[]) fields.get("mmbConstructors", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            if (fields.defaulted("mmbConstructors")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                throw new NullPointerException("mmbConstructors");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            modelMBeanNotifications =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                    (MBeanNotificationInfo[]) fields.get("mmbNotifications", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            if (fields.defaulted("mmbNotifications")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                throw new NullPointerException("mmbNotifications");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            modelMBeanOperations =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                    (MBeanOperationInfo[]) fields.get("mmbOperations", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            if (fields.defaulted("mmbOperations")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                throw new NullPointerException("mmbOperations");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            // Read an object serialized in the new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            in.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * Serializes a {@link ModelMBeanInfoSupport} to an {@link ObjectOutputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    private void writeObject(ObjectOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        if (compat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            // Serializes this instance in the old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            ObjectOutputStream.PutField fields = out.putFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            fields.put("modelMBeanDescriptor", modelMBeanDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            fields.put("mmbAttributes", modelMBeanAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            fields.put("mmbConstructors", modelMBeanConstructors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            fields.put("mmbNotifications", modelMBeanNotifications);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            fields.put("mmbOperations", modelMBeanOperations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            fields.put("currClass", currClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            out.writeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            // Serializes this instance in the new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            out.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
}