costin 2003/01/10 23:23:29
Modified: modeler/src/java/org/apache/commons/modeler Registry.java
Removed: modeler/src/java/org/apache/commons/modeler
BaseRegistry.java
Log:
I added BaseRegistry few weeks ago - attempting to make
modeler useable without a dependency on JMX. That doesn't seem
to work - modeler is too specific to JMX, and many features
can't be exposed.
I also cleaned up some of the new APIs ( I hope I didn't broke
any of the old ones and nobody started to use them - gump will
tell very soon )
Revision Changes Path
1.14 +100 -38
jakarta-commons/modeler/src/java/org/apache/commons/modeler/Registry.java
Index: Registry.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/Registry.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- Registry.java 7 Jan 2003 21:07:40 -0000 1.13
+++ Registry.java 11 Jan 2003 07:23:29 -0000 1.14
@@ -83,9 +83,8 @@
*
* @author Craig R. McClanahan
* @author Costin Manolache
- * @version $Revision$ $Date$
*/
-public final class Registry extends BaseRegistry {
+public final class Registry {
// ----------------------------------------------------------- Constructors
@@ -259,6 +258,7 @@
*
* @exception Exception if any parsing or processing error occurs
* @deprecated use normal class method instead
+ * @since 1.0
*/
public static void loadRegistry(InputStream stream) throws Exception {
Registry registry = getRegistry();
@@ -292,11 +292,38 @@
return ds;
}
- public void loadDescriptors( String location, String type, InputStream stream )
+ public void loadDescriptors( String type, Object source )
throws Exception
{
- DescriptorSource ds=getDescriptorSource(type);
- ds.loadDescriptors(this, location, type, stream);
+ log.trace("loadDescriptors " + source );
+
+ if( source instanceof URL ) {
+ System.out.println("Try " + source );
+ URL url=(URL)source;
+// URL url1=new URL( url.toString() + ".ser");
+// try {
+// System.out.println("Ser: " + url1);
+// InputStream stream=url1.openStream();
+// if( stream != null ) {
+// DescriptorSource
ds=getDescriptorSource("MbeansDescriptorsSer");
+// ds.loadDescriptors(this, url1.toString(), type, stream);
+// return;
+// }
+// } catch( FileNotFoundException ex ) {
+// // nothing
+// log.debug("Not found: " + url1 );
+// } catch( Exception ex ) {
+// ex.printStackTrace();
+// }
+ InputStream stream=url.openStream();
+ DescriptorSource ds=getDescriptorSource(type);
+ ds.loadDescriptors(this, url.toString(), type, stream);
+ }
+
+ if( source instanceof InputStream ) {
+ DescriptorSource ds=getDescriptorSource(type);
+ ds.loadDescriptors(this, null, type, (InputStream)source);
+ }
}
/**
@@ -307,11 +334,12 @@
* information
*
* @exception Exception if any parsing or processing error occurs
+ * @since 1.0
*/
public void loadDescriptors(InputStream stream, String type)
throws Exception
{
- loadDescriptors(null, type, stream );
+ loadDescriptors( type, stream );
}
/**
@@ -338,29 +366,34 @@
String name)
throws Exception
{
- if( type==null ) {
- // XXX find type from bean name.
- }
- ManagedBean managed = registry.findManagedBean(type);
- if( managed==null ) {
- // TODO: check package and parent packages
-
- // TODO: check super-class
-
- // introspection
- managed=createManagedBean(domain, bean.getClass(), type);
- addManagedBean(managed);
- }
-
- // The real mbean is created and registered
- ModelMBean mbean = managed.createMBean(bean);
+ String nameStr=null;
+ try {
+ if( type==null ) {
+ // XXX find type from bean name.
+ }
+ ManagedBean managed = registry.findManagedBean(type);
+ if( managed==null ) {
+ // TODO: check package and parent packages
+
+ // TODO: check super-class
+
+ // introspection
+ managed=createManagedBean(domain, bean.getClass(), type);
+ managed.setName( type );
+ addManagedBean(managed);
+ }
- if( name==null ) {
- // XXX generate a seq or hash ?
- // should we genereate the seq automatically ?
+ // The real mbean is created and registered
+ ModelMBean mbean = managed.createMBean(bean);
+ StringBuffer sb=new StringBuffer();
+ sb.append( domain ).append(":");
+ sb.append( name );
+ nameStr=sb.toString();
+ getServer().registerMBean( mbean, new ObjectName( nameStr ));
+ } catch( Exception ex) {
+ log.error("Error registering " + nameStr );
+ throw ex;
}
- getServer().registerMBean( mbean, new ObjectName( domain + ": type="
- + type + " ; " + name ));
}
public void unregisterComponent( String name ) {
@@ -375,15 +408,6 @@
}
- public void registerClass(Class beanClass, String domain, String className,
- String type, Object source)
- {
- // use intropsection. Source is not supported yet.
- ManagedBean managed=createManagedBean(domain, beanClass, type);
-
- }
-
-
public String registerMBean( String domain, String name ) {
try {
// XXX use aliases, suffix only, proxy.getName(), etc
@@ -434,13 +458,51 @@
try {
DescriptorSource
ds=getDescriptorSource("MbeansDescriptorsIntrospection");
ds.loadDescriptors(this, type, type, realClass);
- System.out.println("Loading " + realClass.getName());
- return findManagedBean(realClass.getName());
+ if( log.isDebugEnabled())
+ log.debug("Loading " + type + " " + realClass.getName());
+ return findManagedBean(type);
} catch( Exception ex ) {
ex.printStackTrace();
}
return null;
}
+ /** Find the 'type' for this class
+ *
+ */
+ public String getType( String domain, Class realClass ) {
+ // first look at explicit mappings ( exceptions in MBeanUtils )
+
+ // We could also look up super classes and locate one we know about
+
+ // We could use the domain as a discriminator
+
+ String name=realClass.getName();
+ name=name.substring( name.lastIndexOf( ".") + 1 );
+
+ return name;
+ }
+
+ // Store all objects that have been registered via modeler
+ // it is used to generate unique names automatically - using seq=
+ // scheme
+ Hashtable instances=new Hashtable();
+ /** If a name was not provided, generate a name based on the
+ * class name and a sequence number.
+ */
+ public String generateSeqName(String domain, Class realClass) {
+ String name=getType( domain, realClass );
+
+ Integer iInt=(Integer)instances.get(name );
+ int seq=0;
+ if( iInt!= null ) {
+ seq=iInt.intValue();
+ seq++;
+ instances.put( name, new Integer( seq ));
+ } else {
+ instances.put( name, new Integer( 0 ));
+ }
+ return "name=" + name + ",seq=" + seq;
+ }
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>