commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-commons/modeler/src/java/org/apache/commons/modeler Registry.java
Date Thu, 26 Dec 2002 18:21:01 GMT
costin      2002/12/26 10:21:01

  Modified:    modeler/src/java/org/apache/commons/modeler Registry.java
  Log:
  Refactored digester to a "source" module.
  Add a simple scheme to map the "type" parameter to a module.
  
  Revision  Changes    Path
  1.10      +30 -106   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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Registry.java	13 Nov 2002 06:25:32 -0000	1.9
  +++ Registry.java	26 Dec 2002 18:21:01 -0000	1.10
  @@ -69,11 +69,9 @@
   import javax.management.*;
   import javax.management.modelmbean.ModelMBean;
   
  -import org.apache.commons.digester.Digester;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  -
   /**
    * <p>Registry for MBean descriptor information.  This class implements
    * the Singleton design pattern.</p>
  @@ -267,6 +265,34 @@
           registry.loadDescriptors( stream, "modeler" );
       }
   
  +
  +    /** Source for descriptor data. More sources can be added.
  +     *
  +     */
  +    public static class DescriptorSource {
  +
  +        public void loadDescriptors( Registry registry, String location,
  +                                     String type, InputStream stream)
  +            throws Exception
  +        {
  +            // TODO
  +        }
  +    }
  +
  +    public void loadDescriptors( String location, String type, InputStream stream )
  +        throws Exception
  +    {
  +        if( type==null ) type="MbeansDescriptorsDOM";
  +        String moduleType=type + "Source";
  +        String sourceClassName=System.getProperty("org.apache.commons.modeler.source",
  +                "org.apache.commons.modeler.modules." + moduleType);
  +        // "org.apache.commons.modeler.modules.MBeansDescriptorsDigesterSource")
  +
  +        Class c=Class.forName( sourceClassName );
  +        DescriptorSource ds=(DescriptorSource)c.newInstance();
  +        ds.loadDescriptors(this, location, type, stream);
  +    }
  +
       /**
        * Load the registry from the XML input found in the specified input
        * stream.
  @@ -279,107 +305,7 @@
       public void loadDescriptors(InputStream stream, String type)
           throws Exception
       {
  -        long t1=System.currentTimeMillis();
  -
  -        // Create a digester to use for parsing
  -        Registry registry = this;
  -
  -        Digester digester = new Digester();
  -        digester.setNamespaceAware(false);
  -        digester.setValidating(false);
  -        URL url = registry.getClass().getResource
  -            ("/org/apache/commons/modeler/mbeans-descriptors.dtd");
  -        digester.register
  -            ("-//Apache Software Foundation//DTD Model MBeans Configuration File",
  -             url.toString());
  -
  -        // Push our registry object onto the stack
  -        digester.push(registry);
  -
  -        // Configure the parsing rules
  -        digester.addObjectCreate
  -            ("mbeans-descriptors/mbean",
  -             "org.apache.commons.modeler.ManagedBean");
  -        digester.addSetProperties
  -            ("mbeans-descriptors/mbean");
  -        digester.addSetNext
  -            ("mbeans-descriptors/mbean",
  -             "addManagedBean",
  -             "org.apache.commons.modeler.ManagedBean");
  -
  -        digester.addObjectCreate
  -            ("mbeans-descriptors/mbean/attribute",
  -             "org.apache.commons.modeler.AttributeInfo");
  -        digester.addSetProperties
  -            ("mbeans-descriptors/mbean/attribute");
  -        digester.addSetNext
  -            ("mbeans-descriptors/mbean/attribute",
  -             "addAttribute",
  -             "org.apache.commons.modeler.AttributeInfo");
  -
  -        digester.addObjectCreate
  -            ("mbeans-descriptors/mbean/constructor",
  -             "org.apache.commons.modeler.ConstructorInfo");
  -        digester.addSetProperties
  -            ("mbeans-descriptors/mbean/constructor");
  -        digester.addSetNext
  -            ("mbeans-descriptors/mbean/constructor",
  -             "addConstructor",
  -             "org.apache.commons.modeler.ConstructorInfo");
  -
  -        digester.addObjectCreate
  -            ("mbeans-descriptors/mbean/constructor/parameter",
  -             "org.apache.commons.modeler.ParameterInfo");
  -        digester.addSetProperties
  -            ("mbeans-descriptors/mbean/constructor/parameter");
  -        digester.addSetNext
  -            ("mbeans-descriptors/mbean/constructor/parameter",
  -             "addParameter",
  -             "org.apache.commons.modeler.ParameterInfo");
  -
  -        digester.addObjectCreate
  -            ("mbeans-descriptors/mbean/notification",
  -             "org.apache.commons.modeler.NotificationInfo");
  -        digester.addSetProperties
  -            ("mbeans-descriptors/mbean/notification");
  -        digester.addSetNext
  -            ("mbeans-descriptors/mbean/notification",
  -             "addNotification",
  -             "org.apache.commons.modeler.NotificationInfo");
  -        digester.addCallMethod
  -            ("mbeans-descriptors/mbean/notification/notification-type",
  -             "addNotifType", 0);
  -
  -        digester.addObjectCreate
  -            ("mbeans-descriptors/mbean/operation",
  -             "org.apache.commons.modeler.OperationInfo");
  -        digester.addSetProperties
  -            ("mbeans-descriptors/mbean/operation");
  -        digester.addSetNext
  -            ("mbeans-descriptors/mbean/operation",
  -             "addOperation",
  -             "org.apache.commons.modeler.OperationInfo");
  -
  -        digester.addObjectCreate
  -            ("mbeans-descriptors/mbean/operation/parameter",
  -             "org.apache.commons.modeler.ParameterInfo");
  -        digester.addSetProperties
  -             ("mbeans-descriptors/mbean/operation/parameter");
  -        digester.addSetNext
  -             ("mbeans-descriptors/mbean/operation/parameter",
  -              "addParameter",
  -              "org.apache.commons.modeler.ParameterInfo");
  -
  -        // Process the input file to configure our registry
  -        try {
  -            digester.parse(stream);
  -        } catch (Exception e) {
  -            log.error("Error digesting Registry data", e);
  -            throw e;
  -        }
  -        long t2=System.currentTimeMillis();
  -        if( t2-t1 > 500 )
  -            log.info("Loaded registry information " + ( t2 - t1 ) + " ms");
  +        loadDescriptors(null, type, stream );
       }
   
       /**
  @@ -389,9 +315,7 @@
        * @param mbeanServer The new <code>MBeanServer</code> instance
        */
       public static void setServer(MBeanServer mbeanServer) {
  -
           server = mbeanServer;
  -
       }
   
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message