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