--- a/jdk/src/share/classes/javax/management/modelmbean/RequiredModelMBean.java Sat Jul 05 23:29:16 2008 -0700
+++ b/jdk/src/share/classes/javax/management/modelmbean/RequiredModelMBean.java Wed Jul 09 09:56:00 2008 -0700
@@ -23,7 +23,7 @@
* have any questions.
*/
/*
- * @author IBM Corp.
+ * @(#)author IBM Corp.
*
* Copyright IBM Corp. 1999-2000. All rights reserved.
*/
@@ -55,6 +55,7 @@
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.Descriptor;
+import javax.management.DynamicWrapperMBean;
import javax.management.InstanceNotFoundException;
import javax.management.InvalidAttributeValueException;
import javax.management.ListenerNotFoundException;
@@ -115,7 +116,7 @@
*/
public class RequiredModelMBean
- implements ModelMBean, MBeanRegistration, NotificationEmitter {
+ implements ModelMBean, MBeanRegistration, NotificationEmitter, DynamicWrapperMBean {
/*************************************/
/* attributes */
@@ -133,6 +134,9 @@
* and operations will be executed */
private Object managedResource = null;
+ /* true if getWrappedObject returns the wrapped resource */
+ private boolean visible;
+
/* records the registering in MBeanServer */
private boolean registered = false;
private transient MBeanServer server = null;
@@ -318,9 +322,13 @@
*
* @param mr Object that is the managed resource
* @param mr_type The type of reference for the managed resource.
- * <br>Can be: "ObjectReference", "Handle", "IOR", "EJBHandle",
- * or "RMIReference".
- * <br>In this implementation only "ObjectReference" is supported.
+ * <br>Can be: "ObjectReference", "VisibleObjectReference",
+ * "Handle", "IOR", "EJBHandle", or "RMIReference".
+ * <br>In this implementation only "ObjectReference" and
+ * "VisibleObjectReference" are supported. The two
+ * types are equivalent except for the behavior of the
+ * {@link #getWrappedObject()} and {@link #getWrappedClassLoader()}
+ * methods.
*
* @exception MBeanException The initializer of the object has
* thrown an exception.
@@ -340,10 +348,11 @@
"setManagedResource(Object,String)","Entry");
}
+ visible = "visibleObjectReference".equalsIgnoreCase(mr_type);
+
// check that the mr_type is supported by this JMXAgent
// only "objectReference" is supported
- if ((mr_type == null) ||
- (! mr_type.equalsIgnoreCase("objectReference"))) {
+ if (!"objectReference".equalsIgnoreCase(mr_type) && !visible) {
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
MODELMBEAN_LOGGER.logp(Level.FINER,
RequiredModelMBean.class.getName(),
@@ -369,6 +378,51 @@
}
/**
+ * <p>Get the managed resource for this Model MBean. For compatibility
+ * reasons, the managed resource is only returned if the resource type
+ * specified to {@link #setManagedResource setManagedResource} was {@code
+ * "visibleObjectReference"}. Otherwise, {@code this} is returned.</p>
+ *
+ * @return The value that was specified to {@link #setManagedResource
+ * setManagedResource}, if the resource type is {@code
+ * "visibleObjectReference"}. Otherwise, {@code this}.
+ */
+ public Object getWrappedObject() {
+ if (visible)
+ return managedResource;
+ else
+ return this;
+ }
+
+ /**
+ * <p>Get the ClassLoader of the managed resource for this Model MBean. For
+ * compatibility reasons, the ClassLoader of the managed resource is only
+ * returned if the resource type specified to {@link #setManagedResource
+ * setManagedResource} was {@code "visibleObjectReference"}. Otherwise,
+ * {@code this.getClass().getClassLoader()} is returned.</p>
+ *
+ * @return The ClassLoader of the value that was specified to
+ * {@link #setManagedResource setManagedResource}, if the resource
+ * type is {@code "visibleObjectReference"}. Otherwise, {@code
+ * this.getClass().getClassLoader()}.
+ */
+ public ClassLoader getWrappedClassLoader() {
+ return getWrappedObject().getClass().getClassLoader();
+ }
+
+ private static boolean isTrue(Descriptor d, String field) {
+ if (d == null)
+ return false;
+ Object x = d.getFieldValue(field);
+ if (x instanceof Boolean)
+ return (Boolean) x;
+ if (!(x instanceof String))
+ return false;
+ String s = (String) x;
+ return ("true".equalsIgnoreCase(s) || "T".equalsIgnoreCase(s));
+ }
+
+ /**
* <p>Instantiates this MBean instance with the data found for
* the MBean in the persistent store. The data loaded could include
* attribute and operation values.</p>