KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > jmx > config > Operations


1 package org.sapia.soto.jmx.config;
2
3 import org.sapia.soto.ConfigurationException;
4 import org.sapia.soto.jmx.MBeanDescriptor;
5 import org.sapia.soto.jmx.OperationDescriptor;
6 import org.sapia.soto.jmx.ParameterDescriptor;
7
8 import java.util.ArrayList JavaDoc;
9 import java.util.List JavaDoc;
10
11 import javax.management.IntrospectionException JavaDoc;
12
13
14 /**
15  * @author Yanick Duchesne
16  * 19-Aug-2003
17  * <dl>
18  * <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>
19  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
20  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
21  * </dl>
22  */

23 public class Operations {
24   private List JavaDoc _includes = new ArrayList JavaDoc();
25   private List JavaDoc _excludes = new ArrayList JavaDoc();
26
27   /**
28    * Constructor for Operations.
29    */

30   public Operations() {
31     super();
32   }
33
34   public void init(MBeanDescriptor mbean)
35     throws IntrospectionException JavaDoc, ConfigurationException {
36     Operation operation;
37     OperationDescriptor desc;
38     List JavaDoc includes = new ArrayList JavaDoc();
39     List JavaDoc descs;
40
41     for (int i = 0; i < _includes.size(); i++) {
42       operation = (Operation) _includes.get(i);
43
44       if (operation.getName() == null) {
45         throw new ConfigurationException(
46           "'name' attribute not specified on 'include' element from JMX operation");
47       }
48
49       includes.addAll(descs = mbean.getOperationDescriptorsFor(
50             operation.getName(), operation.getSig()));
51
52       for (int j = 0; j < descs.size(); j++) {
53         desc = (OperationDescriptor) descs.get(j);
54
55         if (operation.getDescription() != null) {
56           desc.setDescription(operation.getDescription());
57         }
58
59         List JavaDoc paramDescs = desc.getParameters();
60         List JavaDoc params = operation.getParams();
61         Param param;
62         ParameterDescriptor paramDesc;
63
64         if (paramDescs.size() == params.size()) {
65           for (int k = 0; k < params.size(); k++) {
66             param = (Param) params.get(k);
67             paramDesc = (ParameterDescriptor) paramDescs.get(k);
68
69             if (param.getDescription() != null) {
70               paramDesc.setDescription(param.getDescription());
71             }
72
73             if (param.getName() != null) {
74               paramDesc.setName(param.getName());
75             }
76           }
77         }
78       }
79     }
80
81     for (int i = 0; i < _excludes.size(); i++) {
82       operation = (Operation) _excludes.get(i);
83
84       if (operation.getName() == null) {
85         throw new ConfigurationException(
86           "'name' attribute not specified on 'include' element from JMX operation");
87       }
88
89       mbean.removeOperationDescriptorsFor(operation.getName(),
90         operation.getSig());
91     }
92
93     for (int i = 0; i < includes.size(); i++) {
94       mbean.addOperationDescriptor((OperationDescriptor) includes.get(i));
95     }
96   }
97
98   public Operation createInclude() {
99     Operation op = new Operation();
100     _includes.add(op);
101
102     return op;
103   }
104
105   public Operation createExclude() {
106     Operation op = new Operation();
107     _excludes.add(op);
108
109     return op;
110   }
111
112   private static void initParams(Operation op, List JavaDoc paramDescs) {
113     ParameterDescriptor desc;
114     List JavaDoc params = op.getParams();
115     Param p;
116
117     for (int i = 0; i < params.size(); i++) {
118       p = (Param) params.get(i);
119       desc = (ParameterDescriptor) paramDescs.get(i);
120       desc.setDescription(p.getDescription());
121       desc.setName(p.getName());
122     }
123   }
124 }
125
Popular Tags