blob: d908b4c713f74f1d8c21c3e89a316a67481b9950 [file] [log] [blame]
Stephane Frenot410b1f62006-07-20 09:35:19 +00001/*
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 * Copyright 2005 The Apache Software Foundation
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 *
23 */
24package org.apache.felix.mosgi.jmx.rmiconnector.mx4j.remote.rmi;
25
26import java.lang.reflect.Method;
27import java.lang.reflect.Proxy;
28import java.rmi.NoSuchObjectException;
29import java.io.IOException;
30
31import javax.management.MBeanServerConnection;
32import javax.management.remote.JMXServerErrorException;
33
34import org.apache.felix.mosgi.jmx.rmiconnector.mx4j.remote.ClientProxy;
35
36/**
37 * @author <a href="mailto:biorn_steedom@users.sourceforge.net">Simone Bordet</a>
38 * @version $Revision: 1.1.1.1 $
39 */
40public class ClientExceptionCatcher extends ClientProxy
41{
42 private ClientExceptionCatcher(MBeanServerConnection target)
43 {
44 super(target);
45 }
46
47 public static MBeanServerConnection newInstance(MBeanServerConnection target)
48 {
49 ClientExceptionCatcher handler = new ClientExceptionCatcher(target);
50 return (MBeanServerConnection)Proxy.newProxyInstance(handler.getClass().getClassLoader(), new Class[]{MBeanServerConnection.class}, handler);
51 }
52
53 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
54 {
55 try
56 {
57 return super.invoke(proxy, method, args);
58 }
59 catch (NoSuchObjectException x)
60 {
61 // The connection has been already closed by the server
62 throw new IOException("Connection closed by the server");
63 }
64 catch (Exception x)
65 {
66 throw x;
67 }
68 catch (Error x)
69 {
70 throw new JMXServerErrorException("Error thrown during invocation", x);
71 }
72 }
73}