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/modules MbeansSource.java
Date Fri, 28 Feb 2003 04:56:33 GMT
costin      2003/02/27 20:56:33

  Modified:    modeler/src/java/org/apache/commons/modeler Registry.java
               modeler/src/java/org/apache/commons/modeler/modules
                        MbeansSource.java
  Log:
  Refactoring to avoid method duplications. Added helper methods to find
  info about a method and attribute.
  
  Revision  Changes    Path
  1.21      +43 -3     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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- Registry.java	26 Feb 2003 22:17:32 -0000	1.20
  +++ Registry.java	28 Feb 2003 04:56:32 -0000	1.21
  @@ -350,7 +350,7 @@
       }
   
       public void invoke( List mbeans, String operation, boolean failFirst )
  -            throws Throwable
  +            throws Exception
       {
           if( mbeans==null ) return;
           Iterator itr=mbeans.iterator();
  @@ -368,9 +368,9 @@
                   getMBeanServer().invoke(oN, operation,
                           new Object[] {}, new String[] {});
   
  -            } catch( Throwable t ) {
  +            } catch( Exception t ) {
                   if( failFirst ) throw t;
  -                log.info("Error initializing " + current);
  +                log.info("Error initializing " + current + " " + t.toString());
               }
           }
       }
  @@ -449,6 +449,46 @@
           } catch( Throwable t ) {
               log.error( "Error unregistering mbean ", t );
           }
  +    }
  +
  +    // -------------------- Helpers  --------------------
  +    public String getType( ObjectName oname, String attName )
  +    {
  +        String type=null;
  +        MBeanInfo info=null;
  +        try {
  +            info=server.getMBeanInfo(oname);
  +        } catch (Exception e) {
  +            log.info( "Can't find metadata " + oname );
  +            return null;
  +        }
  +        MBeanAttributeInfo attInfo[]=info.getAttributes();
  +        for( int i=0; i<attInfo.length; i++ ) {
  +            if( attName.equals(attInfo[i].getName())) {
  +                type=attInfo[i].getType();
  +                return type;
  +            }
  +        }
  +        return null;
  +    }
  +
  +    public MBeanOperationInfo getMethodInfo( ObjectName oname, String opName )
  +    {
  +        String type=null;
  +        MBeanInfo info=null;
  +        try {
  +            info=server.getMBeanInfo(oname);
  +        } catch (Exception e) {
  +            log.info( "Can't find metadata " + oname );
  +            return null;
  +        }
  +        MBeanOperationInfo attInfo[]=info.getOperations();
  +        for( int i=0; i<attInfo.length; i++ ) {
  +            if( opName.equals(attInfo[i].getName())) {
  +                return attInfo[i];
  +            }
  +        }
  +        return null;
       }
   
       // -------------------- Experimental: discovery  --------------------
  
  
  
  1.7       +7 -10     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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MbeansSource.java	26 Feb 2003 22:17:32 -0000	1.6
  +++ MbeansSource.java	28 Feb 2003 04:56:32 -0000	1.7
  @@ -211,17 +211,14 @@
                           " " + value);
               ObjectName oname=new ObjectName(objectName);
               // find the type
  -            MBeanInfo info=server.getMBeanInfo(oname);
  -            MBeanAttributeInfo attInfo[]=info.getAttributes();
  -            for( int i=0; i<attInfo.length; i++ ) {
  -                if( attName.equals(attInfo[i].getName())) {
  -                    type=attInfo[i].getType();
  -                    Object valueO=getValueObject( value, type);
  -                    server.setAttribute(oname, new Attribute(attName, valueO));
  -                    return;
  -                }
  +            if( type==null )
  +                type=registry.getType(  oname, attName );
  +            if( type==null ) {
  +                log.info("Can't find attribute " + objectName + " " + attName );
  +            } else {
  +                Object valueO=getValueObject( value, type);
  +                server.setAttribute(oname, new Attribute(attName, valueO));
               }
  -            log.info("Can't find attribute " + objectName + " " + attName );
           } catch( Exception ex) {
               log.error("Error processing attribute " + objectName + " " +
                       attName + " " + value, ex);
  
  
  

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