1 14 package org.jmanage.core.management; 15 16 import java.lang.reflect.*; 17 import java.io.Serializable ; 18 19 31 public class JMXInterfaceProxy implements InvocationHandler, Serializable { 32 33 public static Object newProxyInstance(Class clazz, Object object){ 34 assert clazz.isInstance(object); 35 JMXInterfaceProxy proxy = new JMXInterfaceProxy(clazz, object); 36 return Proxy.newProxyInstance( 37 JMXInterfaceProxy.class.getClassLoader(), 38 new Class []{clazz}, 39 proxy); 40 } 41 42 private Class clazz; 43 private Object wrappedObject; 44 45 private JMXInterfaceProxy(Class clazz, Object wrappedObject){ 46 this.clazz = clazz; 47 this.wrappedObject = wrappedObject; 48 } 49 50 public Object invoke(Object proxy, Method method, Object [] args) 51 throws Throwable { 52 53 try { 54 Method wrappedMethod = 55 clazz.getMethod(method.getName(), 56 method.getParameterTypes()); 57 return wrappedMethod.invoke(wrappedObject, args); 58 } catch (InvocationTargetException e) { 59 throw e.getCause(); 60 } 61 } 62 } 63 | Popular Tags |