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 Mon, 07 Apr 2003 06:46:58 GMT
costin      2003/04/06 23:46:58

  Modified:    modeler/src/java/org/apache/commons/modeler Registry.java
  Log:
  Few fixes to better deal with the case when the class is not available.
  ( this is very important for "virtual" mbeans or remote mbeans ).
  Also fixed some other conditions that resulted in NPE
  
  Revision  Changes    Path
  1.27      +47 -5     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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- Registry.java	27 Mar 2003 06:18:46 -0000	1.26
  +++ Registry.java	7 Apr 2003 06:46:58 -0000	1.27
  @@ -215,6 +215,7 @@
       {
           if( type==null )
               type=bean.getName();
  +
           ManagedBean managed = registry.findManagedBean(type);
   
           // Search for a descriptor in the same package
  @@ -223,7 +224,7 @@
               if( log.isDebugEnabled() )
                   log.debug( "Looking for descriptor ");
   
  -            findDescriptor( bean );
  +            findDescriptor( bean, type );
   
               managed=findManagedBean(type);
               // TODO: check super-class
  @@ -412,8 +413,14 @@
           }
           String descriptors=res + "/mbeans-descriptors.ser";
   
  +        if( classLoader==null )
  +            classLoader=Thread.currentThread().getContextClassLoader();
  +        if( classLoader==null )
  +            classLoader=this.getClass().getClassLoader();
  +
           URL dURL=classLoader.getResource( descriptors );
   
  +
           if( dURL == null ) {
               descriptors=res + "/mbeans-descriptors.xml";
               dURL=classLoader.getResource( descriptors );
  @@ -784,9 +791,11 @@
        * @param bean
        * @return
        */
  -    private boolean findDescriptor( Class beanClass ) {
  -        String className=beanClass.getName();
  -        String pkg=className;
  +    private boolean findDescriptor( Class beanClass, String pkg ) {
  +
  +        if( beanClass!=null ) {
  +            pkg=beanClass.getName();
  +        }
           while( pkg.indexOf( ".") > 0 ) {
               int lastComp=pkg.lastIndexOf( ".");
               if( lastComp <= 0 ) return false;
  @@ -794,7 +803,10 @@
               if( searchedPaths.get( pkg ) != null ) {
                   return false;
               }
  -            loadDescriptors(pkg, beanClass.getClassLoader());
  +            if( beanClass!=null )
  +                loadDescriptors(pkg, beanClass.getClassLoader());
  +            else
  +                loadDescriptors(pkg, null);
           }
           return false;
       }
  @@ -814,4 +826,34 @@
       }
   
   
  +    /** Convert a string to object, based on type. Used by several
  +     * components. We could provide some pluggability.
  +     * @param type
  +     * @param value
  +     * @return
  +     */ 
  +    public Object convertValue(String type, String value)
  +    {
  +        Object objValue=value;
  +        
  +        if( type==null || "java.lang.String".equals( type )) {
  +            // string is default
  +            objValue=value;
  +        } else if( "javax.management.ObjectName".equals( type ) ||
  +                "ObjectName".equals( type )) {
  +            try {
  +                objValue=new ObjectName( value );
  +            } catch (MalformedObjectNameException e) {
  +                return null;
  +            }
  +        } else if( "java.lang.Integer".equals( type ) ||
  +                "int".equals( type )) {
  +            objValue=new Integer( value );
  +        } else if( "java.lang.Boolean".equals( type ) ||
  +                "boolean".equals( type )) {
  +            objValue=new Boolean( value );
  +        }
  +        return objValue;
  +    }
  +    
   }
  
  
  

---------------------------------------------------------------------
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