1 17 18 19 package org.apache.catalina.ant.jmx; 20 21 22 import javax.management.MBeanServerConnection ; 23 import javax.management.ObjectName ; 24 25 import org.apache.tools.ant.BuildException; 26 27 28 58 59 public class JMXAccessorGetTask extends JMXAccessorTask { 60 61 62 64 private String attribute; 65 66 68 71 private static final String info = "org.apache.catalina.ant.JMXAccessorGetTask/1.0"; 72 73 78 public String getInfo() { 79 80 return (info); 81 82 } 83 84 86 89 public String getAttribute() { 90 return attribute; 91 } 92 93 96 public void setAttribute(String attribute) { 97 this.attribute = attribute; 98 } 99 100 101 103 111 public String jmxExecute(MBeanServerConnection jmxServerConnection) 112 throws Exception { 113 114 if (getName() == null) { 115 throw new BuildException("Must specify a 'name'"); 116 } 117 if ((attribute == null)) { 118 throw new BuildException( 119 "Must specify a 'attribute' for get"); 120 } 121 return jmxGet(jmxServerConnection, getName()); 122 } 123 124 125 131 protected String jmxGet(MBeanServerConnection jmxServerConnection,String name) throws Exception { 132 String error = null; 133 if(isEcho()) { 134 handleOutput("MBean " + name + " get attribute " + attribute ); 135 } 136 Object result = jmxServerConnection.getAttribute( 137 new ObjectName (name), attribute); 138 if (result != null) { 139 echoResult(attribute,result); 140 createProperty(result); 141 } else 142 error = "Attribute " + attribute + " is empty"; 143 return error; 144 } 145 } 146 | Popular Tags |