1 8 9 package mx4j.remote.rmi; 10 11 import java.lang.reflect.Method ; 12 import java.lang.reflect.Proxy ; 13 import java.rmi.NoSuchObjectException ; 14 import java.io.IOException ; 15 16 import javax.management.MBeanServerConnection ; 17 import javax.management.remote.JMXServerErrorException ; 18 19 import mx4j.remote.ClientProxy; 20 21 25 public class ClientExceptionCatcher extends ClientProxy 26 { 27 private ClientExceptionCatcher(MBeanServerConnection target) 28 { 29 super(target); 30 } 31 32 public static MBeanServerConnection newInstance(MBeanServerConnection target) 33 { 34 ClientExceptionCatcher handler = new ClientExceptionCatcher(target); 35 return (MBeanServerConnection )Proxy.newProxyInstance(handler.getClass().getClassLoader(), new Class []{MBeanServerConnection .class}, handler); 36 } 37 38 public Object invoke(Object proxy, Method method, Object [] args) throws Throwable 39 { 40 try 41 { 42 return super.invoke(proxy, method, args); 43 } 44 catch (NoSuchObjectException x) 45 { 46 throw new IOException ("Connection closed by the server"); 48 } 49 catch (Exception x) 50 { 51 throw x; 52 } 53 catch (Error x) 54 { 55 throw new JMXServerErrorException ("Error thrown during invocation", x); 56 } 57 } 58 } 59 | Popular Tags |