KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > jmx > OperationDescriptor


1 package org.sapia.soto.jmx;
2
3 import java.lang.reflect.Method JavaDoc;
4
5 import java.util.ArrayList JavaDoc;
6 import java.util.List JavaDoc;
7
8 import javax.management.MBeanOperationInfo JavaDoc;
9 import javax.management.MBeanParameterInfo JavaDoc;
10
11
12 /**
13  * An instance of this class generates the <code>MBeanOperationInfo</code>
14  * corresponding to a given MBean operation.
15  * <p>
16  * It allows callers to set a description that will be past to the generated
17  * <code>MBeanOperationInfo</code>.
18  *
19  * @author Yanick Duchesne
20  * <dl>
21  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
22  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
23  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
24  * </dl>
25  */

26 public class OperationDescriptor {
27   private String JavaDoc _name;
28   private String JavaDoc _description = MBeanDescriptor.DEFAULT_DESC;
29   private List JavaDoc _parameters = new ArrayList JavaDoc();
30   private String JavaDoc _type = void.class.getName();
31   private Method JavaDoc _method;
32   private int _impact = MBeanOperationInfo.UNKNOWN;
33
34   /**
35    * Constructor for OperationDescriptor.
36    */

37   public OperationDescriptor() {
38     super();
39   }
40
41   /**
42    * Sets this instance's "impact" value.
43    *
44    * @param impact an "impact" value, as an <code>int</code> that
45    * corresponds to a constant in the MBeanOperationInfo class.
46    */

47   public void setImpact(int impact) {
48     _impact = impact;
49   }
50
51   /**
52    * Sets this instance's description.
53    *
54    * @param desc a description.
55    */

56   public void setDescription(String JavaDoc desc) {
57     _description = desc;
58   }
59
60   /**
61    * Returns the <code>MBeanOperationInfo</code> corresponding to this
62    * instance's MBean operation.
63    *
64    * @return the <code>MBeanOperationInfo</code> corresponding to this
65    * instance.
66    */

67   public MBeanOperationInfo JavaDoc getInfo() {
68     return new MBeanOperationInfo JavaDoc(_name, _description, getParameterInfos(),
69       _type, _impact);
70   }
71
72   /**
73    * Returns this instance's method - corresponding to this instance's operation.
74    */

75   public Method JavaDoc getMethod() {
76     return _method;
77   }
78
79   public String JavaDoc getOperationName() {
80     return _name;
81   }
82
83   public List JavaDoc getParameters() {
84     return _parameters;
85   }
86
87   void setMethod(Method JavaDoc method) {
88     _method = method;
89     _type = method.getReturnType().getName();
90   }
91
92   void setOperationName(String JavaDoc name) {
93     _name = name;
94   }
95
96   MBeanParameterInfo JavaDoc[] getParameterInfos() {
97     MBeanParameterInfo JavaDoc[] infos = new MBeanParameterInfo JavaDoc[_parameters.size()];
98     ParameterDescriptor desc;
99
100     for (int i = 0; i < _parameters.size(); i++) {
101       desc = (ParameterDescriptor) _parameters.get(i);
102       infos[i] = desc.getInfo();
103     }
104
105     return infos;
106   }
107
108   void addParameters(ParameterDescriptor desc) {
109     _parameters.add(desc);
110   }
111
112   public String JavaDoc toString() {
113     return "[ name=" + _name + ", description=" + _description + ", type=" +
114     _type + ", parameters=" + _parameters + " ]";
115   }
116 }
117
Popular Tags