1 17 package org.apache.catalina.ant.jmx; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 import javax.management.MBeanServerConnection ; 23 import javax.management.ObjectName ; 24 25 import org.apache.tools.ant.BuildException; 26 27 61 public class JMXAccessorCreateTask extends JMXAccessorTask { 62 64 private String className; 65 private String classLoader; 66 private List args=new ArrayList (); 67 68 70 73 private static final String info = "org.apache.catalina.ant.JMXAccessorCreateTask/1.0"; 74 75 81 public String getInfo() { 82 83 return (info); 84 85 } 86 87 89 92 public String getClassLoader() { 93 return classLoader; 94 } 95 96 99 public void setClassLoader(String classLoaderName) { 100 this.classLoader = classLoaderName; 101 } 102 103 106 public String getClassName() { 107 return className; 108 } 109 110 113 public void setClassName(String className) { 114 this.className = className; 115 } 116 117 public void addArg(Arg arg ) { 118 args.add(arg); 119 } 120 121 124 public List getArgs() { 125 return args; 126 } 127 130 public void setArgs(List args) { 131 this.args = args; 132 } 133 134 136 144 public String jmxExecute(MBeanServerConnection jmxServerConnection) 145 throws Exception { 146 147 if (getName() == null) { 148 throw new BuildException("Must specify a 'name'"); 149 } 150 if ((className == null)) { 151 throw new BuildException( 152 "Must specify a 'className' for get"); 153 } 154 return jmxCreate(jmxServerConnection, getName()); 155 } 156 157 164 protected String jmxCreate(MBeanServerConnection jmxServerConnection, 165 String name) throws Exception { 166 String error = null; 167 Object argsA[] = null; 168 String sigA[] = null; 169 if (args != null) { 170 argsA = new Object [ args.size()]; 171 sigA = new String [args.size()]; 172 for( int i=0; i<args.size(); i++ ) { 173 Arg arg=(Arg)args.get(i); 174 if( arg.type==null) { 175 arg.type="java.lang.String"; 176 sigA[i]=arg.getType(); 177 argsA[i]=arg.getValue(); 178 } else { 179 sigA[i]=arg.getType(); 180 argsA[i]=convertStringToType(arg.getValue(),arg.getType()); 181 } 182 } 183 } 184 if (classLoader != null && !"".equals(classLoader)) { 185 if (isEcho()) { 186 handleOutput("create MBean " + name + " from class " 187 + className + " with classLoader " + classLoader); 188 } 189 if(args == null) 190 jmxServerConnection.createMBean(className, new ObjectName (name), new ObjectName (classLoader)); 191 else 192 jmxServerConnection.createMBean(className, new ObjectName (name), new ObjectName (classLoader),argsA,sigA); 193 194 } else { 195 if (isEcho()) { 196 handleOutput("create MBean " + name + " from class " 197 + className); 198 } 199 if(args == null) 200 jmxServerConnection.createMBean(className, new ObjectName (name)); 201 else 202 jmxServerConnection.createMBean(className, new ObjectName (name),argsA,sigA); 203 } 204 return error; 205 } 206 207 } 208 | Popular Tags |