costin      2003/02/27 20:54:35

  Modified:    modeler/src/java/org/apache/commons/modeler/ant JmxSet.java
                        MLETTask.java ModelerTask.java ant.properties
  Log:
  A bit of refactoring and improvements in the ant tasks, to simplify the
  syntax and take advantage of metadata.
  
  The type is no longer needed ( since we have it anyway ). Duplicated code
  removed. <mbean> can take a "modeler" boolean flag that will add support
  for arbitrary beans ( it was a separate tag before ).
  
  Revision  Changes    Path
  1.5       +24 -14    
jakarta-commons/modeler/src/java/org/apache/commons/modeler/ant/JmxSet.java
  
  Index: JmxSet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/ant/JmxSet.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JmxSet.java       5 Jan 2003 16:38:09 -0000       1.4
  +++ JmxSet.java       28 Feb 2003 04:54:35 -0000      1.5
  @@ -57,6 +57,7 @@
   import org.apache.tools.ant.*;
   import org.apache.commons.logging.LogFactory;
   import org.apache.commons.logging.Log;
  +import org.apache.commons.modeler.Registry;
   
   import javax.management.*;
   import javax.management.MBeanServer;
  @@ -74,6 +75,7 @@
       String valueRef;
       Object objValue;
       String objectName;
  +    ObjectName oname;
       String type;
   
   
  @@ -84,6 +86,14 @@
           this.attribute = attribute;
       }
   
  +    public void setName( String name ) {
  +        this.attribute=name;
  +    }
  +
  +    public String getName() {
  +        return attribute;
  +    }
  +
       public void setValue(String value) {
           this.value = value;
       }
  @@ -108,30 +118,30 @@
           this.objectName = name;
       }
   
  +    public void setObjectName( ObjectName oname ) {
  +        this.oname=oname;
  +    }
   
       public void execute() {
           try {
  -            MBeanServer server=(MBeanServer)project.getReference("jmx.server");
  +            Registry registry=Registry.getRegistry();
  +            MBeanServer server=registry.getMBeanServer();
   
  -            if (server == null) {
  -                if( MBeanServerFactory.findMBeanServer(null).size() > 0 ) {
  -                    
server=(MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);
  -                } else {
  -                    if( log.isDebugEnabled())
  -                        log.debug("Creating mbean server");
  -                    server=MBeanServerFactory.createMBeanServer();
  -                }
  -                project.addReference("jmx.server", server);
  +            if( oname==null )
  +                oname=new ObjectName(objectName);
  +            if( type==null ) {
  +                type=registry.getType(oname, attribute);
  +                if( log.isDebugEnabled())
  +                    log.debug("Discovered type " + type);
               }
   
  -            ObjectName oname=new ObjectName(objectName);
  -
               // XXX convert value, use meta data to find type
  -            if( objValue==null && valueRef != null ) {
  +             if( objValue==null && valueRef != null ) {
                    objValue=project.getReference(valueRef);
                }
                if( objValue==null ) {
  -                 if( type==null) {// string is default
  +                 if( type==null || "java.lang.String".equals( type )) {
  +                     // string is default
                        objValue=value;
                    } else if( "ObjectName".equals( type )) {
                        if( log.isTraceEnabled())
  
  
  
  1.4       +47 -16    
jakarta-commons/modeler/src/java/org/apache/commons/modeler/ant/MLETTask.java
  
  Index: MLETTask.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/ant/MLETTask.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MLETTask.java     5 Jan 2003 16:38:09 -0000       1.3
  +++ MLETTask.java     28 Feb 2003 04:54:35 -0000      1.4
  @@ -83,8 +83,10 @@
       String archive;
       String codebase;
       String objectName;
  +    ObjectName oname;
   
  -    Vector args;
  +    List args=new ArrayList();
  +    List attributes=new ArrayList();
   
       // ant specific
       String loaderRef; // class loader ref
  @@ -93,8 +95,11 @@
       }
   
       public void addArg(Arg arg ) {
  -        if( args==null ) args=new Vector();
  -        args.addElement(arg);
  +        args.add(arg);
  +    }
  +
  +    public void addAttribute( JmxSet arg ) {
  +        attributes.add( arg );
       }
   
   
  @@ -151,36 +156,62 @@
           return server;
       }
   
  +    boolean modeler=false;
  +
  +    public void setModeler(boolean modeler) {
  +        this.modeler = modeler;
  +    }
   
       protected void bindJmx(String objectName, String code,
  -                        String arg0, Vector args)
  +                           String arg0, List args)
               throws Exception
       {
           MBeanServer server=getMBeanServer();
  -        ObjectName oname=new ObjectName( objectName );
  +        oname=new ObjectName( objectName );
  +        if( modeler ) {
  +            Arg codeArg=new Arg();
  +            codeArg.setType("java.lang.String");
  +            codeArg.setValue( code );
  +            if( args==null) args=new ArrayList();
  +            args.add(0, codeArg);
  +            code="org.apache.commons.modeler.BaseModelMBean";
  +        }
  +
  +        Object argsA[]=new Object[ args.size()];
  +        String sigA[]=new String[args.size()];
  +        for( int i=0; i<args.size(); i++ ) {
  +            Arg arg=(Arg)args.get(i);
  +            if( arg.type==null )
  +                arg.type="java.lang.String";
  +            sigA[i]=arg.getType();
  +            argsA[i]=arg.getValue();
  +            // XXX Deal with not string types - IntrospectionUtils
  +        }
   
           // XXX Use the loader ref, if any
  -        if( args==null ) {
  +        if( args.size()==0 ) {
               server.createMBean(code, oname);
           } else {
  -            Object argsA[]=new Object[ args.size()];
  -            String sigA[]=new String[args.size()];
  -            for( int i=0; i<args.size(); i++ ) {
  -                Arg arg=(Arg)args.elementAt(i);
  -                if( arg.type==null )
  -                    arg.type="java.lang.String";
  -                sigA[i]=arg.getType();
  -                argsA[i]=arg.getValue();
  -                // XXX Deal with not string types - IntrospectionUtils
  -            }
               server.createMBean(code, oname, argsA, sigA );
           }
       }
   
  +    public ObjectName getObjectName() {
  +        return oname;
  +    }
   
       public void execute() throws BuildException {
           try {
  +            // create the mbean
               bindJmx( objectName, code, null, args);
  +
  +            // process attributes
  +            for( int i=0; i<attributes.size(); i++ ) {
  +                JmxSet att=(JmxSet)attributes.get(i);
  +                att.setObjectName( oname );
  +                log.info("Setting attribute " + oname + " " + att.getName());
  +                att.execute();
  +            }
           } catch(Exception ex) {
               log.error("Can't create mbean " + objectName, ex);
           }
  
  
  
  1.4       +7 -6      
jakarta-commons/modeler/src/java/org/apache/commons/modeler/ant/ModelerTask.java
  
  Index: ModelerTask.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/ant/ModelerTask.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ModelerTask.java  5 Jan 2003 16:38:09 -0000       1.3
  +++ ModelerTask.java  28 Feb 2003 04:54:35 -0000      1.4
  @@ -81,12 +81,13 @@
               Arg codeArg=new Arg();
               codeArg.setType("java.lang.String");
               codeArg.setValue( code );
  -            if( args==null) args=new Vector();
  -            args.insertElementAt(codeArg, 0);
  -            super.bindJmx(objectName,
  -                    "org.apache.commons.modeler.BaseModelMBean",
  -                    null,
  -                    args );
  +            if( args==null) args=new ArrayList();
  +            args.add(0, codeArg);
  +            super.execute();
  +//            super.bindJmx(objectName,
  +//                    "org.apache.commons.modeler.BaseModelMBean",
  +//                    null,
  +//                    args );
           } catch(Exception ex) {
               ex.printStackTrace();
           }
  
  
  
  1.2       +3 -0      
jakarta-commons/modeler/src/java/org/apache/commons/modeler/ant/ant.properties
  
  Index: ant.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/modeler/src/java/org/apache/commons/modeler/ant/ant.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ant.properties    5 Jan 2003 16:38:09 -0000       1.1
  +++ ant.properties    28 Feb 2003 04:54:35 -0000      1.2
  @@ -5,6 +5,9 @@
   jmx-operation=org.apache.commons.modeler.ant.JmxInvoke
   mbeans-descriptors=org.apache.commons.modeler.ant.RegistryTask
   
  +jmx-service=org.apache.commons.modeler.ant.ServiceTask
  +service=org.apache.commons.modeler.ant.ServiceTask
  +
   # old names, to be removed
   jmxSet=org.apache.commons.modeler.ant.JmxSet
   jmx=org.apache.commons.modeler.ant.JmxInvoke
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to