1 16 17 package org.apache.commons.modeler.ant; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.apache.commons.modeler.Registry; 25 import org.apache.tools.ant.BuildException; 26 import org.apache.tools.ant.Task; 27 28 34 public class ServiceTask extends Task { 35 private static Log log = LogFactory.getLog(ServiceTask.class); 36 List mbeans=new ArrayList (); 37 String action; 38 String refId; 39 40 public ServiceTask() { 41 } 42 43 public void addMbean(MLETTask mbean) { 44 mbeans.add(mbean); 45 } 46 47 public List getMbeans() { 48 return mbeans; 49 } 50 51 56 public void setAction(String action) { 57 this.action=action; 58 } 59 60 63 public void setRefId( String ref ) { 64 this.refId=ref; 65 } 66 67 public void execute() throws BuildException { 68 try { 69 Registry reg=Registry.getRegistry(); 70 71 if( refId != null ) { 72 ServiceTask stask=(ServiceTask)project.getReference(refId); 73 } 74 List onames=new ArrayList (); 76 77 for( int i=0; i<mbeans.size(); i++ ) { 78 MLETTask mbean=(MLETTask)mbeans.get(i); 79 mbean.execute(); 80 onames.add( mbean.getObjectName()); 81 } 82 83 if( action==null ) { 84 reg.invoke(onames, "init", false); 86 reg.invoke(onames, "start", false); 87 } else { 88 reg.invoke(onames, action, false ); 89 } 90 91 } catch(Exception ex) { 92 log.error("Error ", ex); 93 } 94 } 95 } 96 | Popular Tags |