jdk/src/share/classes/javax/management/StandardMBean.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 687 874e25a9844a
child 834 dc74d4ddc28e
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 687
diff changeset
     2
 * Copyright 2002-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.jmx.mbeanserver.DescriptorCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.jmx.mbeanserver.Introspector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.jmx.mbeanserver.MBeanSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.jmx.mbeanserver.MXBeanSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.jmx.mbeanserver.StandardMBeanSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.jmx.mbeanserver.Util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.WeakHashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.logging.Level;
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
    40
import javax.management.openmbean.MXBeanMappingFactory;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.openmbean.OpenMBeanAttributeInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.management.openmbean.OpenMBeanAttributeInfoSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.openmbean.OpenMBeanConstructorInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.openmbean.OpenMBeanConstructorInfoSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.management.openmbean.OpenMBeanOperationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.management.openmbean.OpenMBeanOperationInfoSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.management.openmbean.OpenMBeanParameterInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.management.openmbean.OpenMBeanParameterInfoSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
    50
import static com.sun.jmx.defaults.JmxProperties.MISC_LOGGER;
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
    51
import static javax.management.JMX.MBeanOptions;
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
    52
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>An MBean whose management interface is determined by reflection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * on a Java interface.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>This class brings more flexibility to the notion of Management
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Interface in the use of Standard MBeans.  Straightforward use of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * the patterns for Standard MBeans described in the JMX Specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * means that there is a fixed relationship between the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * class of an MBean and its management interface (i.e., if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * implementation class is Thing, the management interface must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * ThingMBean).  This class makes it possible to keep the convenience
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * of specifying the management interface with a Java interface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * without requiring that there be any naming relationship between the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * implementation and interface classes.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <p>By making a DynamicMBean out of an MBean, this class makes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * it possible to select any interface implemented by the MBean as its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * management interface, provided that it complies with JMX patterns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * (i.e., attributes defined by getter/setter etc...).</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <p> This class also provides hooks that make it possible to supply
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * custom descriptions and names for the {@link MBeanInfo} returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * the DynamicMBean interface.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <p>Using this class, an MBean can be created with any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * implementation class name <i>Impl</i> and with a management
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * interface defined (as for current Standard MBeans) by any interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <i>Intf</i>, in one of two general ways:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <li>Using the public constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *     {@link #StandardMBean(java.lang.Object, java.lang.Class, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *     StandardMBean(impl,interface)}:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *     <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *     MBeanServer mbs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *     ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *     Impl impl = new Impl(...);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *     StandardMBean mbean = new StandardMBean(impl, Intf.class, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *     mbs.registerMBean(mbean, objectName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *     </pre></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * <li>Subclassing StandardMBean:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *     <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *     public class Impl extends StandardMBean implements Intf {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *        public Impl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *          super(Intf.class, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *       // implement methods of Intf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *     [...]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *     MBeanServer mbs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *     ....
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *     Impl impl = new Impl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *     mbs.registerMBean(impl, objectName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *     </pre></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * <p>In either case, the class <i>Impl</i> must implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * interface <i>Intf</i>.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * <p>Standard MBeans based on the naming relationship between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * implementation and interface classes are of course still
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * available.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * <p>This class may also be used to construct MXBeans.  The usage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * is exactly the same as for Standard MBeans except that in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * examples above, the {@code false} parameter to the constructor or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * {@code super(...)} invocation is instead {@code true}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
public class StandardMBean implements DynamicMBean, MBeanRegistration {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private final static DescriptorCache descriptors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        DescriptorCache.getInstance(JMX.proof);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * The DynamicMBean that wraps the MXBean or Standard MBean implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private volatile MBeanSupport<?> mbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * The cached MBeanInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private volatile MBeanInfo cachedMBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   144
     * The MBeanOptions for this StandardMBean.
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   145
     **/
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   146
    private MBeanOptions options;
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   147
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   148
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Make a DynamicMBean out of <var>implementation</var>, using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * specified <var>mbeanInterface</var> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @param implementation The implementation of this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *        If <code>null</code>, and null implementation is allowed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *        then the implementation is assumed to be <var>this</var>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param mbeanInterface The Management Interface exported by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *        MBean's implementation. If <code>null</code>, then this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *        object will use standard JMX design pattern to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *        the management interface associated with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *        implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param nullImplementationAllowed <code>true</code> if a null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *        implementation is allowed. If null implementation is allowed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *        and a null implementation is passed, then the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *        is assumed to be <var>this</var>.
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   163
     * @param options MBeanOptions to apply to this instance.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @exception IllegalArgumentException if the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *    <var>implementation</var> is null, and null is not allowed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     **/
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   167
    @SuppressWarnings("unchecked")  // cast to T
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    private <T> void construct(T implementation, Class<T> mbeanInterface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                               boolean nullImplementationAllowed,
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   170
                               MBeanOptions options)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                               throws NotCompliantMBeanException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (implementation == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            // Have to use (T)this rather than mbeanInterface.cast(this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            // because mbeanInterface might be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            if (nullImplementationAllowed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                implementation = Util.<T>cast(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            else throw new IllegalArgumentException("implementation is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   179
        if (options == null)
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   180
            options = new MBeanOptions();
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   181
        MXBeanMappingFactory mappingFactory = options.getMXBeanMappingFactory();
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   182
        boolean mx = (mappingFactory != null);
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   183
        if (mbeanInterface == null) {
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   184
            mbeanInterface = Util.cast(Introspector.getStandardOrMXBeanInterface(
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   185
                                       implementation.getClass(), mx));
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   186
        }
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   187
        if (mx) {
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   188
            this.mbean =
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   189
                    new MXBeanSupport(implementation, mbeanInterface,
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   190
                                      mappingFactory);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            this.mbean =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    new StandardMBeanSupport(implementation, mbeanInterface);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   195
        this.options = options.canonical();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * <p>Make a DynamicMBean out of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * <var>implementation</var>, using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * <var>mbeanInterface</var> class.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param implementation The implementation of this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @param mbeanInterface The Management Interface exported by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *        MBean's implementation. If <code>null</code>, then this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *        object will use standard JMX design pattern to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *        the management interface associated with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *        implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param <T> Allows the compiler to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * that {@code implementation} does indeed implement the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * described by {@code mbeanInterface}.  The compiler can only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * check this if {@code mbeanInterface} is a class literal such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * as {@code MyMBean.class}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @exception IllegalArgumentException if the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *    <var>implementation</var> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @exception NotCompliantMBeanException if the <var>mbeanInterface</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *    does not follow JMX design patterns for Management Interfaces, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *    if the given <var>implementation</var> does not implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *    specified interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public <T> StandardMBean(T implementation, Class<T> mbeanInterface)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        throws NotCompliantMBeanException {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   224
        construct(implementation, mbeanInterface, false, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <p>Make a DynamicMBean out of <var>this</var>, using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * <var>mbeanInterface</var> class.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   231
     * <p>Calls {@link #StandardMBean(java.lang.Object, java.lang.Class)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *       this(this,mbeanInterface)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * This constructor is reserved to subclasses.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param mbeanInterface The Management Interface exported by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *        MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @exception NotCompliantMBeanException if the <var>mbeanInterface</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *    does not follow JMX design patterns for Management Interfaces, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *    if <var>this</var> does not implement the specified interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    protected StandardMBean(Class<?> mbeanInterface)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        throws NotCompliantMBeanException {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   244
        construct(null, mbeanInterface, true, null);
2
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
     * <p>Make a DynamicMBean out of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * <var>implementation</var>, using the specified
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   250
     * <var>mbeanInterface</var> class, and choosing whether the
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   251
     * resultant MBean is an MXBean.  This constructor can be used
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * to make either Standard MBeans or MXBeans.  Unlike the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * constructor {@link #StandardMBean(Object, Class)}, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * does not throw NotCompliantMBeanException.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @param implementation The implementation of this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @param mbeanInterface The Management Interface exported by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *        MBean's implementation. If <code>null</code>, then this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *        object will use standard JMX design pattern to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *        the management interface associated with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *        implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @param isMXBean If true, the {@code mbeanInterface} parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * names an MXBean interface and the resultant MBean is an MXBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @param <T> Allows the compiler to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * that {@code implementation} does indeed implement the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * described by {@code mbeanInterface}.  The compiler can only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * check this if {@code mbeanInterface} is a class literal such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * as {@code MyMBean.class}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @exception IllegalArgumentException if the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *    <var>implementation</var> is null, or if the <var>mbeanInterface</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *    does not follow JMX design patterns for Management Interfaces, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *    if the given <var>implementation</var> does not implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *    specified interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public <T> StandardMBean(T implementation, Class<T> mbeanInterface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                             boolean isMXBean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        try {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   281
            MBeanOptions opts = new MBeanOptions();
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   282
            if (mbeanInterface == null) {
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   283
                mbeanInterface = Util.cast(Introspector.getStandardOrMXBeanInterface(
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   284
                        implementation.getClass(), isMXBean));
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   285
            }
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   286
            if (isMXBean) {
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   287
                MXBeanMappingFactory f = MXBeanMappingFactory.forInterface(
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   288
                        mbeanInterface);
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   289
                opts.setMXBeanMappingFactory(f);
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   290
            }
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   291
            construct(implementation, mbeanInterface, false, opts);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        } catch (NotCompliantMBeanException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            throw new IllegalArgumentException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * <p>Make a DynamicMBean out of <var>this</var>, using the specified
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   299
     * <var>mbeanInterface</var> class, and choosing whether the resulting
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   300
     * MBean is an MXBean.  This constructor can be used
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * to make either Standard MBeans or MXBeans.  Unlike the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * constructor {@link #StandardMBean(Object, Class)}, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * does not throw NotCompliantMBeanException.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   305
     * <p>Calls {@link #StandardMBean(java.lang.Object, java.lang.Class, boolean)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *       this(this, mbeanInterface, isMXBean)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * This constructor is reserved to subclasses.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @param mbeanInterface The Management Interface exported by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *        MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @param isMXBean If true, the {@code mbeanInterface} parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * names an MXBean interface and the resultant MBean is an MXBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @exception IllegalArgumentException if the <var>mbeanInterface</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *    does not follow JMX design patterns for Management Interfaces, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *    if <var>this</var> does not implement the specified interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    protected StandardMBean(Class<?> mbeanInterface, boolean isMXBean) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        try {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   322
            MBeanOptions opts = new MBeanOptions();
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   323
            if (mbeanInterface == null) {
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   324
                mbeanInterface = Introspector.getStandardOrMXBeanInterface(
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   325
                        getClass(), isMXBean);
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   326
            }
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   327
            if (isMXBean) {
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   328
                MXBeanMappingFactory f = MXBeanMappingFactory.forInterface(
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   329
                        mbeanInterface);
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   330
                opts.setMXBeanMappingFactory(f);
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   331
            }
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   332
            construct(null, mbeanInterface, true, opts);
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   333
        } catch (NotCompliantMBeanException e) {
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   334
            throw new IllegalArgumentException(e);
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   335
        }
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   336
    }
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   337
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   338
    /**
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   339
     * <p>Make a DynamicMBean out of the object
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   340
     * <var>implementation</var>, using the specified
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   341
     * <var>mbeanInterface</var> class and the specified options.</p>
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   342
     *
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   343
     * @param implementation The implementation of this MBean.
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   344
     * @param mbeanInterface The Management Interface exported by this
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   345
     *        MBean's implementation. If <code>null</code>, then this
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   346
     *        object will use standard JMX design pattern to determine
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   347
     *        the management interface associated with the given
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   348
     *        implementation.
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   349
     * @param options MBeanOptions that control the operation of the resulting
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   350
     *        MBean, as documented in the {@link MBeanOptions} class.
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   351
     * @param <T> Allows the compiler to check
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   352
     * that {@code implementation} does indeed implement the class
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   353
     * described by {@code mbeanInterface}.  The compiler can only
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   354
     * check this if {@code mbeanInterface} is a class literal such
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   355
     * as {@code MyMBean.class}.
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   356
     *
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   357
     * @exception IllegalArgumentException if the given
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   358
     *    <var>implementation</var> is null, or if the <var>mbeanInterface</var>
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   359
     *    does not follow JMX design patterns for Management Interfaces, or
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   360
     *    if the given <var>implementation</var> does not implement the
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   361
     *    specified interface.
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   362
     **/
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   363
    public <T> StandardMBean(T implementation,
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   364
                             Class<T> mbeanInterface,
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   365
                             MBeanOptions options) {
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   366
        try {
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   367
            construct(implementation, mbeanInterface, false, options);
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   368
        } catch (NotCompliantMBeanException e) {
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   369
            throw new IllegalArgumentException(e);
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   370
        }
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   371
    }
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   372
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   373
    /**
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   374
     * <p>Make a DynamicMBean out of <var>this</var>, using the specified
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   375
     * <var>mbeanInterface</var> class and the specified options.</p>
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   376
     *
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   377
     * <p>Calls {@link #StandardMBean(Object, Class, JMX.MBeanOptions)
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   378
     *       this(this,mbeanInterface,options)}.
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   379
     * This constructor is reserved to subclasses.</p>
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   380
     *
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   381
     * @param mbeanInterface The Management Interface exported by this
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   382
     *        MBean.
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   383
     * @param options MBeanOptions that control the operation of the resulting
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   384
     *        MBean, as documented in the {@link MBeanOptions} class.
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   385
     *
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   386
     * @exception IllegalArgumentException if the <var>mbeanInterface</var>
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   387
     *    does not follow JMX design patterns for Management Interfaces, or
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   388
     *    if <var>this</var> does not implement the specified interface.
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   389
     **/
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   390
    protected StandardMBean(Class<?> mbeanInterface, MBeanOptions options) {
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   391
        try {
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   392
            construct(null, mbeanInterface, true, options);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        } catch (NotCompliantMBeanException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            throw new IllegalArgumentException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * <p>Replace the implementation object wrapped in this object.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @param implementation The new implementation of this Standard MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * (or MXBean). The <code>implementation</code> object must implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * the Standard MBean (or MXBean) interface that was supplied when this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * <code>StandardMBean</code> was constructed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @exception IllegalArgumentException if the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * <var>implementation</var> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @exception NotCompliantMBeanException if the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * <var>implementation</var> does not implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Standard MBean (or MXBean) interface that was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * supplied at construction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @see #getImplementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public void setImplementation(Object implementation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        throws NotCompliantMBeanException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        if (implementation == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            throw new IllegalArgumentException("implementation is null");
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   421
        setImplementation2(implementation);
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   422
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   424
    private <T> void setImplementation2(T implementation)
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   425
    throws NotCompliantMBeanException {
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   426
        Class<? super T> intf = Util.cast(getMBeanInterface());
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   427
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   428
        if (this.mbean.isMXBean()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            this.mbean = new MXBeanSupport(implementation,
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   430
                    intf,
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   431
                    options.getMXBeanMappingFactory());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        } else {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   433
            this.mbean = new StandardMBeanSupport(implementation, intf);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * Get the implementation of this Standard MBean (or MXBean).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @return The implementation of this Standard MBean (or MXBean).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @see #setImplementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    public Object getImplementation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        return mbean.getResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * Get the Management Interface of this Standard MBean (or MXBean).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @return The management interface of this Standard MBean (or MXBean).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    public final Class<?> getMBeanInterface() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        return mbean.getMBeanInterface();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Get the class of the implementation of this Standard MBean (or MXBean).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @return The class of the implementation of this Standard MBean (or MXBean).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    public Class<?> getImplementationClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        return mbean.getResource().getClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   463
    /**
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   464
     * Return the MBeanOptions that were specified or implied for this StandardMBean
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   465
     * instance.  If an MBeanOptions object was supplied when this StandardMBean
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   466
     * instance was constructed, and if that object has not been modified in the
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   467
     * meantime, then the returned object will be equal to that object, although
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   468
     * it might not be the same object.
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   469
     * @return The MBeanOptions that were specified or implied for this StandardMBean
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   470
     * instance.
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   471
     */
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   472
    public MBeanOptions getOptions() {
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   473
        return options.uncanonical();
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   474
    }
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   475
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    // ------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    // From the DynamicMBean interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    // ------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    public Object getAttribute(String attribute)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        throws AttributeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
               MBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
               ReflectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return mbean.getAttribute(attribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    // ------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    // From the DynamicMBean interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    // ------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    public void setAttribute(Attribute attribute)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        throws AttributeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
               InvalidAttributeValueException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
               MBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
               ReflectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        mbean.setAttribute(attribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    // ------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    // From the DynamicMBean interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    // ------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    public AttributeList getAttributes(String[] attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        return mbean.getAttributes(attributes);
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
    // From the DynamicMBean interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    // ------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    public AttributeList setAttributes(AttributeList attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        return mbean.setAttributes(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    // ------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    // From the DynamicMBean interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    // ------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    public Object invoke(String actionName, Object params[], String signature[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            throws MBeanException, ReflectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        return mbean.invoke(actionName, params, signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * Get the {@link MBeanInfo} for this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * This method implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * {@link javax.management.DynamicMBean#getMBeanInfo()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     *   DynamicMBean.getMBeanInfo()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * This method first calls {@link #getCachedMBeanInfo()} in order to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * retrieve the cached MBeanInfo for this MBean, if any. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * MBeanInfo returned by {@link #getCachedMBeanInfo()} is not null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * then it is returned.<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * Otherwise, this method builds a default MBeanInfo for this MBean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * using the Management Interface specified for this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * While building the MBeanInfo, this method calls the customization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * hooks that make it possible for subclasses to supply their custom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * descriptions, parameter names, etc...<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * Finally, it calls {@link #cacheMBeanInfo(javax.management.MBeanInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * cacheMBeanInfo()} in order to cache the new MBeanInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * @return The cached MBeanInfo for that MBean, if not null, or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     *         newly built MBeanInfo if none was cached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    public MBeanInfo getMBeanInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            final MBeanInfo cached = getCachedMBeanInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            if (cached != null) return cached;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        } catch (RuntimeException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            if (MISC_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                MISC_LOGGER.logp(Level.FINEST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                        MBeanServerFactory.class.getName(), "getMBeanInfo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                        "Failed to get cached MBeanInfo", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        if (MISC_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            MISC_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                    MBeanServerFactory.class.getName(), "getMBeanInfo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    "Building MBeanInfo for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                    getImplementationClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        MBeanSupport msupport = mbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        final MBeanInfo bi = msupport.getMBeanInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        final Object impl = msupport.getResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        final boolean immutableInfo = immutableInfo(this.getClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        final String                  cname = getClassName(bi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        final String                  text  = getDescription(bi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        final MBeanConstructorInfo[]  ctors = getConstructors(bi,impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        final MBeanAttributeInfo[]    attrs = getAttributes(bi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        final MBeanOperationInfo[]    ops   = getOperations(bi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        final MBeanNotificationInfo[] ntfs  = getNotifications(bi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        final Descriptor              desc  = getDescriptor(bi, immutableInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        final MBeanInfo nmbi = new MBeanInfo(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                cname, text, attrs, ctors, ops, ntfs, desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            cacheMBeanInfo(nmbi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        } catch (RuntimeException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            if (MISC_LOGGER.isLoggable(Level.FINEST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                MISC_LOGGER.logp(Level.FINEST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                        MBeanServerFactory.class.getName(), "getMBeanInfo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                        "Failed to cache MBeanInfo", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        return nmbi;
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
     * Customization hook:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * Get the className that will be used in the MBeanInfo returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * Subclasses may redefine this method in order to supply their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * custom class name.  The default implementation returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * {@link MBeanInfo#getClassName() info.getClassName()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @param info The default MBeanInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @return the class name for the new MBeanInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    protected String getClassName(MBeanInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        if (info == null) return getImplementationClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        return info.getClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * Customization hook:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * Get the description that will be used in the MBeanInfo returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * Subclasses may redefine this method in order to supply their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * custom MBean description.  The default implementation returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * {@link MBeanInfo#getDescription() info.getDescription()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @param info The default MBeanInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @return the description for the new MBeanInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    protected String getDescription(MBeanInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        if (info == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        return info.getDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * <p>Customization hook:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * Get the description that will be used in the MBeanFeatureInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * returned by this MBean.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * <p>Subclasses may redefine this method in order to supply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * their custom description.  The default implementation returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * {@link MBeanFeatureInfo#getDescription()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * info.getDescription()}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * <p>This method is called by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     *      {@link #getDescription(MBeanAttributeInfo)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     *      {@link #getDescription(MBeanOperationInfo)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     *      {@link #getDescription(MBeanConstructorInfo)}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * @param info The default MBeanFeatureInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * @return the description for the given MBeanFeatureInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    protected String getDescription(MBeanFeatureInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        if (info == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        return info.getDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * Customization hook:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * Get the description that will be used in the MBeanAttributeInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * returned by this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * <p>Subclasses may redefine this method in order to supply their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * custom description.  The default implementation returns {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * #getDescription(MBeanFeatureInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * getDescription((MBeanFeatureInfo) info)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * @param info The default MBeanAttributeInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @return the description for the given MBeanAttributeInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    protected String getDescription(MBeanAttributeInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        return getDescription((MBeanFeatureInfo)info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * Customization hook:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * Get the description that will be used in the MBeanConstructorInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * returned by this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * Subclasses may redefine this method in order to supply their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * custom description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * The default implementation returns {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * #getDescription(MBeanFeatureInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * getDescription((MBeanFeatureInfo) info)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * @param info The default MBeanConstructorInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * @return the description for the given MBeanConstructorInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    protected String getDescription(MBeanConstructorInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        return getDescription((MBeanFeatureInfo)info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * Customization hook:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * Get the description that will be used for the  <var>sequence</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * MBeanParameterInfo of the MBeanConstructorInfo returned by this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * Subclasses may redefine this method in order to supply their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * custom description.  The default implementation returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * {@link MBeanParameterInfo#getDescription() param.getDescription()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * @param ctor  The default MBeanConstructorInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * @param param The default MBeanParameterInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * @param sequence The sequence number of the parameter considered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     *        ("0" for the first parameter, "1" for the second parameter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     *        etc...).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * @return the description for the given MBeanParameterInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    protected String getDescription(MBeanConstructorInfo ctor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                                    MBeanParameterInfo   param,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                                    int sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        if (param == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        return param.getDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * Customization hook:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * Get the name that will be used for the <var>sequence</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * MBeanParameterInfo of the MBeanConstructorInfo returned by this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * Subclasses may redefine this method in order to supply their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * custom parameter name.  The default implementation returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * {@link MBeanParameterInfo#getName() param.getName()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * @param ctor  The default MBeanConstructorInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * @param param The default MBeanParameterInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * @param sequence The sequence number of the parameter considered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     *        ("0" for the first parameter, "1" for the second parameter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     *        etc...).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * @return the name for the given MBeanParameterInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    protected String getParameterName(MBeanConstructorInfo ctor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                                      MBeanParameterInfo param,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                                      int sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        if (param == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        return param.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * Customization hook:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * Get the description that will be used in the MBeanOperationInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * returned by this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * Subclasses may redefine this method in order to supply their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * custom description.  The default implementation returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * {@link #getDescription(MBeanFeatureInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * getDescription((MBeanFeatureInfo) info)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * @param info The default MBeanOperationInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * @return the description for the given MBeanOperationInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    protected String getDescription(MBeanOperationInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        return getDescription((MBeanFeatureInfo)info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * Customization hook:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * Get the <var>impact</var> flag of the operation that will be used in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * the MBeanOperationInfo returned by this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * Subclasses may redefine this method in order to supply their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * custom impact flag.  The default implementation returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * {@link MBeanOperationInfo#getImpact() info.getImpact()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * @param info The default MBeanOperationInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * @return the impact flag for the given MBeanOperationInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    protected int getImpact(MBeanOperationInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        if (info == null) return MBeanOperationInfo.UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        return info.getImpact();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * Customization hook:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * Get the name that will be used for the <var>sequence</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * MBeanParameterInfo of the MBeanOperationInfo returned by this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * Subclasses may redefine this method in order to supply their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * custom parameter name.  The default implementation returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * {@link MBeanParameterInfo#getName() param.getName()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * @param op    The default MBeanOperationInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * @param param The default MBeanParameterInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * @param sequence The sequence number of the parameter considered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     *        ("0" for the first parameter, "1" for the second parameter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     *        etc...).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * @return the name to use for the given MBeanParameterInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    protected String getParameterName(MBeanOperationInfo op,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                                      MBeanParameterInfo param,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                                      int sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        if (param == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        return param.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * Customization hook:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * Get the description that will be used for the  <var>sequence</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * MBeanParameterInfo of the MBeanOperationInfo returned by this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * Subclasses may redefine this method in order to supply their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * custom description.  The default implementation returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * {@link MBeanParameterInfo#getDescription() param.getDescription()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * @param op    The default MBeanOperationInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * @param param The default MBeanParameterInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * @param sequence The sequence number of the parameter considered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     *        ("0" for the first parameter, "1" for the second parameter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     *        etc...).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * @return the description for the given MBeanParameterInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    protected String getDescription(MBeanOperationInfo op,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                                    MBeanParameterInfo param,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                                    int sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        if (param == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        return param.getDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * Customization hook:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * Get the MBeanConstructorInfo[] that will be used in the MBeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * returned by this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * By default, this method returns <code>null</code> if the wrapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * implementation is not <var>this</var>. Indeed, if the wrapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * implementation is not this object itself, it will not be possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * to recreate a wrapped implementation by calling the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * constructors through <code>MBeanServer.createMBean(...)</code>.<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * Otherwise, if the wrapped implementation is <var>this</var>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * <var>ctors</var> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * Subclasses may redefine this method in order to modify this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * behavior, if needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * @param ctors The default MBeanConstructorInfo[] derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * @param impl  The wrapped implementation. If <code>null</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     *        passed, the wrapped implementation is ignored and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     *        <var>ctors</var> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * @return the MBeanConstructorInfo[] for the new MBeanInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    protected MBeanConstructorInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        getConstructors(MBeanConstructorInfo[] ctors, Object impl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            if (ctors == null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            if (impl != null && impl != this) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            return ctors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * Customization hook:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * Get the MBeanNotificationInfo[] that will be used in the MBeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * returned by this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * Subclasses may redefine this method in order to supply their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * custom notifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * @param info The default MBeanInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * @return the MBeanNotificationInfo[] for the new MBeanInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    MBeanNotificationInfo[] getNotifications(MBeanInfo info) {
687
874e25a9844a 6562936: Support custom type mappings in MXBeans
emcmanus
parents: 526
diff changeset
   840
        return info.getNotifications();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * <p>Get the Descriptor that will be used in the MBeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * returned by this MBean.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * <p>Subclasses may redefine this method in order to supply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * their custom descriptor.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * <p>The default implementation of this method returns a Descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * that contains at least the field {@code interfaceClassName}, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * value {@link #getMBeanInterface()}.getName(). It may also contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * the field {@code immutableInfo}, with a value that is the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * {@code "true"} if the implementation can determine that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * {@code MBeanInfo} returned by {@link #getMBeanInfo()} will always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * be the same. It may contain other fields: fields defined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * JMX specification must have appropriate values, and other fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * must follow the conventions for non-standard field names.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * @param info The default MBeanInfo derived by reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * @return the Descriptor for the new MBeanInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    Descriptor getDescriptor(MBeanInfo info, boolean immutableInfo) {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
   864
        ImmutableDescriptor desc;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        if (info == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            info.getDescriptor() == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            info.getDescriptor().getFieldNames().length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            final String interfaceClassNameS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                "interfaceClassName=" + getMBeanInterface().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            final String immutableInfoS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                "immutableInfo=" + immutableInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            desc = new ImmutableDescriptor(interfaceClassNameS, immutableInfoS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            desc = descriptors.get(desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            Descriptor d = info.getDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            Map<String,Object> fields = new HashMap<String,Object>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            for (String fieldName : d.getFieldNames()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                if (fieldName.equals("immutableInfo")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                    // Replace immutableInfo as the underlying MBean/MXBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                    // could already implement NotificationBroadcaster and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                    // return immutableInfo=true in its MBeanInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                    fields.put(fieldName, Boolean.toString(immutableInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                    fields.put(fieldName, d.getFieldValue(fieldName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            desc = new ImmutableDescriptor(fields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        return desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * Customization hook:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * Return the MBeanInfo cached for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * <p>Subclasses may redefine this method in order to implement their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * own caching policy.  The default implementation stores one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * {@link MBeanInfo} object per instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * @return The cached MBeanInfo, or null if no MBeanInfo is cached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * @see #cacheMBeanInfo(MBeanInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    protected MBeanInfo getCachedMBeanInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        return cachedMBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * Customization hook:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * cache the MBeanInfo built for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * <p>Subclasses may redefine this method in order to implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * their own caching policy.  The default implementation stores
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * <code>info</code> in this instance.  A subclass can define
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * other policies, such as not saving <code>info</code> (so it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * reconstructed every time {@link #getMBeanInfo()} is called) or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * sharing a unique {@link MBeanInfo} object when several
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * <code>StandardMBean</code> instances have equal {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * MBeanInfo} values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * @param info the new <code>MBeanInfo</code> to cache.  Any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * previously cached value is discarded.  This parameter may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * null, in which case there is no new cached value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    protected void cacheMBeanInfo(MBeanInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        cachedMBeanInfo = info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    private boolean isMXBean() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        return mbean.isMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    private static <T> boolean identicalArrays(T[] a, T[] b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        if (a == b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        if (a == null || b == null || a.length != b.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        for (int i = 0; i < a.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            if (a[i] != b[i])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    private static <T> boolean equal(T a, T b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        if (a == b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        if (a == null || b == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        return a.equals(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    private static MBeanParameterInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            customize(MBeanParameterInfo pi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                      String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                      String description) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        if (equal(name, pi.getName()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                equal(description, pi.getDescription()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            return pi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        else if (pi instanceof OpenMBeanParameterInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            OpenMBeanParameterInfo opi = (OpenMBeanParameterInfo) pi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            return new OpenMBeanParameterInfoSupport(name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                                                     description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                                                     opi.getOpenType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                                                     pi.getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            return new MBeanParameterInfo(name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                                          pi.getType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                                          description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                                          pi.getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    private static MBeanConstructorInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            customize(MBeanConstructorInfo ci,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                      String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                      MBeanParameterInfo[] signature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        if (equal(description, ci.getDescription()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                identicalArrays(signature, ci.getSignature()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            return ci;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        if (ci instanceof OpenMBeanConstructorInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            OpenMBeanParameterInfo[] oparams =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                paramsToOpenParams(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            return new OpenMBeanConstructorInfoSupport(ci.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                                                       description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                                                       oparams,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                                                       ci.getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            return new MBeanConstructorInfo(ci.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                                            description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                                            signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                                            ci.getDescriptor());
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
    private static MBeanOperationInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            customize(MBeanOperationInfo oi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                      String description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                      MBeanParameterInfo[] signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                      int impact) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        if (equal(description, oi.getDescription()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                identicalArrays(signature, oi.getSignature()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                impact == oi.getImpact())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            return oi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        if (oi instanceof OpenMBeanOperationInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            OpenMBeanOperationInfo ooi = (OpenMBeanOperationInfo) oi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            OpenMBeanParameterInfo[] oparams =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                paramsToOpenParams(signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            return new OpenMBeanOperationInfoSupport(oi.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                                                     description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                                                     oparams,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                                                     ooi.getReturnOpenType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                                                     impact,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                                                     oi.getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            return new MBeanOperationInfo(oi.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                                          description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                                          signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                                          oi.getReturnType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                                          impact,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                                          oi.getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    private static MBeanAttributeInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            customize(MBeanAttributeInfo ai,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                      String description) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        if (equal(description, ai.getDescription()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            return ai;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        if (ai instanceof OpenMBeanAttributeInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            OpenMBeanAttributeInfo oai = (OpenMBeanAttributeInfo) ai;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            return new OpenMBeanAttributeInfoSupport(ai.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                                                     description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                                                     oai.getOpenType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                                                     ai.isReadable(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                                                     ai.isWritable(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                                                     ai.isIs(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                                                     ai.getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            return new MBeanAttributeInfo(ai.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                                          ai.getType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                                          description,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                                          ai.isReadable(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                                          ai.isWritable(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                                          ai.isIs(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                                          ai.getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    private static OpenMBeanParameterInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            paramsToOpenParams(MBeanParameterInfo[] params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        if (params instanceof OpenMBeanParameterInfo[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            return (OpenMBeanParameterInfo[]) params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        OpenMBeanParameterInfo[] oparams =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            new OpenMBeanParameterInfoSupport[params.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        System.arraycopy(params, 0, oparams, 0, params.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        return oparams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    // ------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    // Build the custom MBeanConstructorInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    // ------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    private MBeanConstructorInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            getConstructors(MBeanInfo info, Object impl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        final MBeanConstructorInfo[] ctors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            getConstructors(info.getConstructors(), impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        if (ctors == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        final int ctorlen = ctors.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        final MBeanConstructorInfo[] nctors = new MBeanConstructorInfo[ctorlen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        for (int i=0; i<ctorlen; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            final MBeanConstructorInfo c = ctors[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            final MBeanParameterInfo[] params = c.getSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            final MBeanParameterInfo[] nps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            if (params != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                final int plen = params.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                nps = new MBeanParameterInfo[plen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                for (int ii=0;ii<plen;ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                    MBeanParameterInfo p = params[ii];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                    nps[ii] = customize(p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                                        getParameterName(c,p,ii),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                                        getDescription(c,p,ii));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                nps = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            nctors[i] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                customize(c, getDescription(c), nps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        return nctors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    // ------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    // Build the custom MBeanOperationInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    // ------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    private MBeanOperationInfo[] getOperations(MBeanInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        final MBeanOperationInfo[] ops = info.getOperations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        if (ops == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        final int oplen = ops.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        final MBeanOperationInfo[] nops = new MBeanOperationInfo[oplen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        for (int i=0; i<oplen; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            final MBeanOperationInfo o = ops[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            final MBeanParameterInfo[] params = o.getSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            final MBeanParameterInfo[] nps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            if (params != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                final int plen = params.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                nps = new MBeanParameterInfo[plen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                for (int ii=0;ii<plen;ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                    MBeanParameterInfo p = params[ii];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                    nps[ii] = customize(p,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                                        getParameterName(o,p,ii),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                                        getDescription(o,p,ii));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                nps = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            nops[i] = customize(o, getDescription(o), nps, getImpact(o));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        return nops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    // ------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    // Build the custom MBeanAttributeInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    // ------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    private MBeanAttributeInfo[] getAttributes(MBeanInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        final MBeanAttributeInfo[] atts = info.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        if (atts == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            return null; // should not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        final MBeanAttributeInfo[] natts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        final int attlen = atts.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        natts = new MBeanAttributeInfo[attlen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        for (int i=0; i<attlen; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            final MBeanAttributeInfo a = atts[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            natts[i] = customize(a, getDescription(a));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        return natts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * <p>Allows the MBean to perform any operations it needs before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * being registered in the MBean server.  If the name of the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * is not specified, the MBean can provide a name for its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * registration.  If any exception is raised, the MBean will not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * registered in the MBean server.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * <p>The default implementation of this method returns the {@code name}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * parameter.  It does nothing else for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * Standard MBeans.  For MXBeans, it records the {@code MBeanServer}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * and {@code ObjectName} parameters so they can be used to translate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * inter-MXBean references.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * <p>It is good practice for a subclass that overrides this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * to call the overridden method via {@code super.preRegister(...)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     * This is necessary if this object is an MXBean that is referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * by attributes or operations in other MXBeans.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * @param server The MBean server in which the MBean will be registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * @param name The object name of the MBean.  This name is null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * the name parameter to one of the <code>createMBean</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * <code>registerMBean</code> methods in the {@link MBeanServer}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * interface is null.  In that case, this method must return a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * non-null ObjectName for the new MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * @return The name under which the MBean is to be registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * This value must not be null.  If the <code>name</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * parameter is not null, it will usually but not necessarily be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * the returned value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * @throws IllegalArgumentException if this is an MXBean and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * {@code name} is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * @throws InstanceAlreadyExistsException if this is an MXBean and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * it has already been registered under another name (in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     * MBean Server or another).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * @throws Exception no other checked exceptions are thrown by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     * this method but {@code Exception} is declared so that subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * can override the method and throw their own exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    public ObjectName preRegister(MBeanServer server, ObjectName name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        mbean.register(server, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * <p>Allows the MBean to perform any operations needed after having been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * registered in the MBean server or after the registration has failed.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * <p>The default implementation of this method does nothing for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * Standard MBeans.  For MXBeans, it undoes any work done by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     * {@link #preRegister preRegister} if registration fails.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     * <p>It is good practice for a subclass that overrides this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     * to call the overridden method via {@code super.postRegister(...)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     * This is necessary if this object is an MXBean that is referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     * by attributes or operations in other MXBeans.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * @param registrationDone Indicates whether or not the MBean has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * been successfully registered in the MBean server. The value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     * false means that the registration phase has failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    public void postRegister(Boolean registrationDone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        if (!registrationDone)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            mbean.unregister();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     * <p>Allows the MBean to perform any operations it needs before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     * being unregistered by the MBean server.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     * <p>The default implementation of this method does nothing.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     * <p>It is good practice for a subclass that overrides this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     * to call the overridden method via {@code super.preDeegister(...)}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     * @throws Exception no checked exceptions are throw by this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     * but {@code Exception} is declared so that subclasses can override
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * this method and throw their own exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    public void preDeregister() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * <p>Allows the MBean to perform any operations needed after having been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * unregistered in the MBean server.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * <p>The default implementation of this method does nothing for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     * Standard MBeans.  For MXBeans, it removes any information that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * was recorded by the {@link #preRegister preRegister} method.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * <p>It is good practice for a subclass that overrides this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * to call the overridden method via {@code super.postRegister(...)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * This is necessary if this object is an MXBean that is referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * by attributes or operations in other MXBeans.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
    public void postDeregister() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        mbean.unregister();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    // MBeanInfo immutability
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * Cached results of previous calls to immutableInfo. This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * a WeakHashMap so that we don't prevent a class from being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * garbage collected just because we know whether its MBeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     * is immutable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    private static final Map<Class, Boolean> mbeanInfoSafeMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        new WeakHashMap<Class, Boolean>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * Return true if {@code subclass} is known to preserve the immutability
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * of the {@code MBeanInfo}. The {@code subclass} is considered to have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * an immutable {@code MBeanInfo} if it does not override any of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     * getMBeanInfo, getCachedMBeanInfo, cacheMBeanInfo and getNotificationInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    static boolean immutableInfo(Class<? extends StandardMBean> subclass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        if (subclass == StandardMBean.class ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            subclass == StandardEmitterMBean.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        synchronized (mbeanInfoSafeMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            Boolean safe = mbeanInfoSafeMap.get(subclass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
            if (safe == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                    MBeanInfoSafeAction action =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                        new MBeanInfoSafeAction(subclass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                    safe = AccessController.doPrivileged(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                } catch (Exception e) { // e.g. SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                    /* We don't know, so we assume it isn't.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                    safe = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                mbeanInfoSafeMap.put(subclass, safe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            return safe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    static boolean overrides(Class<?> subclass, Class<?> superclass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                             String name, Class<?>... params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        for (Class<?> c = subclass; c != superclass; c = c.getSuperclass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                c.getDeclaredMethod(name, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
            } catch (NoSuchMethodException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                // OK: this class doesn't override it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
    private static class MBeanInfoSafeAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            implements PrivilegedAction<Boolean> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        private final Class subclass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        MBeanInfoSafeAction(Class subclass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            this.subclass = subclass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        public Boolean run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            // Check for "void cacheMBeanInfo(MBeanInfo)" method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            if (overrides(subclass, StandardMBean.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                          "cacheMBeanInfo", MBeanInfo.class))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            // Check for "MBeanInfo getCachedMBeanInfo()" method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
            if (overrides(subclass, StandardMBean.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                          "getCachedMBeanInfo", (Class[]) null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            // Check for "MBeanInfo getMBeanInfo()" method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            if (overrides(subclass, StandardMBean.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                          "getMBeanInfo", (Class[]) null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            // Check for "MBeanNotificationInfo[] getNotificationInfo()"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            // method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
            // This method is only taken into account for the MBeanInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            // immutability checks if and only if the given subclass is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            // StandardEmitterMBean itself or can be assigned to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
            // StandardEmitterMBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            if (StandardEmitterMBean.class.isAssignableFrom(subclass))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                if (overrides(subclass, StandardEmitterMBean.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                              "getNotificationInfo", (Class[]) null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
}