KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > naming > interceptors > ExceptionInterceptor


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.naming.interceptors;
23
24 import java.io.Externalizable JavaDoc;
25 import java.io.IOException JavaDoc;
26
27 import javax.naming.CommunicationException JavaDoc;
28 import javax.naming.NamingException JavaDoc;
29 import javax.naming.ServiceUnavailableException JavaDoc;
30
31 import org.jboss.invocation.Invocation;
32 import org.jboss.proxy.Interceptor;
33
34 /** A client interceptor that handles the wrapping of exceptions to
35  * NamingExceptions
36  *
37  * @author Scott.Stark@jboss.org
38  * @version $Revision: 37459 $
39  */

40 public class ExceptionInterceptor extends Interceptor
41    implements Externalizable JavaDoc
42 {
43    /** The serialVersionUID. @since 1.1.2.1 */
44    private static final long serialVersionUID = 6010013004557885014L;
45
46    /** Handle methods locally on the client
47     *
48     * @param mi
49     * @return
50     * @throws Throwable
51     */

52    public Object JavaDoc invoke(Invocation mi) throws Throwable JavaDoc
53    {
54       Object JavaDoc value = null;
55       try
56       {
57          value = getNext().invoke(mi);
58       }
59       catch(NamingException JavaDoc e)
60       {
61          throw e;
62       }
63       catch(IOException JavaDoc e)
64       {
65          CommunicationException JavaDoc ce = new CommunicationException JavaDoc("Operation failed");
66          ce.setRootCause(e);
67          throw ce;
68       }
69       catch(Throwable JavaDoc t)
70       {
71          ServiceUnavailableException JavaDoc sue = new ServiceUnavailableException JavaDoc("Unexpected failure");
72          sue.setRootCause(t);
73          throw sue;
74       }
75
76       return value;
77    }
78
79 }
80
Popular Tags