KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > remote > rmi > ClientExceptionCatcher


1 /*
2  * Copyright (C) MX4J.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package mx4j.remote.rmi;
10
11 import java.lang.reflect.Method JavaDoc;
12 import java.lang.reflect.Proxy JavaDoc;
13 import java.rmi.NoSuchObjectException JavaDoc;
14 import java.io.IOException JavaDoc;
15
16 import javax.management.MBeanServerConnection JavaDoc;
17 import javax.management.remote.JMXServerErrorException JavaDoc;
18
19 import mx4j.remote.ClientProxy;
20
21 /**
22  * @author <a HREF="mailto:biorn_steedom@users.sourceforge.net">Simone Bordet</a>
23  * @version $Revision: 1.1 $
24  */

25 public class ClientExceptionCatcher extends ClientProxy
26 {
27    private ClientExceptionCatcher(MBeanServerConnection JavaDoc target)
28    {
29       super(target);
30    }
31
32    public static MBeanServerConnection JavaDoc newInstance(MBeanServerConnection JavaDoc target)
33    {
34       ClientExceptionCatcher handler = new ClientExceptionCatcher(target);
35       return (MBeanServerConnection JavaDoc)Proxy.newProxyInstance(handler.getClass().getClassLoader(), new Class JavaDoc[]{MBeanServerConnection JavaDoc.class}, handler);
36    }
37
38    public Object JavaDoc invoke(Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args) throws Throwable JavaDoc
39    {
40       try
41       {
42          return super.invoke(proxy, method, args);
43       }
44       catch (NoSuchObjectException JavaDoc x)
45       {
46          // The connection has been already closed by the server
47
throw new IOException JavaDoc("Connection closed by the server");
48       }
49       catch (Exception JavaDoc x)
50       {
51          throw x;
52       }
53       catch (Error JavaDoc x)
54       {
55          throw new JMXServerErrorException JavaDoc("Error thrown during invocation", x);
56       }
57    }
58 }
59
Popular Tags