KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > jmx > server > ObjectInterfaceInfo


1 package org.oddjob.jmx.server;
2
3 import javax.management.MBeanAttributeInfo JavaDoc;
4 import javax.management.MBeanException JavaDoc;
5 import javax.management.MBeanNotificationInfo JavaDoc;
6 import javax.management.MBeanOperationInfo JavaDoc;
7 import javax.management.MBeanParameterInfo JavaDoc;
8 import javax.management.Notification JavaDoc;
9 import javax.management.ReflectionException JavaDoc;
10
11 import org.oddjob.jmx.client.ObjectInterface;
12
13 /**
14  */

15 public class ObjectInterfaceInfo implements InterfaceInfo {
16     
17     public Class JavaDoc interfaceClass() {
18         return ObjectInterface.class;
19     }
20     
21     public MBeanAttributeInfo JavaDoc[] getMBeanAttributeInfo() {
22         return new MBeanAttributeInfo JavaDoc[0];
23     }
24
25     public MBeanOperationInfo JavaDoc[] getMBeanOperationInfo() {
26         return new MBeanOperationInfo JavaDoc[] {
27             new MBeanOperationInfo JavaDoc("toString", "toString.",
28                         new MBeanParameterInfo JavaDoc[0], String JavaDoc.class.getName(),
29                         MBeanOperationInfo.INFO)
30             };
31     }
32     
33     public MBeanNotificationInfo JavaDoc[] getMBeanNotificationInfo() {
34         return new MBeanNotificationInfo JavaDoc[0];
35     }
36     
37     
38     public InterfaceHandler attach(Object JavaDoc target, OddjobMBean ojmb) {
39         return new ObjectInterfaceHandler(target);
40     }
41
42     class ObjectInterfaceHandler implements InterfaceHandler {
43     
44         private final Object JavaDoc object;
45         
46         ObjectInterfaceHandler(Object JavaDoc object) {
47             this.object = object;
48         }
49         
50         public Object JavaDoc invoke(String JavaDoc actionName, Object JavaDoc[] params, String JavaDoc[] signature) throws MBeanException JavaDoc, ReflectionException JavaDoc {
51             if ("toString".equals(actionName)
52                     && signature.length == 0) {
53                 return object.toString();
54             }
55             else {
56                 throw new ReflectionException JavaDoc(
57                         new IllegalStateException JavaDoc("invoked for an unknown method."),
58                                 actionName);
59             }
60         }
61         
62         public Notification JavaDoc[] getLastNotifications() {
63             return null;
64         }
65         
66         public void destroy() {
67         }
68     }
69 }
Popular Tags