KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.sapia.soto.jmx.config;
2
3 import org.sapia.soto.jmx.MBeanDescriptor;
4
5 import javax.management.MBeanAttributeInfo JavaDoc;
6 import javax.management.MBeanOperationInfo JavaDoc;
7 import javax.management.MBeanParameterInfo JavaDoc;
8
9
10 /**
11  * @author Yanick Duchesne
12  * <dl>
13  * <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>
14  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
15  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
16  * </dl> */

17 public class SomeBean {
18   private String JavaDoc _name;
19
20   public void setName(String JavaDoc name) {
21     _name = name;
22   }
23
24   public String JavaDoc getName() {
25     return _name;
26   }
27
28   public void performOperationOne(String JavaDoc param1, int param2) {
29   }
30
31   public void performOperationTwo(String JavaDoc param1, int param2) {
32   }
33
34   public static void main(String JavaDoc[] args) {
35     try {
36       SomeBean bean = new SomeBean();
37       MBeanDescriptor mbean = MBeanDescriptor.newInstanceFor(bean);
38       Attributes attrs = new Attributes();
39       Attribute a = attrs.createInclude();
40       a.setDescription("The Name");
41       a.setName("name");
42       a.setWritable(false);
43       attrs.init(mbean);
44
45       Operations ops = new Operations();
46       Operation include = ops.createInclude();
47       include.setName("performOperationOne");
48       include.setDescription("Some operation");
49
50       Operation exclude = ops.createExclude();
51       exclude.setName("performOperationTwo");
52       exclude.setDescription("Some operation");
53       ops.init(mbean);
54
55       mbean.init();
56
57       MBeanAttributeInfo JavaDoc[] info = mbean.getMBeanInfo().getAttributes();
58       System.out.println("Operations:");
59
60       for (int i = 0; i < info.length; i++) {
61         System.out.println("==============================");
62         System.out.println(info[i].getName());
63         System.out.println(info[i].getDescription());
64         System.out.println("readable: " + info[i].isReadable() +
65           ", writable: " + info[i].isWritable());
66       }
67
68       MBeanOperationInfo JavaDoc[] opInfo = mbean.getMBeanInfo().getOperations();
69
70       for (int i = 0; i < opInfo.length; i++) {
71         System.out.println("==============================");
72         System.out.println(opInfo[i].getName());
73         System.out.println(opInfo[i].getDescription());
74
75         MBeanParameterInfo JavaDoc[] params = opInfo[i].getSignature();
76
77         for (int j = 0; j < params.length; j++) {
78           System.out.println(params[j].getName() + ", " +
79             params[j].getDescription());
80         }
81       }
82     } catch (Throwable JavaDoc t) {
83       t.printStackTrace();
84     }
85   }
86 }
87
Popular Tags