jdk/src/share/classes/javax/management/modelmbean/RequiredModelMBean.java
changeset 834 dc74d4ddc28e
parent 715 f16baef3a20e
parent 833 bfa2bef7517c
child 1004 5ba8217eb504
equal deleted inserted replaced
832:5484c7a35278 834:dc74d4ddc28e
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    23  * have any questions.
    23  * have any questions.
    24  */
    24  */
    25 /*
    25 /*
    26  * @author    IBM Corp.
    26  * @(#)author    IBM Corp.
    27  *
    27  *
    28  * Copyright IBM Corp. 1999-2000.  All rights reserved.
    28  * Copyright IBM Corp. 1999-2000.  All rights reserved.
    29  */
    29  */
    30 
    30 
    31 
    31 
    53 import javax.management.AttributeChangeNotification;
    53 import javax.management.AttributeChangeNotification;
    54 import javax.management.AttributeChangeNotificationFilter;
    54 import javax.management.AttributeChangeNotificationFilter;
    55 import javax.management.AttributeList;
    55 import javax.management.AttributeList;
    56 import javax.management.AttributeNotFoundException;
    56 import javax.management.AttributeNotFoundException;
    57 import javax.management.Descriptor;
    57 import javax.management.Descriptor;
       
    58 import javax.management.DynamicWrapperMBean;
    58 import javax.management.InstanceNotFoundException;
    59 import javax.management.InstanceNotFoundException;
    59 import javax.management.InvalidAttributeValueException;
    60 import javax.management.InvalidAttributeValueException;
    60 import javax.management.ListenerNotFoundException;
    61 import javax.management.ListenerNotFoundException;
    61 import javax.management.MBeanAttributeInfo;
    62 import javax.management.MBeanAttributeInfo;
    62 import javax.management.MBeanConstructorInfo;
    63 import javax.management.MBeanConstructorInfo;
   113  *
   114  *
   114  * @since 1.5
   115  * @since 1.5
   115  */
   116  */
   116 
   117 
   117 public class RequiredModelMBean
   118 public class RequiredModelMBean
   118     implements ModelMBean, MBeanRegistration, NotificationEmitter {
   119     implements ModelMBean, MBeanRegistration, NotificationEmitter, DynamicWrapperMBean {
   119 
   120 
   120     /*************************************/
   121     /*************************************/
   121     /* attributes                        */
   122     /* attributes                        */
   122     /*************************************/
   123     /*************************************/
   123     ModelMBeanInfo modelMBeanInfo;
   124     ModelMBeanInfo modelMBeanInfo;
   130     private NotificationBroadcasterSupport attributeBroadcaster = null;
   131     private NotificationBroadcasterSupport attributeBroadcaster = null;
   131 
   132 
   132     /* handle, name, or reference for instance on which the actual invoke
   133     /* handle, name, or reference for instance on which the actual invoke
   133      * and operations will be executed */
   134      * and operations will be executed */
   134     private Object managedResource = null;
   135     private Object managedResource = null;
       
   136 
       
   137     /* true if getWrappedObject returns the wrapped resource */
       
   138     private boolean visible;
   135 
   139 
   136     /* records the registering in MBeanServer */
   140     /* records the registering in MBeanServer */
   137     private boolean registered = false;
   141     private boolean registered = false;
   138     private transient MBeanServer server = null;
   142     private transient MBeanServer server = null;
   139 
   143 
   316      * execute all methods in this ModelMBean management interface
   320      * execute all methods in this ModelMBean management interface
   317      * (MBeanInfo and Descriptors).
   321      * (MBeanInfo and Descriptors).
   318      *
   322      *
   319      * @param mr Object that is the managed resource
   323      * @param mr Object that is the managed resource
   320      * @param mr_type The type of reference for the managed resource.
   324      * @param mr_type The type of reference for the managed resource.
   321      *     <br>Can be: "ObjectReference", "Handle", "IOR", "EJBHandle",
   325      *     <br>Can be: "ObjectReference", "VisibleObjectReference",
   322      *         or "RMIReference".
   326      *         "Handle", "IOR", "EJBHandle", or "RMIReference".
   323      *     <br>In this implementation only "ObjectReference" is supported.
   327      *     <br>In this implementation only "ObjectReference" and
       
   328      *         "VisibleObjectReference" are supported.  The two
       
   329      *         types are equivalent except for the behavior of the
       
   330      *         {@link #getWrappedObject()} and {@link #getWrappedClassLoader()}
       
   331      *         methods.
   324      *
   332      *
   325      * @exception MBeanException The initializer of the object has
   333      * @exception MBeanException The initializer of the object has
   326      *            thrown an exception.
   334      *            thrown an exception.
   327      * @exception InstanceNotFoundException The managed resource
   335      * @exception InstanceNotFoundException The managed resource
   328      *            object could not be found
   336      *            object could not be found
   338             MODELMBEAN_LOGGER.logp(Level.FINER,
   346             MODELMBEAN_LOGGER.logp(Level.FINER,
   339                     RequiredModelMBean.class.getName(),
   347                     RequiredModelMBean.class.getName(),
   340                 "setManagedResource(Object,String)","Entry");
   348                 "setManagedResource(Object,String)","Entry");
   341         }
   349         }
   342 
   350 
       
   351         visible = "visibleObjectReference".equalsIgnoreCase(mr_type);
       
   352 
   343         // check that the mr_type is supported by this JMXAgent
   353         // check that the mr_type is supported by this JMXAgent
   344         // only "objectReference" is supported
   354         // only "objectReference" is supported
   345         if ((mr_type == null) ||
   355         if (!"objectReference".equalsIgnoreCase(mr_type) && !visible) {
   346             (! mr_type.equalsIgnoreCase("objectReference"))) {
       
   347             if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   356             if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   348                 MODELMBEAN_LOGGER.logp(Level.FINER,
   357                 MODELMBEAN_LOGGER.logp(Level.FINER,
   349                         RequiredModelMBean.class.getName(),
   358                         RequiredModelMBean.class.getName(),
   350                     "setManagedResource(Object,String)",
   359                     "setManagedResource(Object,String)",
   351                     "Managed Resouce Type is not supported: " + mr_type);
   360                     "Managed Resouce Type is not supported: " + mr_type);
   364         if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   373         if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
   365             MODELMBEAN_LOGGER.logp(Level.FINER,
   374             MODELMBEAN_LOGGER.logp(Level.FINER,
   366                     RequiredModelMBean.class.getName(),
   375                     RequiredModelMBean.class.getName(),
   367                 "setManagedResource(Object, String)", "Exit");
   376                 "setManagedResource(Object, String)", "Exit");
   368         }
   377         }
       
   378     }
       
   379 
       
   380     /**
       
   381      * <p>Get the managed resource for this Model MBean. For compatibility
       
   382      * reasons, the managed resource is only returned if the resource type
       
   383      * specified to {@link #setManagedResource setManagedResource} was {@code
       
   384      * "visibleObjectReference"}. Otherwise, {@code this} is returned.</p>
       
   385      *
       
   386      * @return The value that was specified to {@link #setManagedResource
       
   387      * setManagedResource}, if the resource type is {@code
       
   388      * "visibleObjectReference"}. Otherwise, {@code this}.
       
   389      */
       
   390     public Object getWrappedObject() {
       
   391         if (visible)
       
   392             return managedResource;
       
   393         else
       
   394             return this;
       
   395     }
       
   396 
       
   397     /**
       
   398      * <p>Get the ClassLoader of the managed resource for this Model MBean. For
       
   399      * compatibility reasons, the ClassLoader of the managed resource is only
       
   400      * returned if the resource type specified to {@link #setManagedResource
       
   401      * setManagedResource} was {@code "visibleObjectReference"}. Otherwise,
       
   402      * {@code this.getClass().getClassLoader()} is returned.</p>
       
   403      *
       
   404      * @return The ClassLoader of the value that was specified to
       
   405      * {@link #setManagedResource setManagedResource}, if the resource
       
   406      * type is {@code "visibleObjectReference"}. Otherwise, {@code
       
   407      * this.getClass().getClassLoader()}.
       
   408      */
       
   409     public ClassLoader getWrappedClassLoader() {
       
   410         return getWrappedObject().getClass().getClassLoader();
       
   411     }
       
   412 
       
   413     private static boolean isTrue(Descriptor d, String field) {
       
   414         if (d == null)
       
   415             return false;
       
   416         Object x = d.getFieldValue(field);
       
   417         if (x instanceof Boolean)
       
   418             return (Boolean) x;
       
   419         if (!(x instanceof String))
       
   420             return false;
       
   421         String s = (String) x;
       
   422         return ("true".equalsIgnoreCase(s) || "T".equalsIgnoreCase(s));
   369     }
   423     }
   370 
   424 
   371     /**
   425     /**
   372      * <p>Instantiates this MBean instance with the data found for
   426      * <p>Instantiates this MBean instance with the data found for
   373      * the MBean in the persistent store.  The data loaded could include
   427      * the MBean in the persistent store.  The data loaded could include