You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by co...@apache.org on 2003/01/21 01:33:45 UTC

cvs commit: jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules MbeansDescriptorsDOMSource.java MbeansDescriptorsDigesterSource.java MbeansDescriptorsIntrospectionSource.java MbeansDescriptorsSerSource.java MbeansSource.java

costin      2003/01/20 16:33:45

  Modified:    modeler/src/java/org/apache/commons/modeler
                        BaseModelMBean.java
                        BaseNotificationBroadcaster.java Main.java
                        Registry.java
               modeler/src/java/org/apache/commons/modeler/ant
                        RegistryTask.java
               modeler/src/java/org/apache/commons/modeler/modules
                        MbeansDescriptorsDOMSource.java
                        MbeansDescriptorsDigesterSource.java
                        MbeansDescriptorsIntrospectionSource.java
                        MbeansDescriptorsSerSource.java MbeansSource.java
  Log:
  Another round of changes / refactorings. I think things are getting closer
  to stable.
  
  A number of bug fixes / enhancements in IntrospectionSource ( used if
  no explicit metadata is found ).
  
  If a descriptor is not found, we'll also look for mbeans-descriptors in
  the same package with the class we are looking for.
  
  Started to optimize a bit the notification helper - using the Fixed filter.
  
  It is not perfect yet, but I think it's getting better.
  
  Revision  Changes    Path
  1.12      +6 -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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- BaseModelMBean.java	11 Jan 2003 07:28:07 -0000	1.11
  +++ BaseModelMBean.java	21 Jan 2003 00:33:45 -0000	1.12
  @@ -1178,7 +1178,8 @@
               resource = c.newInstance();
               if( log.isDebugEnabled())
                   log.debug("Introspecting " + type);
  -            descriptor=reg.createManagedBean(null, c, type);
  +            reg.loadDescriptors("MbeansDescriptorsIntrospectionSource", c, type);
  +            descriptor=reg.findManagedBean(type);
   
               this.setModelMBeanInfo(descriptor.createMBeanInfo());
           } catch( Exception ex) {
  
  
  
  1.3       +29 -4     jakarta-commons/modeler/src/java/org/apache/commons/modeler/BaseNotificationBroadcaster.java
  
  Index: BaseNotificationBroadcaster.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/BaseNotificationBroadcaster.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BaseNotificationBroadcaster.java	15 Jun 2002 18:17:02 -0000	1.2
  +++ BaseNotificationBroadcaster.java	21 Jan 2003 00:33:45 -0000	1.3
  @@ -82,7 +82,7 @@
    *</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision$ $Date$
  + * @author Costin Manolache
    */
   
   public class BaseNotificationBroadcaster implements NotificationBroadcaster {
  @@ -258,6 +258,31 @@
   
       }
   
  +
  +    // -------------------- Internal Extensions   --------------------
  +
  +    // Fast access. First index is the hook type
  +    // ( FixedNotificationFilter.getType() ).
  +    NotificationListener hooks[][]=new NotificationListener[20][];
  +    int hookCount[]=new int[20];
  +
  +    private synchronized void registerNotifications( FixedNotificationFilter filter ) {
  +        String names[]=filter.getNames();
  +        Registry reg=Registry.getRegistry();
  +        for( int i=0; i<names.length; i++ ) {
  +            int code=reg.getNotificationCode(null, names[i]);
  +            if( hooks.length < code ) {
  +                // XXX reallocate
  +                throw new RuntimeException( "Too many hooks " + code );
  +            }
  +            NotificationListener listeners[]=hooks[code];
  +            if( listeners== null ) {
  +
  +            }
  +
  +
  +        }
  +    }
   
   }
   
  
  
  
  1.3       +4 -4      jakarta-commons/modeler/src/java/org/apache/commons/modeler/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/Main.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Main.java	11 Jan 2003 07:30:06 -0000	1.2
  +++ Main.java	21 Jan 2003 00:33:45 -0000	1.3
  @@ -119,7 +119,7 @@
           File fileF=new File( file );
           URL url=new URL("file", null, fileF.getAbsolutePath());
   
  -        reg.loadDescriptors( type, url);
  +        reg.loadDescriptors( type, url, null);
       }
   
       public static void main( String args[] ) {
  
  
  
  1.15      +200 -200  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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Registry.java	11 Jan 2003 07:23:29 -0000	1.14
  +++ Registry.java	21 Jan 2003 00:33:45 -0000	1.15
  @@ -63,7 +63,6 @@
   
   import java.io.*;
   import java.net.*;
  -import java.lang.reflect.*;
   import java.util.*;
   
   import javax.management.*;
  @@ -71,6 +70,7 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.apache.commons.modeler.modules.ModelerSource;
   
   /**
    * <p>Registry for MBean descriptor information.  This class implements
  @@ -85,6 +85,28 @@
    * @author Costin Manolache
    */
   public final class Registry {
  +    /**
  +     * The Log instance to which we will write our log messages.
  +     */
  +    private static Log log = LogFactory.getLog(Registry.class);
  +    /**
  +     * The registry instance created by our factory method the first time
  +     * it is called.
  +     */
  +    private static Registry registry = null;
  +
  +
  +    /**
  +     * The <code>MBeanServer</code> instance that we will use to register
  +     * management beans.
  +     */
  +    private MBeanServer server = null;
  +
  +    /**
  +     * The set of ManagedBean instances for the beans this registry
  +     * knows about, keyed by name.
  +     */
  +    private HashMap descriptors = new HashMap();
   
   
       // ----------------------------------------------------------- Constructors
  @@ -100,35 +122,32 @@
   
       }
   
  -
  -    // ----------------------------------------------------- Instance Variables
  -
  -
  -    /**
  -     * The set of ManagedBean instances for the beans this registry
  -     * knows about, keyed by name.
  -     */
  -    private HashMap descriptors = new HashMap();
  -
  -
       /**
  -     * The Log instance to which we will write our log messages.
  +     * Factory method to create (if necessary) and return our
  +     * <code>Registry</code> instance.
        */
  -    private static Log log = LogFactory.getLog(Registry.class);
  +    public synchronized static Registry getRegistry() {
   
  +        if (registry == null) {
  +            log.debug("Creating new Registry instance");
  +            registry = new Registry();
  +        }
  +        return (registry);
   
  -    // --------------------------------------------------------- Public Methods
  +    }
   
  +    // -------------------- Metadata   --------------------
   
       /**
  -     * Add a new bean to the set of beans known to this registry.
  +     * Add a new bean metadata to the set of beans known to this registry.
        *
        * @param bean The managed bean to be added
  +     * @since 1.0
        */
       public void addManagedBean(ManagedBean bean) {
           // called from digester
  +        // XXX Use group + name
           descriptors.put(bean.getName(), bean);
  -
       }
   
   
  @@ -137,22 +156,23 @@
        * bean name, if any; otherwise return <code>null</code>.
        *
        * @param name Name of the managed bean to be returned
  +     * @since 1.0
  +     * XXX Group ?? Use Group + Type
        */
       public ManagedBean findManagedBean(String name) {
  -
           return ((ManagedBean) descriptors.get(name));
  -
       }
   
   
       /**
        * Return the set of bean names for all managed beans known to
        * this registry.
  +     *
  +     * @since 1.0
  +     * XXX Use the group
        */
       public String[] findManagedBeans() {
  -
           return ((String[]) descriptors.keySet().toArray(new String[0]));
  -
       }
   
   
  @@ -162,6 +182,7 @@
        *
        * @param group Name of the group of interest, or <code>null</code>
        *  to select beans that do <em>not</em> belong to a group
  +     * @since 1.0
        */
       public String[] findManagedBeans(String group) {
   
  @@ -185,56 +206,56 @@
        * Remove an existing bean from the set of beans known to this registry.
        *
        * @param bean The managed bean to be removed
  +     * @since 1.0
  +     * TODO: change this to use group/name
        */
       public void removeManagedBean(ManagedBean bean) {
  -
           descriptors.remove(bean.getName());
  -
       }
   
  -
  -    // ------------------------------------------------------- Static Variables
  -
  +    // -------------------- Access the mbean server  --------------------
   
       /**
  -     * The registry instance created by our factory method the first time
  -     * it is called.
  +     * Factory method to create (if necessary) and return our
  +     * <code>MBeanServer</code> instance.
  +     *
  +     * @since 1.0
  +     * @deprecated Use the instance method
        */
  -    private static Registry registry = null;
  -
  +    public static MBeanServer getServer() {
  +        return Registry.getRegistry().getMBeanServer();
  +    }
   
       /**
  -     * The <code>MBeanServer</code> instance that we will use to register
  -     * management beans.
  +     * Set the <code>MBeanServer</code> to be utilized for our
  +     * registered management beans.
  +     *
  +     * @param mbeanServer The new <code>MBeanServer</code> instance
  +     * @since 1.0
  +     * @deprecated Use the instance method
        */
  -    private static MBeanServer server = null;
  -
  -
  -
  -    // --------------------------------------------------------- Static Methods
  +    public static void setServer(MBeanServer mbeanServer) {
  +        Registry.getRegistry().setServer(mbeanServer);
  +    }
   
       /**
  -     * Factory method to create (if necessary) and return our
  -     * <code>Registry</code> instance.
  +     * Set the <code>MBeanServer</code> to be utilized for our
  +     * registered management beans.
  +     *
  +     * @param server The new <code>MBeanServer</code> instance
  +     * @since 2.0
        */
  -    public synchronized static Registry getRegistry() {
  -
  -        if (registry == null) {
  -            log.debug("Creating new Registry instance");
  -            registry = new Registry();
  -        }
  -        return (registry);
  -
  +    public void setMBeanServer( MBeanServer server ) {
  +        this.server=server;
       }
   
  -    // XXX This should be decoupled - Registry should only deal with
  -    // type info, and it may be nice to not depend directly on JMX.
  -
       /**
        * Factory method to create (if necessary) and return our
        * <code>MBeanServer</code> instance.
  +     *
  +     * @since 2.0
        */
  -    public synchronized static MBeanServer getServer() {
  +    public synchronized MBeanServer getMBeanServer() {
           long t1=System.currentTimeMillis();
   
           if (server == null) {
  @@ -249,6 +270,8 @@
           return (server);
       }
   
  +    // -------------------- Loading data from different sources  --------------
  +
       /**
        * Load the registry from the XML input found in the specified input
        * stream.
  @@ -262,105 +285,49 @@
        */
       public static void loadRegistry(InputStream stream) throws Exception {
           Registry registry = getRegistry();
  -        registry.loadDescriptors( stream, "MbeansDescriptorsDOM" );
  +        registry.loadDescriptors( "MbeansDescriptorsDOMSource", stream, null );
       }
   
   
  -    /** Source for descriptor data. More sources can be added.
  +    /**
  +     * Load the registry from the XML input found in the specified input
  +     * stream.
        *
  +     * @param type The type of information to load. A name of a bean or
  +     *      a local type.
  +     * @param source InputStream or URL to be loaded
  +     *
  +     * @exception Exception if any parsing or processing error occurs
  +     * @since 2.0
        */
  -    public static class DescriptorSource {
  -
  -        public void loadDescriptors( Registry registry, String location,
  -                                     String type, Object source)
  -            throws Exception
  -        {
  -            // TODO
  -        }
  -    }
  -
  -    private DescriptorSource getDescriptorSource( String type )
  -        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);
  -
  -        Class c=Class.forName( sourceClassName );
  -        DescriptorSource ds=(DescriptorSource)c.newInstance();
  -        return ds;
  -    }
  -
  -    public void loadDescriptors( String type, Object source )
  +    public void loadDescriptors( String sourceType, Object source, String param)
           throws Exception
       {
           log.trace("loadDescriptors " + source );
  +        ModelerSource ds=getModelerSource(sourceType);
   
           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);
  +            ds.loadDescriptors(this, url.toString(), param, stream);
           }
   
           if( source instanceof InputStream ) {
  -            DescriptorSource ds=getDescriptorSource(type);
  -            ds.loadDescriptors(this, null, type, (InputStream)source);
  +            ds.loadDescriptors(this, null, param, source);
           }
  -    }
  -
  -    /**
  -     * Load the registry from the XML input found in the specified input
  -     * stream.
  -     *
  -     * @param stream InputStream containing the registry configuration
  -     *  information
  -     *
  -     * @exception Exception if any parsing or processing error occurs
  -     * @since 1.0
  -     */
  -    public void loadDescriptors(InputStream stream, String type)
  -        throws Exception
  -    {
  -        loadDescriptors( type, stream );
  -    }
   
  -    /**
  -     * Set the <code>MBeanServer</code> to be utilized for our
  -     * registered management beans.
  -     *
  -     * @param mbeanServer The new <code>MBeanServer</code> instance
  -     */
  -    public static void setServer(MBeanServer mbeanServer) {
  -        server = mbeanServer;
  -    }
  -
  -
  -    // ---------------------- BaseRegistry overrides --------------------------
  -    public Object getMBeanServer() {
  -        return getServer();
  +        if( source instanceof Class ) {
  +            ds.loadDescriptors(this, ((Class)source).getName(), param, source);
  +        }
       }
   
  +    // -------------------- Instance registration  --------------------
   
       /** Main registration method
        *
  +     * If the metadata is not found, introspection will be used to generate
  +     * it automatically.
  +     *
        */
       public void registerComponent(Object bean, String domain, String type,
                                     String name)
  @@ -373,12 +340,17 @@
               }
               ManagedBean managed = registry.findManagedBean(type);
               if( managed==null ) {
  -                // TODO: check package and parent packages
  -
  +                // check package and parent packages
  +                findDescriptor( bean );
  +                managed=findManagedBean(type);
                   // TODO: check super-class
  -
  +            }
  +            if( managed==null ) {
                   // introspection
  -                managed=createManagedBean(domain, bean.getClass(), type);
  +                loadDescriptors("MbeansDescriptorsIntrospectionSource",
  +                        bean.getClass(), type);
  +
  +                managed=findManagedBean(type);
                   managed.setName( type );
                   addManagedBean(managed);
               }
  @@ -389,16 +361,24 @@
               sb.append( domain ).append(":");
               sb.append( name );
               nameStr=sb.toString();
  -            getServer().registerMBean( mbean, new ObjectName( nameStr ));
  +            ObjectName oname=new ObjectName( nameStr );
  +
  +            if(  getServer().isRegistered( oname )) {
  +                if( log.isDebugEnabled())
  +                    log.debug("Unregistering existing component " + oname );
  +                getServer().unregisterMBean( oname );
  +            }
  +
  +            getServer().registerMBean( mbean, oname);
           } catch( Exception ex) {
  -            log.error("Error registering " + nameStr );
  +            log.error("Error registering " + nameStr, ex );
               throw ex;
           }
       }
   
  -    public void unregisterComponent( String name ) {
  +    public void unregisterComponent( String domain, String name ) {
           try {
  -            ObjectName oname=new ObjectName( name );
  +            ObjectName oname=new ObjectName( domain + ":" + name );
   
               // XXX remove from our tables.
               getServer().unregisterMBean( oname );
  @@ -407,28 +387,13 @@
           }
       }
   
  -
  -    public String registerMBean( String domain, String name ) {
  -        try {
  -            // XXX use aliases, suffix only, proxy.getName(), etc
  -            String fullName=domain + ": " +  name;
  -            ObjectName oname=new ObjectName( fullName );
  -
  -            if(  getServer().isRegistered( oname )) {
  -                log.info("Unregistering " + oname );
  -                getServer().unregisterMBean( oname );
  -            }
  -            getServer().registerMBean( this, oname );
  -            return fullName;
  -        } catch( Throwable t ) {
  -            log.error( "Error creating mbean ", t );
  -            return null;
  -        }
  -    }
  -
  +    // -------------------- Experimental: discovery  --------------------
       public static String MODELER_MANIFEST="/META-INF/modeler-mbeans.xml";
   
  -    /** Discover all META-INF/modeler.xml files in classpath and register the components
  +    /** Discover all META-INF/modeler.xml files in classpath and register
  +     * the components
  +     *
  +     * @since EXPERIMENTAL
        */
       public void loadDescriptors(ClassLoader cl, String type) {
           try {
  @@ -437,72 +402,107 @@
                   URL url=(URL)en.nextElement();
                   InputStream is=url.openStream();
                   if( log.isDebugEnabled()) log.debug("Loading " + url);
  -                loadDescriptors(is, "modeler" );
  +                loadDescriptors("MBeansDescriptorDOMSource", is, null );
               }
           } catch( Exception ex ) {
               ex.printStackTrace();
           }
       }
   
  +    // -------------------- Support for unique names  --------------------
  +
  +    // Store all objects that have been registered via modeler
  +    // it is used to generate unique names automatically - using seq=
  +    // scheme
  +    Hashtable instances=new Hashtable();
  +
       /**
  -     *  todo Find if the 'className' is the name of the MBean or
  -     *       the real class ( I suppose first ).
  -     *  todo Read (optional) descriptions from a .properties, generated
  -     *       from source.
  -     *  todo Deal with constructors.
  +     * Help manage multiple instances with the same name prefix.
        *
        */
  -    public ManagedBean createManagedBean(String domain, Class realClass,
  -                                         String type)
  -    {
  -        try {
  -            DescriptorSource ds=getDescriptorSource("MbeansDescriptorsIntrospection");
  -            ds.loadDescriptors(this, type, type, realClass);
  -            if( log.isDebugEnabled())
  -                log.debug("Loading " + type + " " + realClass.getName());
  -            return findManagedBean(type);
  -        } catch( Exception ex ) {
  -            ex.printStackTrace();
  +    public int generateSeqNumber(String name) {
  +        //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 null;
  +        return seq;
       }
   
  -    /** Find the 'type' for this class
  +    // -------------------- Notification codes  --------------------
  +
  +    // per registry
  +    private int notificationId=0;
  +    private Hashtable notificationCodes=new Hashtable();
  +
  +    /** Return an int ID for the notification name. Used for indexed
  +     * access.
        *
  +     * @param domain Not used currently
  +     * @param name  Type of the notification
  +     * @return
        */
  -    public String getType( String domain, Class realClass ) {
  -        // first look at explicit mappings ( exceptions in MBeanUtils )
  +    public synchronized int getNotificationCode( String domain, String name) {
  +        Integer i=(Integer)notificationCodes.get(name);
  +        if( i!= null ) return i.intValue();
   
  -        // We could also look up super classes and locate one we know about
  +        int code=notificationId++;
  +        notificationCodes.put( name, new Integer( code ));
  +        return code;
  +    }
   
  -        // We could use the domain as a discriminator
  +    // -------------------- Implementation methods  --------------------
   
  -        String name=realClass.getName();
  -        name=name.substring( name.lastIndexOf( ".") + 1 );
  +    /** Lookup the component descriptor in the package and
  +     * in the parent packages.
  +     *
  +     * @param bean
  +     * @return
  +     */
  +    private boolean findDescriptor( Object bean ) {
  +        String className=bean.getClass().getName();
  +        String res=className.replace( '.', '/');
  +        int lastComp=res.lastIndexOf( "/");
  +        if( lastComp <= 0 ) return false;
   
  +        String packageName=res.substring(0, lastComp);
  +        String descriptors=packageName + "/mbeans-descriptors.xml";
  +        if( log.isDebugEnabled() )
  +            log.debug( "Finding " + descriptors );
   
  -        return name;
  +        URL dURL=bean.getClass().getClassLoader().getResource( descriptors );
  +        if( dURL == null )
  +            return false;
  +
  +        log.info( "Found " + dURL);
  +        try {
  +            loadDescriptors("MbeansDescriptorsDOMSource", dURL, null);
  +        } catch(Exception ex ) {
  +            log.error("Error loading " + dURL);
  +        }
  +
  +        return false;
       }
   
  -    // 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 ));
  +    private ModelerSource getModelerSource( String type )
  +            throws Exception
  +    {
  +        if( type==null ) type="MbeansDescriptorsDOMSource";
  +        if( type.indexOf( ".") < 0 ) {
  +            type="org.apache.commons.modeler.modules." + type;
           }
  -        return "name=" + name + ",seq=" + seq;
  +
  +        Class c=Class.forName( type );
  +        ModelerSource ds=(ModelerSource)c.newInstance();
  +        return ds;
       }
  +
  +
   }
  
  
  
  1.5       +1 -1      jakarta-commons/modeler/src/java/org/apache/commons/modeler/ant/RegistryTask.java
  
  Index: RegistryTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/ant/RegistryTask.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RegistryTask.java	11 Jan 2003 07:29:07 -0000	1.4
  +++ RegistryTask.java	21 Jan 2003 00:33:45 -0000	1.5
  @@ -119,7 +119,7 @@
               throw new BuildException( "Resource or file attribute required");
           }
   
  -        Registry.getRegistry().loadDescriptors( type, url);
  +        Registry.getRegistry().loadDescriptors( type, url, null);
   
           if( outFile !=null ) {
               FileOutputStream fos=new FileOutputStream(outFile);
  
  
  
  1.3       +37 -2     jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules/MbeansDescriptorsDOMSource.java
  
  Index: MbeansDescriptorsDOMSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules/MbeansDescriptorsDOMSource.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MbeansDescriptorsDOMSource.java	6 Jan 2003 05:56:42 -0000	1.2
  +++ MbeansDescriptorsDOMSource.java	21 Jan 2003 00:33:45 -0000	1.3
  @@ -10,14 +10,49 @@
   import java.io.InputStream;
   
   
  -public class MbeansDescriptorsDOMSource extends Registry.DescriptorSource
  +public class MbeansDescriptorsDOMSource extends ModelerSource
   {
       private static Log log = LogFactory.getLog(MbeansDescriptorsDOMSource.class);
   
  +    Registry registry;
  +    String location;
  +    String type;
  +    Object source;
  +
  +    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 void loadDescriptors( Registry registry, String location,
                                    String type, Object source)
  -        throws Exception
  +            throws Exception
       {
  +        setRegistry(registry);
  +        setLocation(location);
  +        setType(type);
  +        setSource(source);
  +        execute();
  +    }
  +
  +    public void execute() throws Exception {
  +        if( registry==null ) registry=Registry.getRegistry();
  +
           try {
               InputStream stream=(InputStream)source;
               long t1=System.currentTimeMillis();
  
  
  
  1.3       +37 -1     jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules/MbeansDescriptorsDigesterSource.java
  
  Index: MbeansDescriptorsDigesterSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules/MbeansDescriptorsDigesterSource.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MbeansDescriptorsDigesterSource.java	6 Jan 2003 05:56:42 -0000	1.2
  +++ MbeansDescriptorsDigesterSource.java	21 Jan 2003 00:33:45 -0000	1.3
  @@ -8,16 +8,52 @@
   import java.io.InputStream;
   import java.net.URL;
   
  -public class MbeansDescriptorsDigesterSource extends Registry.DescriptorSource
  +public class MbeansDescriptorsDigesterSource extends ModelerSource
   {
       private static Log log =
               LogFactory.getLog(MbeansDescriptorsDigesterSource.class);
   
  +    Registry registry;
  +    String location;
  +    String type;
  +    Object source;
  +
  +    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 void loadDescriptors( Registry registry, String location,
                                    String type, Object source)
               throws Exception
       {
  +        setRegistry(registry);
  +        setLocation(location);
  +        setType(type);
  +        setSource(source);
  +        execute();
  +    }
  +
  +    public void execute() throws Exception {
  +        if( registry==null ) registry=Registry.getRegistry();
  +
           InputStream stream=(InputStream)source;
  +
           long t1=System.currentTimeMillis();
   
           Digester digester = new Digester();
  
  
  
  1.3       +54 -6     jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules/MbeansDescriptorsIntrospectionSource.java
  
  Index: MbeansDescriptorsIntrospectionSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules/MbeansDescriptorsIntrospectionSource.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MbeansDescriptorsIntrospectionSource.java	11 Jan 2003 07:30:06 -0000	1.2
  +++ MbeansDescriptorsIntrospectionSource.java	21 Jan 2003 00:33:45 -0000	1.3
  @@ -12,16 +12,51 @@
   import java.lang.reflect.Modifier;
   import java.util.Hashtable;
   import java.util.Enumeration;
  +import javax.management.ObjectName;
   
   
  -public class MbeansDescriptorsIntrospectionSource extends Registry.DescriptorSource
  +public class MbeansDescriptorsIntrospectionSource extends ModelerSource
   {
       private static Log log = LogFactory.getLog(MbeansDescriptorsIntrospectionSource.class);
   
  +    Registry registry;
  +    String location;
  +    String type;
  +    Object source;
  +
  +    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 void loadDescriptors( Registry registry, String location,
                                    String type, Object source)
  -        throws Exception
  +            throws Exception
       {
  +        setRegistry(registry);
  +        setLocation(location);
  +        setType(type);
  +        setSource(source);
  +        execute();
  +    }
  +
  +    public void execute() throws Exception {
  +        if( registry==null ) registry=Registry.getRegistry();
           try {
               ManagedBean managed=createManagedBean(registry, null, (Class)source, type);
               if( managed==null ) return;
  @@ -38,6 +73,11 @@
   
       // ------------ Implementation for non-declared introspection classes
   
  +    static Hashtable specialMethods=new Hashtable();
  +    static {
  +        specialMethods.put( "preDeregister", "");
  +        specialMethods.put( "postDeregister", "");
  +    }
   
       // createMBean == registerClass + registerMBean
   
  @@ -49,7 +89,8 @@
               ret == Long.TYPE ||
               ret == java.io.File.class ||
               ret == Boolean.class ||
  -            ret == Boolean.TYPE
  +            ret == Boolean.TYPE ||
  +            ret == ObjectName.class
               ;
       }
   
  @@ -97,6 +138,11 @@
                           log.debug("Wrong param count " + name + " " + params.length);
                       continue;
                   }
  +                if( ! supportedType( params[0] ) ) {
  +                    if( log.isDebugEnabled() )
  +                        log.debug("Unsupported type " + methods[j] + " " + params[0]);
  +                    continue;
  +                }
                   if( ! Modifier.isPublic( methods[j].getModifiers() ) ) {
                       if( log.isDebugEnabled())
                           log.debug("Not public " + name);
  @@ -113,6 +159,8 @@
                       continue;
                   if( ! Modifier.isPublic( methods[j].getModifiers() ) )
                       continue;
  +                if( specialMethods.get( methods[j].getName() ) != null )
  +                    continue;
                   invokeAttMap.put( name, methods[j]);
               }
           }
  @@ -126,7 +174,9 @@
        * XXX Deal with constructors
        *
        */
  -    public ManagedBean createManagedBean(Registry registry, String domain, Class realClass, String type) {
  +    public ManagedBean createManagedBean(Registry registry, String domain,
  +                                         Class realClass, String type)
  +    {
           ManagedBean mbean= new ManagedBean();
   
           Method methods[]=null;
  @@ -142,8 +192,6 @@
           methods = realClass.getMethods();
   
           initMethods(realClass, methods, attMap, getAttMap, setAttMap, invokeAttMap );
  -
  -        if( type==null) type=registry.generateSeqName(domain, realClass);
   
           try {
   
  
  
  
  1.3       +35 -2     jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules/MbeansDescriptorsSerSource.java
  
  Index: MbeansDescriptorsSerSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules/MbeansDescriptorsSerSource.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MbeansDescriptorsSerSource.java	15 Jan 2003 00:36:31 -0000	1.2
  +++ MbeansDescriptorsSerSource.java	21 Jan 2003 00:33:45 -0000	1.3
  @@ -13,14 +13,47 @@
   import java.net.URL;
   
   
  -public class MbeansDescriptorsSerSource extends Registry.DescriptorSource
  +public class MbeansDescriptorsSerSource extends ModelerSource
   {
       private static Log log = LogFactory.getLog(MbeansDescriptorsSerSource.class);
  +    Registry registry;
  +    String location;
  +    String type;
  +    Object source;
  +
  +    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 void loadDescriptors( Registry registry, String location,
                                    String type, Object source)
  -        throws Exception
  +            throws Exception
       {
  +        setRegistry(registry);
  +        setLocation(location);
  +        setType(type);
  +        setSource(source);
  +        execute();
  +    }
  +
  +    public void execute() throws Exception {
  +        if( registry==null ) registry=Registry.getRegistry();
           long t1=System.currentTimeMillis();
           try {
               InputStream stream=null;
  
  
  
  1.4       +35 -2     jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules/MbeansSource.java
  
  Index: MbeansSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/modules/MbeansSource.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MbeansSource.java	6 Jan 2003 05:56:42 -0000	1.3
  +++ MbeansSource.java	21 Jan 2003 00:33:45 -0000	1.4
  @@ -15,14 +15,47 @@
    *  The format is an extended version of MLET.
    *
    */
  -public class MbeansSource extends Registry.DescriptorSource
  +public class MbeansSource extends ModelerSource
   {
       private static Log log = LogFactory.getLog(MbeansSource.class);
  +    Registry registry;
  +    String location;
  +    String type;
  +    Object source;
  +
  +    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 void loadDescriptors( Registry registry, String location,
                                    String type, Object source)
  -        throws Exception
  +            throws Exception
       {
  +        setRegistry(registry);
  +        setLocation(location);
  +        setType(type);
  +        setSource(source);
  +        execute();
  +    }
  +
  +    public void execute() throws Exception {
  +        if( registry==null ) registry=Registry.getRegistry();
           try {
               InputStream stream=(InputStream)source;
               long t1=System.currentTimeMillis();
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>