From 7b46d1d489f336316cee2fc2ab5330c3a818d5d9 Mon Sep 17 00:00:00 2001
From: costin
ModelMBeanAttributeInfo object that corresponds
- * to this AttributeInfo instance.
- */
- protected transient ModelMBeanAttributeInfo info = null;
protected String displayName = null;
+
+ // Information about the method to use
protected String getMethod = null;
protected String setMethod = null;
-
- protected transient Method getMethodObj = null;
- protected transient Method setMethodObj = null;
-
protected boolean readable = true;
protected boolean writeable = true;
-
protected boolean is = false;
- protected String type = null;
-
- protected String persist;
- protected String defaultStringValue;
+
// ------------------------------------------------------------- Properties
-
- /**
- * Override the description property setter.
- *
- * @param description The new description
- */
- public void setDescription(String description) {
- super.setDescription(description);
- this.info = null;
- }
-
- /**
- * Override the name property setter.
- *
- * @param name The new name
- */
- public void setName(String name) {
- super.setName(name);
- this.info = null;
- }
-
/**
* The display name of this attribute.
*/
@@ -97,28 +59,13 @@ public class AttributeInfo extends FeatureInfo implements Serializable {
* The name of the property getter method, if non-standard.
*/
public String getGetMethod() {
+ if(getMethod == null)
+ getMethod = getMethodName(getName(), true, isIs());
return (this.getMethod);
}
public void setGetMethod(String getMethod) {
this.getMethod = getMethod;
- this.info = null;
- }
-
- public Method getGetMethodObj() {
- return getMethodObj;
- }
-
- public void setGetMethodObj(Method getMethodObj) {
- this.getMethodObj = getMethodObj;
- }
-
- public Method getSetMethodObj() {
- return setMethodObj;
- }
-
- public void setSetMethodObj(Method setMethodObj) {
- this.setMethodObj = setMethodObj;
}
/**
@@ -130,7 +77,6 @@ public class AttributeInfo extends FeatureInfo implements Serializable {
public void setIs(boolean is) {
this.is = is;
- this.info = null;
}
@@ -143,7 +89,6 @@ public class AttributeInfo extends FeatureInfo implements Serializable {
public void setReadable(boolean readable) {
this.readable = readable;
- this.info = null;
}
@@ -151,28 +96,15 @@ public class AttributeInfo extends FeatureInfo implements Serializable {
* The name of the property setter method, if non-standard.
*/
public String getSetMethod() {
+ if( setMethod == null )
+ setMethod = getMethodName(getName(), false, false);
return (this.setMethod);
}
public void setSetMethod(String setMethod) {
this.setMethod = setMethod;
- this.info = null;
- }
-
-
- /**
- * The fully qualified Java class name of this attribute.
- */
- public String getType() {
- return (this.type);
- }
-
- public void setType(String type) {
- this.type = type;
- this.info = null;
}
-
/**
* Is this attribute writeable by management applications?
*/
@@ -182,35 +114,8 @@ public class AttributeInfo extends FeatureInfo implements Serializable {
public void setWriteable(boolean writeable) {
this.writeable = writeable;
- this.info = null;
- }
-
- /** Persistence policy.
- * All persistent attributes should have this attribute set.
- * Valid values:
- * ???
- */
- public String getPersist() {
- return persist;
}
- public void setPersist(String persist) {
- this.persist = persist;
- }
-
- /** Default value. If set, it can provide info to the user and
- * it can be used by persistence mechanism to generate a more compact
- * representation ( a value may not be saved if it's default )
- */
- public String getDefault() {
- return defaultStringValue;
- }
-
- public void setDefault(String defaultStringValue) {
- this.defaultStringValue = defaultStringValue;
- }
-
-
// --------------------------------------------------------- Public Methods
@@ -218,74 +123,15 @@ public class AttributeInfo extends FeatureInfo implements Serializable {
* Create and return a ModelMBeanAttributeInfo object that
* corresponds to the attribute described by this instance.
*/
- public ModelMBeanAttributeInfo createAttributeInfo() {
+ MBeanAttributeInfo createAttributeInfo() {
// Return our cached information (if any)
- if (info != null)
- return (info);
- if((getMethodObj != null) || (setMethodObj != null) ) {
- try {
- info=new ModelMBeanAttributeInfo(getName(), getDescription(),
- getMethodObj, setMethodObj);
- return info;
- } catch( Exception ex) {
- ex.printStackTrace();
- }
+ if (info == null) {
+ info = new MBeanAttributeInfo(getName(), getType(), getDescription(),
+ isReadable(), isWriteable(), false);
}
-
- // Create and return a new information object
- info = new ModelMBeanAttributeInfo
- (getName(), getType(), getDescription(),
- isReadable(), isWriteable(), false);
- Descriptor descriptor = info.getDescriptor();
- if (getDisplayName() != null)
- descriptor.setField("displayName", getDisplayName());
- if (isReadable()) {
- if (getGetMethod() != null)
- descriptor.setField("getMethod", getGetMethod());
- else
- descriptor.setField("getMethod",
- getMethodName(getName(), true, isIs()));
- }
- if (isWriteable()) {
- if (getSetMethod() != null)
- descriptor.setField("setMethod", getSetMethod());
- else
- descriptor.setField("setMethod",
- getMethodName(getName(), false, false));
- }
- addFields(descriptor);
- info.setDescriptor(descriptor);
- return (info);
-
- }
-
-
- /**
- * Return a string representation of this attribute descriptor.
- */
- public String toString() {
-
- StringBuffer sb = new StringBuffer("AttributeInfo[");
- sb.append("name=");
- sb.append(name);
- sb.append(", description=");
- sb.append(description);
- if (!readable) {
- sb.append(", readable=");
- sb.append(readable);
- }
- sb.append(", type=");
- sb.append(type);
- if (!writeable) {
- sb.append(", writeable=");
- sb.append(writeable);
- }
- sb.append("]");
- return (sb.toString());
-
+ return (MBeanAttributeInfo)info;
}
-
// -------------------------------------------------------- Private Methods
diff --git a/java/org/apache/tomcat/util/modeler/BaseModelMBean.java b/java/org/apache/tomcat/util/modeler/BaseModelMBean.java
index f633beb1c..28b8c9c8b 100644
--- a/java/org/apache/tomcat/util/modeler/BaseModelMBean.java
+++ b/java/org/apache/tomcat/util/modeler/BaseModelMBean.java
@@ -20,15 +20,12 @@ package org.apache.tomcat.util.modeler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Hashtable;
import java.util.Iterator;
import javax.management.Attribute;
import javax.management.AttributeChangeNotification;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
-import javax.management.Descriptor;
import javax.management.DynamicMBean;
import javax.management.InstanceNotFoundException;
import javax.management.InvalidAttributeValueException;
@@ -45,30 +42,40 @@ import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.RuntimeErrorException;
import javax.management.RuntimeOperationsException;
-import javax.management.ServiceNotFoundException;
-import javax.management.modelmbean.DescriptorSupport;
import javax.management.modelmbean.InvalidTargetObjectTypeException;
-import javax.management.modelmbean.ModelMBean;
-import javax.management.modelmbean.ModelMBeanAttributeInfo;
-import javax.management.modelmbean.ModelMBeanInfo;
-import javax.management.modelmbean.ModelMBeanInfoSupport;
-import javax.management.modelmbean.ModelMBeanNotificationInfo;
-import javax.management.modelmbean.ModelMBeanOperationInfo;
+import javax.management.modelmbean.ModelMBeanNotificationBroadcaster;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.tomcat.util.modeler.modules.ModelerSource;
-// TODO: enable ant-like substitutions ? ( or at least discuss it )
+/*
+ * Changes from commons.modeler:
+ *
+ * - use DynamicMBean
+ * - remove methods not used in tomcat and redundant/not very generic
+ * - must be created from the ManagedBean - I don't think there were any direct
+ * uses, but now it is required.
+ * - some of the gratuituous flexibility removed - instead this is more predictive and
+ * strict with the use cases.
+ * - all Method and metadata is stored in ManagedBean. BaseModelBMean and ManagedBean act
+ * like Object and Class.
+ * - setModelMBean is no longer called on resources ( not used in tomcat )
+ * - no caching of Methods for now - operations and setters are not called repeatedly in most
+ * management use cases. Getters should't be called very frequently either - and even if they
+ * are, the overhead of getting the method should be small compared with other JMX costs ( RMI, etc ).
+ * We can add getter cache if needed.
+ * - removed unused constructor, fields
+ *
+ * TODO:
+ * - clean up catalina.mbeans, stop using weird inheritance
+ */
/**
- * Basic implementation of the ModelMBean interface, which
+ *
Basic implementation of the DynamicMBean interface, which
* supports the minimal requirements of the interface contract.
This can be used directly to wrap an existing java bean, or inside - * an mlet or anywhere an MBean would be used. The String parameter - * passed to the constructor will be used to construct an instance of the - * real object that we wrap. + * an mlet or anywhere an MBean would be used. * * Limitations: *
invoke() are immediately executed.ModelMBean associated with the specified
- * ModelMBeanInfo information.
- *
- * @param info ModelMBeanInfo for this MBean
- *
- * @exception MBeanException if the initializer of an object
- * throws an exception
- * @exception RuntimeOperationsException if an IllegalArgumentException
- * occurs
- */
- public BaseModelMBean(ModelMBeanInfo info)
- throws MBeanException, RuntimeOperationsException {
- // XXX should be deprecated - just call setInfo
+ protected BaseModelMBean() throws MBeanException, RuntimeOperationsException {
super();
- setModelMBeanInfo(info);
- if( log.isDebugEnabled()) log.debug("ModelMBeanInfo constructor");
- }
-
- /** Construct a ModelMBean of a specified type.
- * The type can be a class name or the key used in one of the descriptors.
- *
- * If no descriptor is available, we'll first try to locate one in
- * the same package with the class, then use introspection.
- *
- * The mbean resource will be created.
- *
- * @param type Class name or the type key used in the descriptor.
- * @throws MBeanException
- * @throws RuntimeOperationsException
- */
- public BaseModelMBean( String type )
- throws MBeanException, RuntimeOperationsException
- {
- try {
- // This constructor is used from ModelMBeanInfo object that controls our activity.
+
+ /** Metadata for the mbean instance.
*/
- protected ModelMBeanInfo info = null;
-
+ protected ManagedBean managedBean = null;
/**
* The managed resource this MBean is associated with (if any).
*/
protected Object resource = null;
- protected String resourceType = null;
-
- /** Source object used to read this mbean. Can be used to
- * persist the mbean
- */
- protected ModelerSource source=null;
-
- /** Attribute values. XXX That can be stored in the value Field
- */
- protected HashMap attributes=new HashMap();
// --------------------------------------------------- DynamicMBean Methods
+ // TODO: move to ManagedBean
static final Object[] NO_ARGS_PARAM=new Object[0];
static final Class[] NO_ARGS_PARAM_SIG=new Class[0];
- // key: attribute val: getter method
- private Hashtable getAttMap=new Hashtable();
-
- // key: attribute val: setter method
- private Hashtable setAttMap=new Hashtable();
+
+ protected String resourceType = null;
// key: operation val: invoke method
- private Hashtable invokeAttMap=new Hashtable();
+ //private Hashtable invokeAttMap=new Hashtable();
/**
* Obtain and return the value of a specific attribute of this MBean.
@@ -249,45 +176,7 @@ public class BaseModelMBean implements ModelMBean, MBeanRegistration {
return ((DynamicMBean)resource).getAttribute(name);
}
- // Extract the method from cache
- Method m=(Method)getAttMap.get( name );
-
- if( m==null ) {
- // Look up the actual operation to be used
- ModelMBeanAttributeInfo attrInfo = info.getAttribute(name);
- if (attrInfo == null)
- throw new AttributeNotFoundException(" Cannot find attribute " + name);
- Descriptor attrDesc = attrInfo.getDescriptor();
- if (attrDesc == null)
- throw new AttributeNotFoundException("Cannot find attribute " + name + " descriptor");
- String getMethod = (String) attrDesc.getFieldValue("getMethod");
-
- if (getMethod == null)
- throw new AttributeNotFoundException("Cannot find attribute " + name + " get method name");
-
- Object object = null;
- NoSuchMethodException exception = null;
- try {
- object = this;
- m = object.getClass().getMethod(getMethod, NO_ARGS_PARAM_SIG);
- } catch (NoSuchMethodException e) {
- exception = e;;
- }
- if( m== null && resource != null ) {
- try {
- object = resource;
- m = object.getClass().getMethod(getMethod, NO_ARGS_PARAM_SIG);
- exception=null;
- } catch (NoSuchMethodException e) {
- exception = e;
- }
- }
- if( exception != null )
- throw new ReflectionException(exception,
- "Cannot find getter method " + getMethod);
- getAttMap.put( name, m );
- }
-
+ Method m=managedBean.getGetter(name, this, resource);
Object result = null;
try {
Class declaring=m.getDeclaringClass();
@@ -349,14 +238,15 @@ public class BaseModelMBean implements ModelMBean, MBeanRegistration {
}
+ public void setManagedBean(ManagedBean managedBean) {
+ this.managedBean = managedBean;
+ }
/**
* Return the MBeanInfo object for this MBean.
*/
public MBeanInfo getMBeanInfo() {
- // XXX Why do we have to clone ?
- if( info== null ) return null;
- return ((MBeanInfo) info.clone());
+ return managedBean.getMBeanInfo();
}
@@ -395,59 +285,8 @@ public class BaseModelMBean implements ModelMBean, MBeanRegistration {
if( log.isDebugEnabled()) log.debug("Invoke " + name);
MethodKey mkey = new MethodKey(name, signature);
- Method method=(Method)invokeAttMap.get(mkey);
- if( method==null ) {
- if (params == null)
- params = new Object[0];
- if (signature == null)
- signature = new String[0];
- if (params.length != signature.length)
- throw new RuntimeOperationsException
- (new IllegalArgumentException("Inconsistent arguments and signature"),
- "Inconsistent arguments and signature");
-
- // Acquire the ModelMBeanOperationInfo information for
- // the requested operation
- ModelMBeanOperationInfo opInfo = info.getOperation(name);
- if (opInfo == null)
- throw new MBeanException
- (new ServiceNotFoundException("Cannot find operation " + name),
- "Cannot find operation " + name);
-
- // Prepare the signature required by Java reflection APIs
- // FIXME - should we use the signature from opInfo?
- Class types[] = new Class[signature.length];
- for (int i = 0; i < signature.length; i++) {
- types[i]=getAttributeClass( signature[i] );
- }
-
- // Locate the method to be invoked, either in this MBean itself
- // or in the corresponding managed resource
- // FIXME - Accessible methods in superinterfaces?
- Object object = null;
- Exception exception = null;
- try {
- object = this;
- method = object.getClass().getMethod(name, types);
- } catch (NoSuchMethodException e) {
- exception = e;;
- }
- try {
- if ((method == null) && (resource != null)) {
- object = resource;
- method = object.getClass().getMethod(name, types);
- }
- } catch (NoSuchMethodException e) {
- exception = e;
- }
- if (method == null) {
- throw new ReflectionException(exception,
- "Cannot find method " + name +
- " with this signature");
- }
- invokeAttMap.put( mkey, method );
- }
-
+ Method method= managedBean.getInvoke(name, params, signature, this, resource);
+
// Invoke the selected method on the appropriate object
Object result = null;
try {
@@ -482,7 +321,7 @@ public class BaseModelMBean implements ModelMBean, MBeanRegistration {
}
- private Class getAttributeClass(String signature)
+ static Class getAttributeClass(String signature)
throws ReflectionException
{
if (signature.equals(Boolean.TYPE.getName()))
@@ -561,64 +400,17 @@ public class BaseModelMBean implements ModelMBean, MBeanRegistration {
(new IllegalArgumentException("Attribute name is null"),
"Attribute name is null");
- ModelMBeanAttributeInfo attrInfo=info.getAttribute(name);
- if (attrInfo == null)
- throw new AttributeNotFoundException("Cannot find attribute " + name);
-
- Descriptor attrDesc=attrInfo.getDescriptor();
- if (attrDesc == null)
- throw new AttributeNotFoundException("Cannot find attribute " + name + " descriptor");
-
Object oldValue=null;
- if( getAttMap.get(name) != null )
- oldValue=getAttribute( name );
-
-
- // Extract the method from cache
- Method m=(Method)setAttMap.get( name );
+ //if( getAttMap.get(name) != null )
+ // oldValue=getAttribute( name );
- if( m==null ) {
- // Look up the actual operation to be used
- String setMethod = (String) attrDesc.getFieldValue("setMethod");
- if (setMethod == null)
- throw new AttributeNotFoundException("Cannot find attribute " + name + " set method name");
+ Method m=managedBean.getSetter(name,this,resource);
- String argType=attrInfo.getType();
-
- Class signature[] = new Class[] { getAttributeClass( argType ) };
-
- Object object = null;
- NoSuchMethodException exception = null;
- try {
- object = this;
- m = object.getClass().getMethod(setMethod, signature);
- } catch (NoSuchMethodException e) {
- exception = e;;
- }
- if( m== null && resource != null ) {
- try {
- object = resource;
- m = object.getClass().getMethod(setMethod, signature);
- exception=null;
- } catch (NoSuchMethodException e) {
- if( log.isDebugEnabled())
- log.debug("Method not found in resource " +resource);
- exception = e;
- }
- }
- if( exception != null )
- throw new ReflectionException(exception,
- "Cannot find setter method " + setMethod +
- " " + resource);
- setAttMap.put( name, m );
- }
-
- Object result = null;
try {
if( m.getDeclaringClass().isAssignableFrom( this.getClass()) ) {
- result = m.invoke(this, new Object[] { value });
+ m.invoke(this, new Object[] { value });
} else {
- result = m.invoke(resource, new Object[] { value });
+ m.invoke(resource, new Object[] { value });
}
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
@@ -644,11 +436,11 @@ public class BaseModelMBean implements ModelMBean, MBeanRegistration {
} catch(Exception ex) {
log.error("Error sending notification " + name, ex);
}
- attributes.put( name, value );
- if( source != null ) {
- // this mbean is asscoiated with a source - maybe we want to persist
- source.updateField(oname, name, value);
- }
+ //attributes.put( name, value );
+// if( source != null ) {
+// // this mbean is asscoiated with a source - maybe we want to persist
+// source.updateField(oname, name, value);
+// }
}
public String toString() {
@@ -665,15 +457,13 @@ public class BaseModelMBean implements ModelMBean, MBeanRegistration {
* @return The list of attributes that were set and their new values
*/
public AttributeList setAttributes(AttributeList attributes) {
+ AttributeList response = new AttributeList();
// Validate the input parameters
if (attributes == null)
- throw new RuntimeOperationsException
- (new IllegalArgumentException("Attributes list is null"),
- "Attributes list is null");
-
+ return response;
+
// Prepare and return our response, eating all exceptions
- AttributeList response = new AttributeList();
String names[] = new String[attributes.size()];
int n = 0;
Iterator items = attributes.iterator();
@@ -724,10 +514,12 @@ public class BaseModelMBean implements ModelMBean, MBeanRegistration {
* Set the instance handle of the object against which we will execute
* all methods in this ModelMBean management interface.
*
- * This method will detect and call "setModelMbean" method. A resource
+ * null or invalid
*/
public void setManagedResource(Object resource, String type)
- throws InstanceNotFoundException, InvalidTargetObjectTypeException,
+ throws InstanceNotFoundException,
MBeanException, RuntimeOperationsException
{
if (resource == null)
@@ -752,58 +544,24 @@ public class BaseModelMBean implements ModelMBean, MBeanRegistration {
(new IllegalArgumentException("Managed resource is null"),
"Managed resource is null");
- if (!"objectreference".equalsIgnoreCase(type))
- throw new InvalidTargetObjectTypeException(type);
+// if (!"objectreference".equalsIgnoreCase(type))
+// throw new InvalidTargetObjectTypeException(type);
this.resource = resource;
this.resourceType = resource.getClass().getName();
- // Make the resource aware of the model mbean.
- try {
- Method m=resource.getClass().getMethod("setModelMBean",
- new Class[] {ModelMBean.class});
- if( m!= null ) {
- m.invoke(resource, new Object[] {this});
- }
- } catch( NoSuchMethodException t ) {
- // ignore
- } catch( Throwable t ) {
- log.error( "Can't set model mbean ", t );
- }
- }
-
-
- /**
- * Initialize the ModelMBeanInfo associated with this
- * ModelMBean. After the information and associated
- * descriptors have been customized, the ModelMBean should
- * be registered with the associated MBeanServer.
- *
- * Currently the model can be set after registration. This behavior is
- * deprecated and won't be supported in future versions.
- *
- * @param info The ModelMBeanInfo object to be used by this ModelMBean
- *
- * @exception MBeanException If an exception occurs recording this
- * ModelMBeanInfo information
- * @exception RuntimeOperations if the specified parameter is
- * null or invalid
- */
- public void setModelMBeanInfo(ModelMBeanInfo info)
- throws MBeanException, RuntimeOperationsException {
-
- if (info == null)
- throw new RuntimeOperationsException
- (new IllegalArgumentException("ModelMBeanInfo is null"),
- "ModelMBeanInfo is null");
-
- if (!isModelMBeanInfoValid(info))
- throw new RuntimeOperationsException
- (new IllegalArgumentException("ModelMBeanInfo is invalid"),
- "ModelMBeanInfo is invalid");
-
- this.info = (ModelMBeanInfo) info.clone();
-
+// // Make the resource aware of the model mbean.
+// try {
+// Method m=resource.getClass().getMethod("setModelMBean",
+// new Class[] {ModelMBean.class});
+// if( m!= null ) {
+// m.invoke(resource, new Object[] {this});
+// }
+// } catch( NoSuchMethodException t ) {
+// // ignore
+// } catch( Throwable t ) {
+// log.error( "Can't set model mbean ", t );
+// }
}
@@ -1058,38 +816,38 @@ public class BaseModelMBean implements ModelMBean, MBeanRegistration {
public MBeanNotificationInfo[] getNotificationInfo() {
// Acquire the set of application notifications
- MBeanNotificationInfo current[] = info.getNotifications();
+ MBeanNotificationInfo current[] = getMBeanInfo().getNotifications();
if (current == null)
current = new MBeanNotificationInfo[0];
MBeanNotificationInfo response[] =
new MBeanNotificationInfo[current.length + 2];
- Descriptor descriptor = null;
+ // Descriptor descriptor = null;
// Fill in entry for general notifications
- descriptor = new DescriptorSupport
- (new String[] { "name=GENERIC",
- "descriptorType=notification",
- "log=T",
- "severity=5",
- "displayName=jmx.modelmbean.generic" });
- response[0] = new ModelMBeanNotificationInfo
+// descriptor = new DescriptorSupport
+// (new String[] { "name=GENERIC",
+// "descriptorType=notification",
+// "log=T",
+// "severity=5",
+// "displayName=jmx.modelmbean.generic" });
+ response[0] = new MBeanNotificationInfo
(new String[] { "jmx.modelmbean.generic" },
"GENERIC",
- "Text message notification from the managed resource",
- descriptor);
+ "Text message notification from the managed resource");
+ //descriptor);
// Fill in entry for attribute change notifications
- descriptor = new DescriptorSupport
- (new String[] { "name=ATTRIBUTE_CHANGE",
- "descriptorType=notification",
- "log=T",
- "severity=5",
- "displayName=jmx.attribute.change" });
- response[1] = new ModelMBeanNotificationInfo
+// descriptor = new DescriptorSupport
+// (new String[] { "name=ATTRIBUTE_CHANGE",
+// "descriptorType=notification",
+// "log=T",
+// "severity=5",
+// "displayName=jmx.attribute.change" });
+ response[1] = new MBeanNotificationInfo
(new String[] { "jmx.attribute.change" },
"ATTRIBUTE_CHANGE",
- "Observed MBean attribute value has changed",
- descriptor);
+ "Observed MBean attribute value has changed");
+ //descriptor);
// Copy remaining notifications as reported by the application
System.arraycopy(current, 0, response, 2, current.length);
@@ -1183,14 +941,14 @@ public class BaseModelMBean implements ModelMBean, MBeanRegistration {
* @exception RuntimeOperationsException if an exception is reported
* by the persistence mechanism
*/
- public void load() throws InstanceNotFoundException,
- MBeanException, RuntimeOperationsException {
- // XXX If a context was set, use it to load the data
- throw new MBeanException
- (new IllegalStateException("Persistence is not supported"),
- "Persistence is not supported");
-
- }
+// public void load() throws InstanceNotFoundException,
+// MBeanException, RuntimeOperationsException {
+// // XXX If a context was set, use it to load the data
+// throw new MBeanException
+// (new IllegalStateException("Persistence is not supported"),
+// "Persistence is not supported");
+//
+// }
/**
@@ -1209,15 +967,15 @@ public class BaseModelMBean implements ModelMBean, MBeanRegistration {
* @exception RuntimeOperationsException if an exception is reported
* by the persistence mechanism
*/
- public void store() throws InstanceNotFoundException,
- MBeanException, RuntimeOperationsException {
-
- // XXX if a context was set, use it to store the data
- throw new MBeanException
- (new IllegalStateException("Persistence is not supported"),
- "Persistence is not supported");
-
- }
+// public void store() throws InstanceNotFoundException,
+// MBeanException, RuntimeOperationsException {
+//
+// // XXX if a context was set, use it to store the data
+// throw new MBeanException
+// (new IllegalStateException("Persistence is not supported"),
+// "Persistence is not supported");
+//
+// }
// -------------------- BaseModelMBean methods --------------------
@@ -1226,62 +984,62 @@ public class BaseModelMBean implements ModelMBean, MBeanRegistration {
*
* @param type the type of classname of the modeled object
*/
- public void setModeledType( String type ) {
- initModelInfo(type);
- createResource();
- }
+// void setModeledType( String type ) {
+// initModelInfo(type);
+// createResource();
+// }
/** Set the type of the mbean. This is used as a key to locate
* the description in the Registry.
*
* @param type the type of classname of the modeled object
*/
- protected void initModelInfo( String type ) {
- try {
- if( log.isDebugEnabled())
- log.debug("setModeledType " + type);
-
- log.debug( "Set model Info " + type);
- if(type==null) {
- return;
- }
- resourceType=type;
- //Thread.currentThread().setContextClassLoader(BaseModelMBean.class.getClassLoader());
- Class c=null;
- try {
- c=Class.forName( type);
- } catch( Throwable t ) {
- log.debug( "Error creating class " + t);
- }
-
- // The class c doesn't need to exist
- ManagedBean descriptor=getRegistry().findManagedBean(c, type);
- if( descriptor==null )
- return;
- this.setModelMBeanInfo(descriptor.createMBeanInfo());
- } catch( Throwable ex) {
- log.error( "TCL: " + Thread.currentThread().getContextClassLoader(),
- ex);
- }
- }
+// void initModelInfo( String type ) {
+// try {
+// if( log.isDebugEnabled())
+// log.debug("setModeledType " + type);
+//
+// log.debug( "Set model Info " + type);
+// if(type==null) {
+// return;
+// }
+// resourceType=type;
+// //Thread.currentThread().setContextClassLoader(BaseModelMBean.class.getClassLoader());
+// Class c=null;
+// try {
+// c=Class.forName( type);
+// } catch( Throwable t ) {
+// log.debug( "Error creating class " + t);
+// }
+//
+// // The class c doesn't need to exist
+// ManagedBean descriptor=getRegistry().findManagedBean(c, type);
+// if( descriptor==null )
+// return;
+// this.setModelMBeanInfo(descriptor.createMBeanInfo());
+// } catch( Throwable ex) {
+// log.error( "TCL: " + Thread.currentThread().getContextClassLoader(),
+// ex);
+// }
+// }
/** Set the type of the mbean. This is used as a key to locate
* the description in the Registry.
*/
- protected void createResource() {
- try {
- //Thread.currentThread().setContextClassLoader(BaseModelMBean.class.getClassLoader());
- Class c=null;
- try {
- c=Class.forName( resourceType );
- resource = c.newInstance();
- } catch( Throwable t ) {
- log.error( "Error creating class " + t);
- }
- } catch( Throwable ex) {
- log.error( "TCL: " + Thread.currentThread().getContextClassLoader(),
- ex);
- }
- }
+// protected void createResource() {
+// try {
+// //Thread.currentThread().setContextClassLoader(BaseModelMBean.class.getClassLoader());
+// Class c=null;
+// try {
+// c=Class.forName( resourceType );
+// resource = c.newInstance();
+// } catch( Throwable t ) {
+// log.error( "Error creating class " + t);
+// }
+// } catch( Throwable ex) {
+// log.error( "TCL: " + Thread.currentThread().getContextClassLoader(),
+// ex);
+// }
+// }
public String getModelerType() {
@@ -1304,17 +1062,17 @@ public class BaseModelMBean implements ModelMBean, MBeanRegistration {
}
}
- public void setRegistry(Registry registry) {
- this.registry = registry;
- }
-
- public Registry getRegistry() {
- // XXX Need a better solution - to avoid the static
- if( registry == null )
- registry=Registry.getRegistry();
-
- return registry;
- }
+// public void setRegistry(Registry registry) {
+// this.registry = registry;
+// }
+//
+// public Registry getRegistry() {
+// // XXX Need a better solution - to avoid the static
+// if( registry == null )
+// registry=Registry.getRegistry();
+//
+// return registry;
+// }
// ------------------------------------------------------ Protected Methods
@@ -1322,13 +1080,13 @@ public class BaseModelMBean implements ModelMBean, MBeanRegistration {
/**
* Create and return a default ModelMBeanInfo object.
*/
- protected ModelMBeanInfo createDefaultModelMBeanInfo() {
-
- return (new ModelMBeanInfoSupport(this.getClass().getName(),
- "Default ModelMBean",
- null, null, null, null));
-
- }
+// protected ModelMBeanInfo createDefaultModelMBeanInfo() {
+//
+// return (new ModelMBeanInfoSupport(this.getClass().getName(),
+// "Default ModelMBean",
+// null, null, null, null));
+//
+// }
/**
* Is the specified ModelMBeanInfo instance valid?
@@ -1339,9 +1097,9 @@ public class BaseModelMBean implements ModelMBean, MBeanRegistration {
*
* @param info The ModelMBeanInfo object to check
*/
- protected boolean isModelMBeanInfoValid(ModelMBeanInfo info) {
- return (true);
- }
+// protected boolean isModelMBeanInfoValid(ModelMBeanInfo info) {
+// return (true);
+// }
// -------------------- Registration --------------------
// XXX We can add some method patterns here- like setName() and
diff --git a/java/org/apache/tomcat/util/modeler/BaseNotification.java b/java/org/apache/tomcat/util/modeler/BaseNotification.java
deleted file mode 100644
index d6a5e2715..000000000
--- a/java/org/apache/tomcat/util/modeler/BaseNotification.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright 1999,2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tomcat.util.modeler;
-
-import javax.management.Notification;
-
-
-/**
- * Base JMX Notification. Supports in int code and notes - for faster
- * access and dispatching.
- *
- * @author Costin Manolache
- */
-public final class BaseNotification extends Notification {
-
- // ----------------------------------------------------------- Constructors
- private int code;
- private String type;
- private Object source;
- private long seq;
- private long tstamp;
-
- /**
- * Private constructor.
- */
- private BaseNotification(String type,
- Object source,
- long seq,
- long tstamp,
- int code) {
- super(type, source, seq, tstamp);
- init( type, source, seq, tstamp, code );
- this.code=code;
- }
-
- public void recycle() {
-
- }
-
- public void init( String type, Object source,
- long seq, long tstamp, int code )
- {
- this.type=type;
- this.source = source;
- this.seq=seq;
- this.tstamp=tstamp;
- this.code = code;
- }
-
- // -------------------- Override base methods --------------------
- // All base methods need to be overriden - in order to support recycling.
-
-
- // -------------------- Information associated with the notification ----
- // Like events ( which Notification extends ), notifications may store
- // informations related with the event that trigered it. Source and type is
- // one piece, but it is common to store more info.
-
- /** Action id, useable in switches and table indexes
- */
- public int getCode() {
- return code;
- }
-
- // XXX Make it customizable - or grow it
- private Object notes[]=new Object[32];
-
- public final Object getNote(int i ) {
- return notes[i];
- }
-
- public final void setNote(int i, Object o ) {
- notes[i]=o;
- }
-}
diff --git a/java/org/apache/tomcat/util/modeler/ConstructorInfo.java b/java/org/apache/tomcat/util/modeler/ConstructorInfo.java
index 13d0104a1..d3af7b4fc 100644
--- a/java/org/apache/tomcat/util/modeler/ConstructorInfo.java
+++ b/java/org/apache/tomcat/util/modeler/ConstructorInfo.java
@@ -20,9 +20,7 @@ package org.apache.tomcat.util.modeler;
import java.io.Serializable;
-import javax.management.Descriptor;
-import javax.management.MBeanParameterInfo;
-import javax.management.modelmbean.ModelMBeanConstructorInfo;
+import javax.management.MBeanConstructorInfo;
/**
@@ -30,135 +28,28 @@ import javax.management.modelmbean.ModelMBeanConstructorInfo;
* descriptor.
*
* @author Craig R. McClanahan
- * @version $Revision: 155428 $ $Date: 2005-02-26 14:12:25 +0100 (sam., 26 févr. 2005) $
*/
-
-public class ConstructorInfo extends FeatureInfo implements Serializable {
+public class ConstructorInfo extends OperationInfo implements Serializable {
static final long serialVersionUID = -5735336213417238238L;
-
- // ----------------------------------------------------- Instance Variables
-
-
- /**
- * The ModelMBeanConstructorInfo object that corresponds
- * to this ConstructorInfo instance.
- */
- transient ModelMBeanConstructorInfo info = null;
- protected String displayName = null;
- protected ParameterInfo parameters[] = new ParameterInfo[0];
-
-
// ------------------------------------------------------------- Properties
-
- /**
- * Override the description property setter.
- *
- * @param description The new description
- */
- public void setDescription(String description) {
- super.setDescription(description);
- this.info = null;
+ public ConstructorInfo() {
}
-
- /**
- * Override the name property setter.
- *
- * @param name The new name
- */
- public void setName(String name) {
- super.setName(name);
- this.info = null;
- }
-
-
- /**
- * The display name of this attribute.
- */
- public String getDisplayName() {
- return (this.displayName);
- }
-
- public void setDisplayName(String displayName) {
- this.displayName = displayName;
- }
-
-
- /**
- * The set of parameters for this constructor.
- */
- public ParameterInfo[] getSignature() {
- return (this.parameters);
- }
-
-
// --------------------------------------------------------- Public Methods
/**
- * Add a new parameter to the set of parameters for this constructor.
- *
- * @param parameter The new parameter descriptor
- */
- public void addParameter(ParameterInfo parameter) {
-
- synchronized (parameters) {
- ParameterInfo results[] = new ParameterInfo[parameters.length + 1];
- System.arraycopy(parameters, 0, results, 0, parameters.length);
- results[parameters.length] = parameter;
- parameters = results;
- this.info = null;
- }
-
- }
-
-
- /**
* Create and return a ModelMBeanConstructorInfo object that
* corresponds to the attribute described by this instance.
*/
- public ModelMBeanConstructorInfo createConstructorInfo() {
-
+ public MBeanConstructorInfo createConstructorInfo() {
// Return our cached information (if any)
- if (info != null)
- return (info);
-
- // Create and return a new information object
- ParameterInfo params[] = getSignature();
- MBeanParameterInfo parameters[] =
- new MBeanParameterInfo[params.length];
- for (int i = 0; i < params.length; i++)
- parameters[i] = params[i].createParameterInfo();
- info = new ModelMBeanConstructorInfo
- (getName(), getDescription(), parameters);
- Descriptor descriptor = info.getDescriptor();
- descriptor.removeField("class");
- if (getDisplayName() != null)
- descriptor.setField("displayName", getDisplayName());
- addFields(descriptor);
- info.setDescriptor(descriptor);
- return (info);
-
- }
-
-
- /**
- * Return a string representation of this constructor descriptor.
- */
- public String toString() {
-
- StringBuffer sb = new StringBuffer("ConstructorInfo[");
- sb.append("name=");
- sb.append(name);
- sb.append(", description=");
- sb.append(description);
- sb.append(", parameters=");
- sb.append(parameters.length);
- sb.append("]");
- return (sb.toString());
-
+ if (info == null) {
+ info = new MBeanConstructorInfo(getName(), getDescription(),
+ getMBeanParameterInfo());
+ }
+ return (MBeanConstructorInfo)info;
}
-
}
diff --git a/java/org/apache/tomcat/util/modeler/FeatureInfo.java b/java/org/apache/tomcat/util/modeler/FeatureInfo.java
index c23d96c7d..75e149c3b 100644
--- a/java/org/apache/tomcat/util/modeler/FeatureInfo.java
+++ b/java/org/apache/tomcat/util/modeler/FeatureInfo.java
@@ -19,11 +19,8 @@ package org.apache.tomcat.util.modeler;
import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import javax.management.Descriptor;
+import javax.management.MBeanFeatureInfo;
/**
@@ -38,13 +35,17 @@ import javax.management.Descriptor;
public class FeatureInfo implements Serializable {
static final long serialVersionUID = -911529176124712296L;
+
protected String description = null;
- protected List fields = new ArrayList();
protected String name = null;
+ protected MBeanFeatureInfo info = null;
+
+ // all have type except Constructor
+ protected String type = null;
+
// ------------------------------------------------------------- Properties
-
/**
* The human-readable description of this feature.
*/
@@ -58,14 +59,6 @@ public class FeatureInfo implements Serializable {
/**
- * The field information for this feature.
- */
- public List getFields() {
- return (fields);
- }
-
-
- /**
* The name of this feature, which must be unique among features in the
* same collection.
*/
@@ -77,38 +70,15 @@ public class FeatureInfo implements Serializable {
this.name = name;
}
-
- // --------------------------------------------------------- Public Methods
-
-
/**
- * Add a new field to the fields associated with the
- * Descriptor that will be created from this metadata.
- *
- * @param field The field to be added
+ * The fully qualified Java class name of this element.
*/
- public void addField(FieldInfo field) {
- fields.add(field);
+ public String getType() {
+ return (this.type);
}
-
- // ------------------------------------------------------ Protected Methods
-
-
- /**
- * Add the name/value fields that have been stored into the
- * specified Descriptor instance.
- *
- * @param descriptor The Descriptor to add fields to
- */
- protected void addFields(Descriptor descriptor) {
-
- Iterator items = getFields().iterator();
- while (items.hasNext()) {
- FieldInfo item = (FieldInfo) items.next();
- descriptor.setField(item.getName(), item.getValue());
- }
-
+ public void setType(String type) {
+ this.type = type;
}
diff --git a/java/org/apache/tomcat/util/modeler/FieldInfo.java b/java/org/apache/tomcat/util/modeler/FieldInfo.java
deleted file mode 100644
index ddc6a3c82..000000000
--- a/java/org/apache/tomcat/util/modeler/FieldInfo.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 1999-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.apache.tomcat.util.modeler;
-
-
-import java.io.Serializable;
-
-
-/**
- * Simple JavaBean representing the contents of a <field>
- * element in an MBeans descriptor file.
- */
-
-public class FieldInfo implements Serializable {
- static final long serialVersionUID = -8226401620640873691L;
-
- /**
- *
The field name for this field of a descriptor.
- */
- protected String name = null;
-
- public String getName() {
- return (this.name);
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
-
- /**
- * The field value for this field of a descriptor.
- */
- protected Object value = null;
-
- public Object getValue() {
- return (this.value);
- }
-
- public void setValue(Object value) {
- this.value = value;
- }
-
-
-}
diff --git a/java/org/apache/tomcat/util/modeler/JndiJmx.java b/java/org/apache/tomcat/util/modeler/JndiJmx.java
deleted file mode 100644
index 988b5e14d..000000000
--- a/java/org/apache/tomcat/util/modeler/JndiJmx.java
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Copyright 2001-2002,2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.apache.tomcat.util.modeler;
-
-
-import java.util.Enumeration;
-import java.util.Hashtable;
-
-import javax.management.AttributeChangeNotification;
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanException;
-import javax.management.MBeanServer;
-import javax.management.MBeanServerNotification;
-import javax.management.Notification;
-import javax.management.NotificationBroadcaster;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
-import javax.naming.Context;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-// EXPERIMENTAL. It may fit better in tomcat jndi impl.
-
-
-/**
- *
- * Link between JNDI and JMX. JNDI can be used for persistence ( it is
- * an API for storing hierarchical data and a perfect fit for that ), as
- * well as an alternate view of the MBean registry.
- *
- * If this component is enabled, all MBeans will be registered in JNDI, and
- * all attributes that are set via JMX can be stored in a DirContext.
- *
- * This acts as a "recorder" for creation of mbeans and attribute changes
- * done via JMX.
- *
- * XXX How can we control ( filter ) which mbeans will be registere ? Or
- * attributes ?
- * XXX How can we get the beans and attributes loaded before jndijmx ?
- *
- * The intended use:
- * - do whatever you want to start the application
- * - load JndiJmx as an mbean
- * - make changes via JMX. All changes are recorded
- * - you can use JndiJmx to save the changes in a Jndi context.
- * - you can use JndiJmx to load changes from a JndiContext and replay them.
- *
- * The main benefit is that only changed attributes are saved, and the Jndi
- * layer can preserve most of the original structure of the config file. The
- * alternative is to override the config files with config info extracted
- * from the live objects - but it's very hard to save only what was actually
- * changed and preserve structure and comments.
- *
- * @author Costin Manolache
- */
-public class JndiJmx extends BaseModelMBean implements NotificationListener {
-
-
- private static Log log= LogFactory.getLog(JndiJmx.class);
-
- protected Context componentContext;
- protected Context descriptorContext;
- protected Context configContext;
-
- MBeanServer mserver;
-
- /**
- * Protected constructor to require use of the factory create method.
- */
- public JndiJmx() throws MBeanException {
- super(JndiJmx.class.getName());
- }
-
-
- /** If a JNDI context is set, all components
- * will be registered in the context.
- *
- * @param ctx
- */
- public void setComponentContext(Context ctx) {
- this.componentContext= ctx;
- }
-
- /** JNDI context for component descriptors ( metadata ).
- *
- * @param ctx
- */
- public void setDescriptorContext(Context ctx) {
- this.descriptorContext= ctx;
- }
-
- /** JNDI context where attributes will be stored for persistence
- *
- */
- public void setConfigContext( Context ctx ) {
- this.configContext= ctx;
- }
-
- // -------------------- Registration/unregistration --------------------
- // temp - will only set in the jndi contexts
- Hashtable attributes=new Hashtable();
- Hashtable instances=new Hashtable();
-
- public void handleNotification(Notification notification, Object handback)
- {
- // register/unregister mbeans in jndi
- if( notification instanceof MBeanServerNotification ) {
- MBeanServerNotification msnot=(MBeanServerNotification)notification;
-
- ObjectName oname=msnot.getMBeanName();
-
- if( "jmx.mbean.created".equalsIgnoreCase( notification.getType() )) {
- try {
- Object mbean=mserver.getObjectInstance(oname);
-
- if( log.isDebugEnabled() )
- log.debug( "MBean created " + oname + " " + mbean);
-
- // XXX add filter support
- if( mbean instanceof NotificationBroadcaster ) {
- // register for attribute changes
- NotificationBroadcaster nb=(NotificationBroadcaster)mbean;
- nb.addNotificationListener(this, null, null);
- if( log.isDebugEnabled() )
- log.debug( "Add attribute change listener");
- }
-
- instances.put( oname.toString(), mbean );
- } catch( InstanceNotFoundException ex ) {
- log.error( "Instance not found for the created object", ex );
- }
- }
- if( "jmx.mbean.deleted".equalsIgnoreCase( notification.getType() )) {
- instances.remove(oname.toString());
- }
- }
-
- // set attributes in jndi
- // if( "jmx.attribute.changed".equals( notification.getType() )) {
- if( notification instanceof AttributeChangeNotification) {
-
- AttributeChangeNotification anotif=(AttributeChangeNotification)notification;
- String name=anotif.getAttributeName();
- Object value=anotif.getNewValue();
- Object source=anotif.getSource();
- String mname=null;
-
- Hashtable mbeanAtt=(Hashtable)attributes.get( source );
- if( mbeanAtt==null ) {
- mbeanAtt=new Hashtable();
- attributes.put( source, mbeanAtt);
- if( log.isDebugEnabled())
- log.debug("First attribute for " + source );
- }
- mbeanAtt.put( name, anotif );
-
- log.debug( "Attribute change notification " + name + " " + value + " " + source );
-
- }
-
- }
-
- public String dumpStatus() throws Exception
- {
- StringBuffer sb=new StringBuffer();
- Enumeration en=instances.keys();
- while (en.hasMoreElements()) {
- String on = (String) en.nextElement();
- Object mbean=instances.get(on);
- Hashtable mbeanAtt=(Hashtable)attributes.get(mbean);
-
- sb.append( "");
- sb.append( "\n");
- Enumeration attEn=mbeanAtt.keys();
- while (attEn.hasMoreElements()) {
- String an = (String) attEn.nextElement();
- AttributeChangeNotification anotif=
- (AttributeChangeNotification)mbeanAtt.get(an);
- sb.append(" ");
- sb.append( "\n");
- }
-
-
- sb.append( " ");
- sb.append( "\n");
- }
- return sb.toString();
- }
-
- public void replay() throws Exception
- {
-
-
- }
-
-
- public void init() throws Exception
- {
-
- MBeanServer mserver=(MBeanServer)Registry.getRegistry().getMBeanServer();
- ObjectName delegate=new ObjectName("JMImplementation:type=MBeanServerDelegate");
-
- // XXX need to extract info about previously loaded beans
-
- // we'll know of all registered beans
- mserver.addNotificationListener(delegate, this, null, null );
-
- }
-
-}
diff --git a/java/org/apache/tomcat/util/modeler/ManagedBean.java b/java/org/apache/tomcat/util/modeler/ManagedBean.java
index a2c39a74d..14704469f 100644
--- a/java/org/apache/tomcat/util/modeler/ManagedBean.java
+++ b/java/org/apache/tomcat/util/modeler/ManagedBean.java
@@ -18,22 +18,23 @@
package org.apache.tomcat.util.modeler;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
-import javax.management.Descriptor;
+import javax.management.AttributeNotFoundException;
+import javax.management.DynamicMBean;
import javax.management.InstanceNotFoundException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.ReflectionException;
import javax.management.RuntimeOperationsException;
-import javax.management.modelmbean.InvalidTargetObjectTypeException;
-import javax.management.modelmbean.ModelMBean;
-import javax.management.modelmbean.ModelMBeanAttributeInfo;
-import javax.management.modelmbean.ModelMBeanConstructorInfo;
-import javax.management.modelmbean.ModelMBeanInfo;
-import javax.management.modelmbean.ModelMBeanInfoSupport;
-import javax.management.modelmbean.ModelMBeanNotificationInfo;
-import javax.management.modelmbean.ModelMBeanOperationInfo;
+import javax.management.ServiceNotFoundException;
+//import javax.management.modelmbean.InvalidTargetObjectTypeException;
/**
@@ -46,26 +47,31 @@ import javax.management.modelmbean.ModelMBeanOperationInfo;
public class ManagedBean implements java.io.Serializable
{
+ private static final String BASE_MBEAN = "org.apache.tomcat.util.modeler.BaseModelMBean";
// ----------------------------------------------------- Instance Variables
+ static final Object[] NO_ARGS_PARAM=new Object[0];
+ static final Class[] NO_ARGS_PARAM_SIG=new Class[0];
/**
* The ModelMBeanInfo object that corresponds
* to this ManagedBean instance.
*/
- transient ModelMBeanInfo info = null;
- protected AttributeInfo attributes[] = new AttributeInfo[0];
- protected String className =
- "org.apache.tomcat.util.modeler.BaseModelMBean";
- protected ConstructorInfo constructors[] = new ConstructorInfo[0];
+ transient MBeanInfo info = null;
+ // Map
+ private Map attributes = new HashMap();
+ //Map
+ private Map operations = new HashMap();
+
+ protected String className = BASE_MBEAN;
+ //protected ConstructorInfo constructors[] = new ConstructorInfo[0];
protected String description = null;
protected String domain = null;
protected String group = null;
protected String name = null;
- protected List fields = new ArrayList();
+ //protected List fields = new ArrayList();
protected NotificationInfo notifications[] = new NotificationInfo[0];
- protected OperationInfo operations[] = new OperationInfo[0];
protected String type = null;
/** Constructor. Will add default attributes.
@@ -87,7 +93,9 @@ public class ManagedBean implements java.io.Serializable
* The collection of attributes for this MBean.
*/
public AttributeInfo[] getAttributes() {
- return (this.attributes);
+ AttributeInfo result[] = new AttributeInfo[attributes.size()];
+ attributes.values().toArray(result);
+ return result;
}
@@ -107,12 +115,12 @@ public class ManagedBean implements java.io.Serializable
}
- /**
- * The collection of constructors for this MBean.
- */
- public ConstructorInfo[] getConstructors() {
- return (this.constructors);
- }
+// /**
+// * The collection of constructors for this MBean.
+// */
+// public ConstructorInfo[] getConstructors() {
+// return (this.constructors);
+// }
/**
@@ -146,10 +154,10 @@ public class ManagedBean implements java.io.Serializable
* the name/value pairs that should be
* added to the Descriptor created from this metadata.
*/
- public List getFields() {
- return (this.fields);
- }
-
+// public List getFields() {
+// return (this.fields);
+// }
+//
/**
* The (optional) group to which this MBean belongs.
@@ -189,7 +197,9 @@ public class ManagedBean implements java.io.Serializable
* The collection of operations for this MBean.
*/
public OperationInfo[] getOperations() {
- return (this.operations);
+ OperationInfo[] result = new OperationInfo[operations.size()];
+ operations.values().toArray(result);
+ return result;
}
@@ -217,16 +227,7 @@ public class ManagedBean implements java.io.Serializable
* @param attribute The new attribute descriptor
*/
public void addAttribute(AttributeInfo attribute) {
-
- synchronized (attributes) {
- AttributeInfo results[] =
- new AttributeInfo[attributes.length + 1];
- System.arraycopy(attributes, 0, results, 0, attributes.length);
- results[attributes.length] = attribute;
- attributes = results;
- this.info = null;
- }
-
+ attributes.put(attribute.getName(), attribute);
}
@@ -235,18 +236,18 @@ public class ManagedBean implements java.io.Serializable
*
* @param constructor The new constructor descriptor
*/
- public void addConstructor(ConstructorInfo constructor) {
-
- synchronized (constructors) {
- ConstructorInfo results[] =
- new ConstructorInfo[constructors.length + 1];
- System.arraycopy(constructors, 0, results, 0, constructors.length);
- results[constructors.length] = constructor;
- constructors = results;
- this.info = null;
- }
-
- }
+// public void addConstructor(ConstructorInfo constructor) {
+//
+// synchronized (constructors) {
+// ConstructorInfo results[] =
+// new ConstructorInfo[constructors.length + 1];
+// System.arraycopy(constructors, 0, results, 0, constructors.length);
+// results[constructors.length] = constructor;
+// constructors = results;
+// this.info = null;
+// }
+//
+// }
/**
@@ -255,9 +256,9 @@ public class ManagedBean implements java.io.Serializable
*
* @param field The field to be added
*/
- public void addField(FieldInfo field) {
- fields.add(field);
- }
+// public void addField(FieldInfo field) {
+// fields.add(field);
+// }
/**
@@ -286,15 +287,7 @@ public class ManagedBean implements java.io.Serializable
* @param operation The new operation descriptor
*/
public void addOperation(OperationInfo operation) {
- synchronized (operations) {
- OperationInfo results[] =
- new OperationInfo[operations.length + 1];
- System.arraycopy(operations, 0, results, 0, operations.length);
- results[operations.length] = operation;
- operations = results;
- this.info = null;
- }
-
+ operations.put(operation.getName(), operation);
}
@@ -314,9 +307,8 @@ public class ManagedBean implements java.io.Serializable
* ModelMBean instance
* @exception RuntimeOperationsException if a JMX runtime error occurs
*/
- public ModelMBean createMBean()
+ public DynamicMBean createMBean()
throws InstanceNotFoundException,
- InvalidTargetObjectTypeException,
MBeanException, RuntimeOperationsException {
return (createMBean(null));
@@ -343,57 +335,58 @@ public class ManagedBean implements java.io.Serializable
* ModelMBean instance
* @exception RuntimeOperationsException if a JMX runtime error occurs
*/
- public ModelMBean createMBean(Object instance)
+ public DynamicMBean createMBean(Object instance)
throws InstanceNotFoundException,
- InvalidTargetObjectTypeException,
MBeanException, RuntimeOperationsException {
+ BaseModelMBean mbean = null;
+
// Load the ModelMBean implementation class
- Class clazz = null;
- Exception ex = null;
- try {
- clazz = Class.forName(getClassName());
- } catch (Exception e) {
- }
-
- if( clazz==null ) {
+ if(getClassName().equals(BASE_MBEAN)) {
+ // Skip introspection
+ mbean = new BaseModelMBean();
+ } else {
+ Class clazz = null;
+ Exception ex = null;
try {
- ClassLoader cl= Thread.currentThread().getContextClassLoader();
- if ( cl != null)
- clazz= cl.loadClass(getClassName());
+ clazz = Class.forName(getClassName());
} catch (Exception e) {
- ex=e;
+ }
+
+ if( clazz==null ) {
+ try {
+ ClassLoader cl= Thread.currentThread().getContextClassLoader();
+ if ( cl != null)
+ clazz= cl.loadClass(getClassName());
+ } catch (Exception e) {
+ ex=e;
+ }
+ }
+
+ if( clazz==null) {
+ throw new MBeanException
+ (ex, "Cannot load ModelMBean class " + getClassName());
+ }
+ try {
+ // Stupid - this will set the default minfo first....
+ mbean = (BaseModelMBean) clazz.newInstance();
+ } catch (RuntimeOperationsException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new MBeanException
+ (e, "Cannot instantiate ModelMBean of class " +
+ getClassName());
}
}
-
- if( clazz==null) {
- throw new MBeanException
- (ex, "Cannot load ModelMBean class " + getClassName());
- }
-
- // Create a new ModelMBean instance
- ModelMBean mbean = null;
- try {
- mbean = (ModelMBean) clazz.newInstance();
- mbean.setModelMBeanInfo(createMBeanInfo());
- } catch (MBeanException e) {
- throw e;
- } catch (RuntimeOperationsException e) {
- throw e;
- } catch (Exception e) {
- throw new MBeanException
- (e, "Cannot instantiate ModelMBean of class " +
- getClassName());
- }
-
+
+ mbean.setManagedBean(this);
+
// Set the managed resource (if any)
try {
if (instance != null)
mbean.setManagedResource(instance, "ObjectReference");
} catch (InstanceNotFoundException e) {
throw e;
- } catch (InvalidTargetObjectTypeException e) {
- throw e;
}
return (mbean);
@@ -404,7 +397,7 @@ public class ManagedBean implements java.io.Serializable
* Create and return a ModelMBeanInfo object that
* describes this entire managed bean.
*/
- public ModelMBeanInfo createMBeanInfo() {
+ MBeanInfo getMBeanInfo() {
// Return our cached information (if any)
if (info != null)
@@ -412,69 +405,49 @@ public class ManagedBean implements java.io.Serializable
// Create subordinate information descriptors as required
AttributeInfo attrs[] = getAttributes();
- ModelMBeanAttributeInfo attributes[] =
- new ModelMBeanAttributeInfo[attrs.length];
+ MBeanAttributeInfo attributes[] =
+ new MBeanAttributeInfo[attrs.length];
for (int i = 0; i < attrs.length; i++)
attributes[i] = attrs[i].createAttributeInfo();
+
+ OperationInfo opers[] = getOperations();
+ MBeanOperationInfo operations[] =
+ new MBeanOperationInfo[opers.length];
+ for (int i = 0; i < opers.length; i++)
+ operations[i] = opers[i].createOperationInfo();
+
+
+// ConstructorInfo consts[] = getConstructors();
+// ModelMBeanConstructorInfo constructors[] =
+// new ModelMBeanConstructorInfo[consts.length];
+// for (int i = 0; i < consts.length; i++)
+// constructors[i] = consts[i].createConstructorInfo();
- ConstructorInfo consts[] = getConstructors();
- ModelMBeanConstructorInfo constructors[] =
- new ModelMBeanConstructorInfo[consts.length];
- for (int i = 0; i < consts.length; i++)
- constructors[i] = consts[i].createConstructorInfo();
NotificationInfo notifs[] = getNotifications();
- ModelMBeanNotificationInfo notifications[] =
- new ModelMBeanNotificationInfo[notifs.length];
+ MBeanNotificationInfo notifications[] =
+ new MBeanNotificationInfo[notifs.length];
for (int i = 0; i < notifs.length; i++)
notifications[i] = notifs[i].createNotificationInfo();
- OperationInfo opers[] = getOperations();
- ModelMBeanOperationInfo operations[] =
- new ModelMBeanOperationInfo[opers.length];
- for (int i = 0; i < opers.length; i++)
- operations[i] = opers[i].createOperationInfo();
- /*
- // Add operations for attribute getters and setters as needed
- ArrayList list = new ArrayList();
- for (int i = 0; i < operations.length; i++)
- list.add(operations[i]);
- for (int i = 0; i < attributes.length; i++) {
- Descriptor descriptor = attributes[i].getDescriptor();
- String getMethod = (String) descriptor.getFieldValue("getMethod");
- if (getMethod != null) {
- OperationInfo oper =
- new OperationInfo(getMethod, true,
- attributes[i].getType());
- list.add(oper.createOperationInfo());
- }
- String setMethod = (String) descriptor.getFieldValue("setMethod");
- if (setMethod != null) {
- OperationInfo oper =
- new OperationInfo(setMethod, false,
- attributes[i].getType());
- list.add(oper.createOperationInfo());
- }
- }
- if (list.size() > operations.length)
- operations =
- (ModelMBeanOperationInfo[]) list.toArray(operations);
- */
// Construct and return a new ModelMBeanInfo object
- info = new ModelMBeanInfoSupport
- (getClassName(), getDescription(),
- attributes, constructors, operations, notifications);
- try {
- Descriptor descriptor = info.getMBeanDescriptor();
- Iterator fields = getFields().iterator();
- while (fields.hasNext()) {
- FieldInfo field = (FieldInfo) fields.next();
- descriptor.setField(field.getName(), field.getValue());
- }
- info.setMBeanDescriptor(descriptor);
- } catch (MBeanException e) {
- ;
- }
+ info = new MBeanInfo(getClassName(),
+ getDescription(),
+ attributes,
+ new MBeanConstructorInfo[] {},
+ operations,
+ notifications);
+// try {
+// Descriptor descriptor = info.getMBeanDescriptor();
+// Iterator fields = getFields().iterator();
+// while (fields.hasNext()) {
+// FieldInfo field = (FieldInfo) fields.next();
+// descriptor.setField(field.getName(), field.getValue());
+// }
+// info.setMBeanDescriptor(descriptor);
+// } catch (MBeanException e) {
+// ;
+// }
return (info);
@@ -504,5 +477,151 @@ public class ManagedBean implements java.io.Serializable
}
+ Method getGetter(String aname, BaseModelMBean mbean, Object resource)
+ throws AttributeNotFoundException, MBeanException, ReflectionException {
+ // TODO: do we need caching ? JMX is for management, it's not supposed to require lots of performance.
+ Method m=null; // (Method)getAttMap.get( name );
+
+ if( m==null ) {
+ AttributeInfo attrInfo = (AttributeInfo)attributes.get(aname);
+ // Look up the actual operation to be used
+ if (attrInfo == null)
+ throw new AttributeNotFoundException(" Cannot find attribute " + aname + " for " + resource);
+
+ String getMethod = attrInfo.getGetMethod();
+ if (getMethod == null)
+ throw new AttributeNotFoundException("Cannot find attribute " + aname + " get method name");
+
+ Object object = null;
+ NoSuchMethodException exception = null;
+ try {
+ object = mbean;
+ m = object.getClass().getMethod(getMethod, NO_ARGS_PARAM_SIG);
+ } catch (NoSuchMethodException e) {
+ exception = e;;
+ }
+ if( m== null && resource != null ) {
+ try {
+ object = resource;
+ m = object.getClass().getMethod(getMethod, NO_ARGS_PARAM_SIG);
+ exception=null;
+ } catch (NoSuchMethodException e) {
+ exception = e;
+ }
+ }
+ if( exception != null )
+ throw new ReflectionException(exception,
+ "Cannot find getter method " + getMethod);
+ //getAttMap.put( name, m );
+ }
+
+ return m;
+ }
+
+ public Method getSetter(String aname, BaseModelMBean bean, Object resource)
+ throws AttributeNotFoundException, MBeanException, ReflectionException {
+ // Cache may be needed for getters, but it is a really bad idea for setters, this is far
+ // less frequent.
+ Method m=null;//(Method)setAttMap.get( name );
+
+ if( m==null ) {
+ AttributeInfo attrInfo = (AttributeInfo)attributes.get(aname);
+ if (attrInfo == null)
+ throw new AttributeNotFoundException(" Cannot find attribute " + aname);
+
+ // Look up the actual operation to be used
+ String setMethod = attrInfo.getSetMethod();
+ if (setMethod == null)
+ throw new AttributeNotFoundException("Cannot find attribute " + aname + " set method name");
+
+ String argType=attrInfo.getType();
+
+ Class signature[] = new Class[] { BaseModelMBean.getAttributeClass( argType ) };
+
+ Object object = null;
+ NoSuchMethodException exception = null;
+ try {
+ object = this;
+ m = object.getClass().getMethod(setMethod, signature);
+ } catch (NoSuchMethodException e) {
+ exception = e;;
+ }
+ if( m== null && resource != null ) {
+ try {
+ object = resource;
+ m = object.getClass().getMethod(setMethod, signature);
+ exception=null;
+ } catch (NoSuchMethodException e) {
+ exception = e;
+ }
+ }
+ if( exception != null )
+ throw new ReflectionException(exception,
+ "Cannot find setter method " + setMethod +
+ " " + resource);
+ //setAttMap.put( name, m );
+ }
+
+ return m;
+ }
+
+ public Method getInvoke(String aname, Object[] params, String[] signature, BaseModelMBean bean, Object resource)
+ throws MBeanException, ReflectionException {
+ Method method = null;
+ if (method == null) {
+ if (params == null)
+ params = new Object[0];
+ if (signature == null)
+ signature = new String[0];
+ if (params.length != signature.length)
+ throw new RuntimeOperationsException(
+ new IllegalArgumentException(
+ "Inconsistent arguments and signature"),
+ "Inconsistent arguments and signature");
+
+ // Acquire the ModelMBeanOperationInfo information for
+ // the requested operation
+ OperationInfo opInfo = (OperationInfo)operations.get(aname);
+ if (opInfo == null)
+ throw new MBeanException(new ServiceNotFoundException(
+ "Cannot find operation " + aname),
+ "Cannot find operation " + aname);
+
+ // Prepare the signature required by Java reflection APIs
+ // FIXME - should we use the signature from opInfo?
+ Class types[] = new Class[signature.length];
+ for (int i = 0; i < signature.length; i++) {
+ types[i] = BaseModelMBean.getAttributeClass(signature[i]);
+ }
+
+ // Locate the method to be invoked, either in this MBean itself
+ // or in the corresponding managed resource
+ // FIXME - Accessible methods in superinterfaces?
+ Object object = null;
+ Exception exception = null;
+ try {
+ object = this;
+ method = object.getClass().getMethod(aname, types);
+ } catch (NoSuchMethodException e) {
+ exception = e;
+ ;
+ }
+ try {
+ if ((method == null) && (resource != null)) {
+ object = resource;
+ method = object.getClass().getMethod(aname, types);
+ }
+ } catch (NoSuchMethodException e) {
+ exception = e;
+ }
+ if (method == null) {
+ throw new ReflectionException(exception, "Cannot find method "
+ + aname + " with this signature");
+ }
+ // invokeAttMap.put(mkey, method);
+ }
+ return method;
+ }
+
}
diff --git a/java/org/apache/tomcat/util/modeler/NotificationInfo.java b/java/org/apache/tomcat/util/modeler/NotificationInfo.java
index 98e65566d..f6c66f19e 100644
--- a/java/org/apache/tomcat/util/modeler/NotificationInfo.java
+++ b/java/org/apache/tomcat/util/modeler/NotificationInfo.java
@@ -20,8 +20,7 @@ package org.apache.tomcat.util.modeler;
import java.io.Serializable;
-import javax.management.Descriptor;
-import javax.management.modelmbean.ModelMBeanNotificationInfo;
+import javax.management.MBeanNotificationInfo;
/**
@@ -42,7 +41,7 @@ public class NotificationInfo extends FeatureInfo implements Serializable {
* The ModelMBeanNotificationInfo object that corresponds
* to this NotificationInfo instance.
*/
- transient ModelMBeanNotificationInfo info = null;
+ transient MBeanNotificationInfo info = null;
protected String notifTypes[] = new String[0];
// ------------------------------------------------------------- Properties
@@ -103,18 +102,18 @@ public class NotificationInfo extends FeatureInfo implements Serializable {
* Create and return a ModelMBeanNotificationInfo object that
* corresponds to the attribute described by this instance.
*/
- public ModelMBeanNotificationInfo createNotificationInfo() {
+ public MBeanNotificationInfo createNotificationInfo() {
// Return our cached information (if any)
if (info != null)
return (info);
// Create and return a new information object
- info = new ModelMBeanNotificationInfo
+ info = new MBeanNotificationInfo
(getNotifTypes(), getName(), getDescription());
- Descriptor descriptor = info.getDescriptor();
- addFields(descriptor);
- info.setDescriptor(descriptor);
+ //Descriptor descriptor = info.getDescriptor();
+ //addFields(descriptor);
+ //info.setDescriptor(descriptor);
return (info);
}
diff --git a/java/org/apache/tomcat/util/modeler/OperationInfo.java b/java/org/apache/tomcat/util/modeler/OperationInfo.java
index 6be9ea403..6874d2207 100644
--- a/java/org/apache/tomcat/util/modeler/OperationInfo.java
+++ b/java/org/apache/tomcat/util/modeler/OperationInfo.java
@@ -20,9 +20,8 @@ package org.apache.tomcat.util.modeler;
import java.io.Serializable;
-import javax.management.Descriptor;
+import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
-import javax.management.modelmbean.ModelMBeanOperationInfo;
/**
@@ -30,9 +29,7 @@ import javax.management.modelmbean.ModelMBeanOperationInfo;
* descriptor.
*
* @author Craig R. McClanahan
- * @version $Revision: 155428 $ $Date: 2005-02-26 14:12:25 +0100 (sam., 26 févr. 2005) $
*/
-
public class OperationInfo extends FeatureInfo implements Serializable {
static final long serialVersionUID = 4418342922072614875L;
// ----------------------------------------------------------- Constructors
@@ -46,77 +43,16 @@ public class OperationInfo extends FeatureInfo implements Serializable {
super();
}
-
-
- /**
- * Special constructor for setting up getter and setter operations.
- *
- * @param name Name of this operation
- * @param getter Is this a getter (as opposed to a setter)?
- * @param type Data type of the return value (if this is a getter)
- * or the parameter (if this is a setter)
- *
- */
- public OperationInfo(String name, boolean getter, String type) {
-
- super();
- setName(name);
- if (getter) {
- setDescription("Attribute getter method");
- setImpact("INFO");
- setReturnType(type);
- setRole("getter");
- } else {
- setDescription("Attribute setter method");
- setImpact("ACTION");
- setReturnType("void");
- setRole("setter");
- addParameter(new ParameterInfo("value", type,
- "New attribute value"));
- }
-
- }
-
-
+
// ----------------------------------------------------- Instance Variables
-
- /**
- * The ModelMBeanOperationInfo object that corresponds
- * to this OperationInfo instance.
- */
- transient ModelMBeanOperationInfo info = null;
protected String impact = "UNKNOWN";
protected String role = "operation";
- protected String returnType = "void"; // FIXME - Validate
protected ParameterInfo parameters[] = new ParameterInfo[0];
// ------------------------------------------------------------- Properties
-
- /**
- * Override the description property setter.
- *
- * @param description The new description
- */
- public void setDescription(String description) {
- super.setDescription(description);
- this.info = null;
- }
-
-
- /**
- * Override the name property setter.
- *
- * @param name The new name
- */
- public void setName(String name) {
- super.setName(name);
- this.info = null;
- }
-
-
/**
* The "impact" of this operation, which should be a (case-insensitive)
* string value "ACTION", "ACTION_INFO", "INFO", or "UNKNOWN".
@@ -151,11 +87,14 @@ public class OperationInfo extends FeatureInfo implements Serializable {
* operation.
*/
public String getReturnType() {
- return (this.returnType);
+ if(type == null) {
+ type = "void";
+ }
+ return type;
}
public void setReturnType(String returnType) {
- this.returnType = returnType;
+ this.type = returnType;
}
/**
@@ -190,57 +129,32 @@ public class OperationInfo extends FeatureInfo implements Serializable {
* Create and return a ModelMBeanOperationInfo object that
* corresponds to the attribute described by this instance.
*/
- public ModelMBeanOperationInfo createOperationInfo() {
+ MBeanOperationInfo createOperationInfo() {
// Return our cached information (if any)
- if (info != null)
- return (info);
+ if (info == null) {
+ // Create and return a new information object
+ int impact = MBeanOperationInfo.UNKNOWN;
+ if ("ACTION".equals(getImpact()))
+ impact = MBeanOperationInfo.ACTION;
+ else if ("ACTION_INFO".equals(getImpact()))
+ impact = MBeanOperationInfo.ACTION_INFO;
+ else if ("INFO".equals(getImpact()))
+ impact = MBeanOperationInfo.INFO;
+
+ info = new MBeanOperationInfo(getName(), getDescription(),
+ getMBeanParameterInfo(),
+ getReturnType(), impact);
+ }
+ return (MBeanOperationInfo)info;
+ }
- // Create and return a new information object
+ protected MBeanParameterInfo[] getMBeanParameterInfo() {
ParameterInfo params[] = getSignature();
MBeanParameterInfo parameters[] =
new MBeanParameterInfo[params.length];
for (int i = 0; i < params.length; i++)
parameters[i] = params[i].createParameterInfo();
- int impact = ModelMBeanOperationInfo.UNKNOWN;
- if ("ACTION".equals(getImpact()))
- impact = ModelMBeanOperationInfo.ACTION;
- else if ("ACTION_INFO".equals(getImpact()))
- impact = ModelMBeanOperationInfo.ACTION_INFO;
- else if ("INFO".equals(getImpact()))
- impact = ModelMBeanOperationInfo.INFO;
-
- info = new ModelMBeanOperationInfo
- (getName(), getDescription(), parameters,
- getReturnType(), impact);
- Descriptor descriptor = info.getDescriptor();
- descriptor.removeField("class");
- descriptor.setField("role", getRole());
- addFields(descriptor);
- info.setDescriptor(descriptor);
- return (info);
-
- }
-
-
- /**
- * Return a string representation of this operation descriptor.
- */
- public String toString() {
-
- StringBuffer sb = new StringBuffer("OperationInfo[");
- sb.append("name=");
- sb.append(name);
- sb.append(", description=");
- sb.append(description);
- sb.append(", returnType=");
- sb.append(returnType);
- sb.append(", parameters=");
- sb.append(parameters.length);
- sb.append("]");
- return (sb.toString());
-
+ return parameters;
}
-
-
}
diff --git a/java/org/apache/tomcat/util/modeler/ParameterInfo.java b/java/org/apache/tomcat/util/modeler/ParameterInfo.java
index 13717bdf0..f5c7cd942 100644
--- a/java/org/apache/tomcat/util/modeler/ParameterInfo.java
+++ b/java/org/apache/tomcat/util/modeler/ParameterInfo.java
@@ -40,80 +40,9 @@ public class ParameterInfo extends FeatureInfo implements Serializable {
* Standard zero-arguments constructor.
*/
public ParameterInfo() {
-
- super();
-
- }
-
-
- /**
- * Special constructor for setting up parameters programatically.
- *
- * @param name Name of this parameter
- * @param type Java class of this parameter
- * @param description Description of this parameter
- */
- public ParameterInfo(String name, String type, String description) {
-
super();
- setName(name);
- setType(type);
- setDescription(description);
-
- }
-
-
- // ----------------------------------------------------- Instance Variables
-
-
- /**
- * The MBeanParameterInfo object that corresponds
- * to this ParameterInfo instance.
- */
- transient MBeanParameterInfo info = null;
- protected String type = null;
-
- // ------------------------------------------------------------- Properties
-
-
- /**
- * Override the description property setter.
- *
- * @param description The new description
- */
- public void setDescription(String description) {
- super.setDescription(description);
- this.info = null;
- }
-
-
- /**
- * Override the name property setter.
- *
- * @param name The new name
- */
- public void setName(String name) {
- super.setName(name);
- this.info = null;
}
-
- /**
- * The fully qualified Java class name of this parameter.
- */
- public String getType() {
- return (this.type);
- }
-
- public void setType(String type) {
- this.type = type;
- this.info = null;
- }
-
-
- // --------------------------------------------------------- Public Methods
-
-
/**
* Create and return a MBeanParameterInfo object that
* corresponds to the parameter described by this instance.
@@ -121,31 +50,10 @@ public class ParameterInfo extends FeatureInfo implements Serializable {
public MBeanParameterInfo createParameterInfo() {
// Return our cached information (if any)
- if (info != null)
- return (info);
-
- // Create and return a new information object
- info = new MBeanParameterInfo
- (getName(), getType(), getDescription());
- return (info);
-
- }
-
-
- /**
- * Return a string representation of this parameter descriptor.
- */
- public String toString() {
-
- StringBuffer sb = new StringBuffer("ParameterInfo[");
- sb.append("name=");
- sb.append(name);
- sb.append(", description=");
- sb.append(description);
- sb.append(", type=");
- sb.append(type);
- sb.append("]");
- return (sb.toString());
-
+ if (info == null) {
+ info = new MBeanParameterInfo
+ (getName(), getType(), getDescription());
+ }
+ return (MBeanParameterInfo)info;
}
}
diff --git a/java/org/apache/tomcat/util/modeler/Registry.java b/java/org/apache/tomcat/util/modeler/Registry.java
index 14bfa7c6f..55de2dd55 100644
--- a/java/org/apache/tomcat/util/modeler/Registry.java
+++ b/java/org/apache/tomcat/util/modeler/Registry.java
@@ -23,7 +23,6 @@ import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
@@ -38,7 +37,6 @@ import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-import javax.management.modelmbean.ModelMBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -73,10 +71,6 @@ import org.apache.tomcat.util.modeler.modules.ModelerSource;
* @author Costin Manolache
*/
public class Registry implements RegistryMBean, MBeanRegistration {
- /** Experimental support for manifest-based discovery.
- */
- public static String MODELER_MANIFEST="/META-INF/mbeans-descriptors.xml";
-
/**
* The Log instance to which we will write our log messages.
*/
@@ -84,7 +78,7 @@ public class Registry implements RegistryMBean, MBeanRegistration {
// Support for the factory methods
- /** Will be used to isolate different apps and enhance security
+ /** Will be used to isolate different apps and enhance security.
*/
private static HashMap perLoaderRegistries=null;
@@ -106,19 +100,19 @@ public class Registry implements RegistryMBean, MBeanRegistration {
* The set of ManagedBean instances for the beans this registry
* knows about, keyed by name.
*/
- private HashMap descriptors = new HashMap();
+ private HashMap descriptors = new HashMap();
/** List of managed byeans, keyed by class name
*/
- private HashMap descriptorsByClass = new HashMap();
+ private HashMap descriptorsByClass = new HashMap();
// map to avoid duplicated searching or loading descriptors
- private Hashtable searchedPaths=new Hashtable();
+ private HashMap searchedPaths=new HashMap();
- private Object key;
private Object guard;
// Id - small ints to use array access. No reset on stop()
+ // Used for notifications
private Hashtable idDomains=new Hashtable();
private Hashtable ids=new Hashtable();
@@ -160,7 +154,7 @@ public class Registry implements RegistryMBean, MBeanRegistration {
localRegistry=(Registry)perLoaderRegistries.get(key);
if( localRegistry == null ) {
localRegistry=new Registry();
- localRegistry.key=key;
+// localRegistry.key=key;
localRegistry.guard=guard;
perLoaderRegistries.put( key, localRegistry );
return localRegistry;
@@ -184,7 +178,8 @@ public class Registry implements RegistryMBean, MBeanRegistration {
return (registry);
}
- /** Allow containers to isolate apps. Can be called only once.
+ /**
+ * Allow containers to isolate apps. Can be called only once.
* It is highly recommended you call this method if using Registry in
* a container environment. The default is false for backward compatibility
*
@@ -199,28 +194,15 @@ public class Registry implements RegistryMBean, MBeanRegistration {
// -------------------- Generic methods --------------------
- /** Set a guard object that will prevent access to this registry
- * by unauthorized components
- *
- * @param guard
- *
- * @since 1.1
- */
- public void setGuard( Object guard ) {
- if( this.guard!=null ) {
- return; // already set, only once
- }
- this.guard=guard;
- }
-
/** Lifecycle method - clean up the registry metadata.
+ * Called from resetMetadata().
*
* @since 1.1
*/
public void stop() {
- descriptorsByClass = new HashMap();
- descriptors = new HashMap();
- searchedPaths=new Hashtable();
+ descriptorsByClass = new HashMap();
+ descriptors = new HashMap();
+ searchedPaths=new HashMap();
}
/**
@@ -249,9 +231,6 @@ public class Registry implements RegistryMBean, MBeanRegistration {
* descriptors file. In the case of File and URL, if the extension is ".ser"
* a serialized version will be loaded.
*
- * Also ( experimental for now ) a ClassLoader - in which case META-INF/ will
- * be used.
- *
* This method should be used to explicitely load metadata - but this is not
* required in most cases. The registerComponent() method will find metadata
* in the same pacakge.
@@ -259,13 +238,7 @@ public class Registry implements RegistryMBean, MBeanRegistration {
* @param source
*/
public void loadMetadata(Object source ) throws Exception {
- if( source instanceof ClassLoader ) {
- loadMetaInfDescriptors((ClassLoader)source);
- return;
- } else {
- loadDescriptors( null, source, null );
- }
-
+ loadDescriptors( null, source, null );
}
/** Register a bean by creating a modeler mbean and adding it to the
@@ -411,11 +384,9 @@ public class Registry implements RegistryMBean, MBeanRegistration {
*/
public void addManagedBean(ManagedBean bean) {
// XXX Use group + name
- synchronized(descriptors) {
- descriptors.put(bean.getName(), bean);
- if( bean.getType() != null ) {
- descriptorsByClass.put( bean.getType(), bean );
- }
+ descriptors.put(bean.getName(), bean);
+ if( bean.getType() != null ) {
+ descriptorsByClass.put( bean.getType(), bean );
}
}
@@ -430,12 +401,10 @@ public class Registry implements RegistryMBean, MBeanRegistration {
*/
public ManagedBean findManagedBean(String name) {
// XXX Group ?? Use Group + Type
- synchronized(descriptors) {
- ManagedBean mb= descriptors.get(name);
- if( mb==null )
- mb=descriptorsByClass.get(name);
- return mb;
- }
+ ManagedBean mb=((ManagedBean) descriptors.get(name));
+ if( mb==null )
+ mb=(ManagedBean)descriptorsByClass.get(name);
+ return mb;
}
/**
@@ -445,9 +414,7 @@ public class Registry implements RegistryMBean, MBeanRegistration {
* @since 1.0
*/
public String[] findManagedBeans() {
- synchronized(descriptors) {
- return ((String[]) descriptors.keySet().toArray(new String[0]));
- }
+ return ((String[]) descriptors.keySet().toArray(new String[0]));
}
@@ -462,15 +429,13 @@ public class Registry implements RegistryMBean, MBeanRegistration {
public String[] findManagedBeans(String group) {
ArrayList results = new ArrayList();
- synchronized(descriptors) {
- Iterator items = descriptors.values().iterator();
- while (items.hasNext()) {
- ManagedBean item = items.next();
- if ((group == null) && (item.getGroup() == null)) {
- results.add(item.getName());
- } else if (group.equals(item.getGroup())) {
- results.add(item.getName());
- }
+ Iterator items = descriptors.values().iterator();
+ while (items.hasNext()) {
+ ManagedBean item = (ManagedBean) items.next();
+ if ((group == null) && (item.getGroup() == null)) {
+ results.add(item.getName());
+ } else if (group.equals(item.getGroup())) {
+ results.add(item.getName());
}
}
String values[] = new String[results.size()];
@@ -487,10 +452,8 @@ public class Registry implements RegistryMBean, MBeanRegistration {
*/
public void removeManagedBean(ManagedBean bean) {
// TODO: change this to use group/name
- synchronized(descriptors) {
- descriptors.remove(bean.getName());
- descriptorsByClass.remove( bean.getType());
- }
+ descriptors.remove(bean.getName());
+ descriptorsByClass.remove( bean.getType());
}
// -------------------- Deprecated 1.0 methods --------------------
@@ -829,7 +792,7 @@ public class Registry implements RegistryMBean, MBeanRegistration {
ManagedBean managed = findManagedBean(bean.getClass(), type);
// The real mbean is created and registered
- ModelMBean mbean = managed.createMBean(bean);
+ DynamicMBean mbean = managed.createMBean(bean);
if( getMBeanServer().isRegistered( oname )) {
if( log.isDebugEnabled()) {
@@ -850,7 +813,7 @@ public class Registry implements RegistryMBean, MBeanRegistration {
*
* @param packageName
*/
- public synchronized void loadDescriptors( String packageName, ClassLoader classLoader ) {
+ public void loadDescriptors( String packageName, ClassLoader classLoader ) {
String res=packageName.replace( '.', '/');
if( log.isTraceEnabled() ) {
@@ -910,25 +873,6 @@ public class Registry implements RegistryMBean, MBeanRegistration {
}
}
- /** Discover all META-INF/modeler.xml files in classpath and register
- * the components
- *
- * @since EXPERIMENTAL
- */
- private void loadMetaInfDescriptors(ClassLoader cl) {
- try {
- Enumeration en=cl.getResources(MODELER_MANIFEST);
- while( en.hasMoreElements() ) {
- URL url=(URL)en.nextElement();
- InputStream is=url.openStream();
- if( log.isDebugEnabled()) log.debug("Loading " + url);
- loadDescriptors("MbeansDescriptorsDigesterSource", is, null );
- }
- } catch( Exception ex ) {
- ex.printStackTrace();
- }
- }
-
/** Lookup the component descriptor in the package and
* in the parent packages.
*
@@ -1072,12 +1016,6 @@ public class Registry implements RegistryMBean, MBeanRegistration {
}
}
- public List loadMBeans( Object source )
- throws Exception
- {
- return loadMBeans( source, null );
- }
-
/**
* Load the registry from a cached .ser file. This is typically 2-3 times
diff --git a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDOMSource.java b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDOMSource.java
index 3b7314ccb..508ea8df4 100644
--- a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDOMSource.java
+++ b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDOMSource.java
@@ -25,8 +25,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tomcat.util.DomUtil;
import org.apache.tomcat.util.modeler.AttributeInfo;
-import org.apache.tomcat.util.modeler.ConstructorInfo;
-import org.apache.tomcat.util.modeler.FieldInfo;
import org.apache.tomcat.util.modeler.ManagedBean;
import org.apache.tomcat.util.modeler.NotificationInfo;
import org.apache.tomcat.util.modeler.OperationInfo;
@@ -116,7 +114,7 @@ public class MbeansDescriptorsDOMSource extends ModelerSource
Node firstN;
// Process descriptor subnode
- Node mbeanDescriptorN =
+ /*Node mbeanDescriptorN =
DomUtil.getChild(mbeanN, "descriptor");
if (mbeanDescriptorN != null) {
Node firstFieldN =
@@ -127,7 +125,7 @@ public class MbeansDescriptorsDOMSource extends ModelerSource
DomUtil.setAttributes(fi, fieldN);
managed.addField(fi);
}
- }
+ }*/
// process attribute nodes
firstN=DomUtil.getChild( mbeanN, "attribute");
@@ -140,7 +138,7 @@ public class MbeansDescriptorsDOMSource extends ModelerSource
DomUtil.setAttributes(ai, descN);
// Process descriptor subnode
- Node descriptorN =
+ /*Node descriptorN =
DomUtil.getChild(descN, "descriptor");
if (descriptorN != null) {
Node firstFieldN =
@@ -152,6 +150,7 @@ public class MbeansDescriptorsDOMSource extends ModelerSource
ai.addField(fi);
}
}
+ */
// Add this info to our managed bean info
managed.addAttribute( ai );
@@ -162,6 +161,7 @@ public class MbeansDescriptorsDOMSource extends ModelerSource
}
// process constructor nodes
+ /*
firstN=DomUtil.getChild( mbeanN, "constructor");
for (Node descN = firstN; descN != null;
descN = DomUtil.getNext( descN )) {
@@ -200,7 +200,7 @@ public class MbeansDescriptorsDOMSource extends ModelerSource
log.trace("Create constructor " + ci);
}
- }
+ }*/
// process notification nodes
firstN=DomUtil.getChild( mbeanN, "notification");
@@ -213,7 +213,7 @@ public class MbeansDescriptorsDOMSource extends ModelerSource
DomUtil.setAttributes(ni, descN);
// Process descriptor subnode
- Node firstDescriptorN =
+ /*Node firstDescriptorN =
DomUtil.getChild(descN, "descriptor");
if (firstDescriptorN != null) {
Node firstFieldN =
@@ -224,7 +224,7 @@ public class MbeansDescriptorsDOMSource extends ModelerSource
DomUtil.setAttributes(fi, fieldN);
ni.addField(fi);
}
- }
+ }*/
// Process notification-type subnodes
Node firstParamN=DomUtil.getChild( descN, "notification-type");
@@ -254,7 +254,7 @@ public class MbeansDescriptorsDOMSource extends ModelerSource
DomUtil.setAttributes(oi, descN);
// Process descriptor subnode
- Node firstDescriptorN =
+ /*Node firstDescriptorN =
DomUtil.getChild(descN, "descriptor");
if (firstDescriptorN != null) {
Node firstFieldN =
@@ -265,7 +265,7 @@ public class MbeansDescriptorsDOMSource extends ModelerSource
DomUtil.setAttributes(fi, fieldN);
oi.addField(fi);
}
- }
+ }*/
// Process parameter subnodes
Node firstParamN=DomUtil.getChild( descN, "parameter");
diff --git a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java
index a27ff8462..c7645ef01 100644
--- a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java
+++ b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDigesterSource.java
@@ -70,7 +70,7 @@ public class MbeansDescriptorsDigesterSource extends ModelerSource
"addAttribute",
"org.apache.tomcat.util.modeler.AttributeInfo");
- digester.addObjectCreate
+ /*digester.addObjectCreate
("mbeans-descriptors/mbean/attribute/descriptor/field",
"org.apache.tomcat.util.modeler.FieldInfo");
digester.addSetProperties
@@ -119,7 +119,7 @@ public class MbeansDescriptorsDigesterSource extends ModelerSource
("mbeans-descriptors/mbean/descriptor/field",
"addField",
"org.apache.tomcat.util.modeler.FieldInfo");
-
+ */
digester.addObjectCreate
("mbeans-descriptors/mbean/notification",
"org.apache.tomcat.util.modeler.NotificationInfo");
diff --git a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDynamicMBeanSource.java b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDynamicMBeanSource.java
deleted file mode 100644
index 5aa2ff75b..000000000
--- a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsDynamicMBeanSource.java
+++ /dev/null
@@ -1,157 +0,0 @@
-package org.apache.tomcat.util.modeler.modules;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.management.DynamicMBean;
-import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanInfo;
-import javax.management.MBeanOperationInfo;
-import javax.management.MBeanParameterInfo;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.tomcat.util.modeler.AttributeInfo;
-import org.apache.tomcat.util.modeler.ManagedBean;
-import org.apache.tomcat.util.modeler.OperationInfo;
-import org.apache.tomcat.util.modeler.ParameterInfo;
-import org.apache.tomcat.util.modeler.Registry;
-
-
-/** Extract metadata from a dynamic mbean.
- * Used to wrap a dynamic mbean in order to implement persistence.
- *
- * This is really an ugly asspect of the JMX spec - we need to convery
- * from normal metainfo to model metainfo. The info is the same, but
- * they use a different class. Just like the DOM spec - where all implementations
- * get an order of unneeded complexity from the various types.
- *
- */
-public class MbeansDescriptorsDynamicMBeanSource extends ModelerSource
-{
- private static Log log = LogFactory.getLog(MbeansDescriptorsDynamicMBeanSource.class);
-
- Registry registry;
- String location;
- String type;
- Object source;
- List mbeans=new ArrayList();
-
- public void setRegistry(Registry reg) {
- this.registry=reg;
- }
-
- public void setLocation( String loc ) {
- this.location=loc;
- }
-
- /** Used if a single component is loaded
- *
- * @param type
- */
- public void setType( String type ) {
- this.type=type;
- }
-
- public void setSource( Object source ) {
- this.source=source;
- }
-
- public List loadDescriptors( Registry registry, String location,
- String type, Object source)
- throws Exception
- {
- setRegistry(registry);
- setLocation(location);
- setType(type);
- setSource(source);
- execute();
- return mbeans;
- }
-
- public void execute() throws Exception {
- if( registry==null ) registry=Registry.getRegistry();
- try {
- ManagedBean managed=createManagedBean(registry, null, source, type);
- if( managed==null ) return;
- managed.setName( type );
-
- mbeans.add(managed);
-
- } catch( Exception ex ) {
- log.error( "Error reading descriptors ", ex);
- }
- }
-
-
-
- // ------------ Implementation for non-declared introspection classes
-
-
- /**
- * XXX Find if the 'className' is the name of the MBean or
- * the real class ( I suppose first )
- * XXX Read (optional) descriptions from a .properties, generated
- * from source
- * XXX Deal with constructors
- *
- */
- public ManagedBean createManagedBean(Registry registry, String domain,
- Object realObj, String type)
- {
- if( ! ( realObj instanceof DynamicMBean )) {
- return null;
- }
- DynamicMBean dmb=(DynamicMBean)realObj;
-
- ManagedBean mbean= new ManagedBean();
-
- MBeanInfo mbi=dmb.getMBeanInfo();
-
- try {
- MBeanAttributeInfo attInfo[]=mbi.getAttributes();
- for( int i=0; i