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 BaseModelMBean.java Registry.java
Date Sat, 15 Mar 2003 00:34:11 GMT
costin      2003/03/14 16:34:11

  Modified:    modeler  build.xml
               modeler/src/java/org/apache/commons/modeler
                        BaseModelMBean.java Registry.java
  Log:
  Few more fixes. Make the finding of descriptors consistent, fix lookup in
  packages, remove info.
  
  Revision  Changes    Path
  1.12      +2 -2      jakarta-commons/modeler/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/modeler/build.xml,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- build.xml	13 Mar 2003 21:53:44 -0000	1.11
  +++ build.xml	15 Mar 2003 00:34:10 -0000	1.12
  @@ -194,7 +194,7 @@
      description="Clean and compile all components"/>
   
   
  -  <target name="javadoc" depends="compile"
  +  <target name="javadoc" depends="compile" unless="docs-uptodate"
      description="Create component Javadoc documentation">
       <mkdir      dir="${dist.home}"/>
       <mkdir      dir="${dist.home}/docs"/>
  
  
  
  1.16      +5 -18     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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- BaseModelMBean.java	28 Feb 2003 23:39:20 -0000	1.15
  +++ BaseModelMBean.java	15 Mar 2003 00:34:10 -0000	1.16
  @@ -1177,20 +1177,7 @@
               //Thread.currentThread().setContextClassLoader(BaseModelMBean.class.getClassLoader());
               Class c=Class.forName( type);
               resource = c.newInstance();
  -            ManagedBean descriptor=reg.findManagedBean(type);
  -
  -            if( descriptor != null ) {
  -                if( log.isDebugEnabled())
  -                    log.debug("Using descriptor " + type + " " + descriptor);
  -                this.setModelMBeanInfo( descriptor.createMBeanInfo());
  -                return;
  -            }
  -
  -            // Maybe it's a real class name. Use introspection
  -            if( log.isDebugEnabled())
  -                log.debug("Introspecting " + type);
  -            reg.loadDescriptors("MbeansDescriptorsIntrospectionSource", c, type);
  -            descriptor=reg.findManagedBean(type);
  +            ManagedBean descriptor=reg.findManagedBean(c, type);
   
               this.setModelMBeanInfo(descriptor.createMBeanInfo());
           } catch( Throwable ex) {
  
  
  
  1.24      +44 -26    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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- Registry.java	13 Mar 2003 07:05:18 -0000	1.23
  +++ Registry.java	15 Mar 2003 00:34:10 -0000	1.24
  @@ -210,7 +210,39 @@
           return mb;
       }
   
  +    public ManagedBean findManagedBean(Class bean, String type)
  +        throws Exception
  +    {
  +        if( type==null )
  +            type=bean.getName();
  +        ManagedBean managed = registry.findManagedBean(type);
  +
  +        // Search for a descriptor in the same package
  +        if( managed==null ) {
  +            // check package and parent packages
  +            if( log.isDebugEnabled() )
  +                log.debug( "Looking for descriptor ");
  +
  +            findDescriptor( bean );
   
  +            managed=findManagedBean(type);
  +            // TODO: check super-class
  +        }
  +        if( log.isDebugEnabled() )
  +            log.debug( "Managed= "+ managed);
  +
  +        // Still not found - use introspection
  +        if( managed==null ) {
  +            // introspection
  +            loadDescriptors("MbeansDescriptorsIntrospectionSource",
  +                    bean, type);
  +
  +            managed=findManagedBean(type);
  +            managed.setName( type );
  +            addManagedBean(managed);
  +        }
  +        return managed;
  +    }
       /**
        * Return the set of bean names for all managed beans known to
        * this registry.
  @@ -513,6 +545,8 @@
       public void registerComponent(Object bean, ObjectName oname, String type)
              throws Exception
       {
  +        if( log.isDebugEnabled() )
  +            log.debug( "Managed= "+ oname);
   
           if( bean ==null ) {
               log.error("Null component " + oname );
  @@ -524,26 +558,7 @@
                   type=bean.getClass().getName();
               }
   
  -            ManagedBean managed = registry.findManagedBean(type);
  -
  -            if( managed==null ) {
  -                // check package and parent packages
  -                findDescriptor( bean );
  -
  -                managed=findManagedBean(type);
  -                // TODO: check super-class
  -            }
  -
  -            // Still not found - use introspection
  -            if( managed==null ) {
  -                // introspection
  -                loadDescriptors("MbeansDescriptorsIntrospectionSource",
  -                        bean.getClass(), type);
  -
  -                managed=findManagedBean(type);
  -                managed.setName( type );
  -                addManagedBean(managed);
  -            }
  +            ManagedBean managed = registry.findManagedBean(bean.getClass(), type);
   
               // The real mbean is created and registered
               ModelMBean mbean = managed.createMBean(bean);
  @@ -719,30 +734,33 @@
        * @param bean
        * @return
        */
  -    private boolean findDescriptor( Object bean ) {
  -        String className=bean.getClass().getName();
  +    private boolean findDescriptor( Class beanClass ) {
  +        String className=beanClass.getName();
           String res=className.replace( '.', '/');
  -        while( className.indexOf( "/") > 0 ) {
  +        if( log.isDebugEnabled() )
  +            log.debug("Finding descriptor " + res );
  +        while( res.indexOf( "/") > 0 ) {
               int lastComp=res.lastIndexOf( "/");
               if( lastComp <= 0 ) return false;
   
               String packageName=res.substring(0, lastComp);
  +            res=packageName;
               if( searchedPaths.get( packageName ) != null ) {
                   return false;
               }
               String descriptors=packageName + "/mbeans-descriptors.ser";
               if( log.isDebugEnabled() )
                   log.debug( "Finding " + descriptors );
  -            URL dURL=bean.getClass().getClassLoader().getResource( descriptors );
  +            URL dURL=beanClass.getClassLoader().getResource( descriptors );
               if( dURL == null ) {
                   descriptors=packageName + "/mbeans-descriptors.xml";
  -                dURL=bean.getClass().getClassLoader().getResource( descriptors );
  +                dURL=beanClass.getClassLoader().getResource( descriptors );
                   if( dURL == null ) {
                       className=packageName;
                       continue;
                   }
               }
  -            log.info( "Found " + dURL);
  +            log.debug( "Found " + dURL);
               searchedPaths.put( descriptors,  dURL );
               try {
                   if( descriptors.endsWith(".xml" ))
  
  
  

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


Mime
View raw message