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