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