costin 2002/11/12 14:48:40
Modified: modeler/src/java/org/apache/commons/modeler
BaseModelMBean.java
Log:
Added a new constructor and method to allow a 'type' to
be specified when constructing the model mbean.
That allows its use in MLETs and the ant mlet task.
Revision Changes Path
1.7 +40 -5
jakarta-commons/modeler/src/java/org/apache/commons/modeler/BaseModelMBean.java
Index: BaseModelMBean.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/BaseModelMBean.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- BaseModelMBean.java 5 Nov 2002 19:10:19 -0000 1.6
+++ BaseModelMBean.java 12 Nov 2002 22:48:40 -0000 1.7
@@ -170,6 +170,12 @@
}
+ public BaseModelMBean( String type )
+ throws MBeanException, RuntimeOperationsException
+ {
+ super();
+ setModeledType(type);
+ }
// ----------------------------------------------------- Instance Variables
@@ -1113,6 +1119,36 @@
}
+ // -------------------- BaseModelMBean methods --------------------
+
+ /** 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
+ */
+ public void setModeledType( String type ) {
+ try {
+ Registry reg=Registry.getRegistry();
+ ManagedBean descriptor=reg.findManagedBean(type);
+
+ if( descriptor != null ) {
+ System.out.println("Using descriptor " + type);
+ this.setModelMBeanInfo( descriptor.createMBeanInfo());
+ return;
+ }
+
+ // Maybe it's a real class name. Use introspection
+ Class c=Class.forName( type);
+ resource = c.newInstance();
+ System.out.println("Introspecting " + type);
+ descriptor=reg.createManagedBean(null, c, type);
+
+ this.setModelMBeanInfo(descriptor.createMBeanInfo());
+ } catch( Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
// ------------------------------------------------------ Protected Methods
@@ -1126,7 +1162,6 @@
null, null, null, null));
}
-
/**
* Is the specified <code>ModelMBeanInfo</code> instance valid?
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>