1 16 17 package org.apache.commons.modeler.ant; 18 19 import javax.management.Attribute ; 20 import javax.management.MBeanServer ; 21 import javax.management.ObjectName ; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 import org.apache.commons.modeler.Registry; 26 import org.apache.tools.ant.Task; 27 28 32 public class JmxSet extends Task { 33 private static Log log = LogFactory.getLog(JmxSet.class); 34 35 String attribute; 36 String value; 37 String valueRef; 38 Object objValue; 39 String objectName; 40 ObjectName oname; 41 String type; 42 43 44 public JmxSet() { 45 } 46 47 public void setAttribute(String attribute) { 48 this.attribute = attribute; 49 } 50 51 public void setName( String name ) { 52 this.attribute=name; 53 } 54 55 public String getName() { 56 return attribute; 57 } 58 59 public void setValue(String value) { 60 this.value = value; 61 } 62 63 public void addText( String value ) { 64 this.value=value; 65 } 66 67 public void setValueRef(String valueRef) { 68 this.valueRef = valueRef; 69 } 70 71 public void setType(String type) { 72 this.type = type; 73 } 74 75 public void setObjValue(Object objValue) { 76 this.objValue = objValue; 77 } 78 79 public void setObjectName(String name) { 80 this.objectName = name; 81 } 82 83 public void setObjectName( ObjectName oname ) { 84 this.oname=oname; 85 } 86 87 public void execute() { 88 try { 89 Registry registry=Registry.getRegistry(); 90 MBeanServer server=registry.getMBeanServer(); 91 92 if( oname==null ) 93 oname=new ObjectName (objectName); 94 if( type==null ) { 95 type=registry.getType(oname, attribute); 96 if( log.isDebugEnabled()) 97 log.debug("Discovered type " + type); 98 } 99 100 if( objValue==null && valueRef != null ) { 102 objValue=project.getReference(valueRef); 103 } 104 if( objValue==null ) { 105 objValue=registry.convertValue(type, value); 106 107 } 108 if( log.isDebugEnabled()) 109 log.debug("Setting " + oname + " " + attribute + " " + 110 objValue); 111 server.setAttribute(oname, new Attribute (attribute, objValue)); 112 113 } catch(Exception ex) { 114 ex.printStackTrace(); 115 } 116 } 117 118 } 119 | Popular Tags |