KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > security > srp > SRPServerProxy


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.security.srp;
23
24 import java.io.Serializable JavaDoc;
25 import java.lang.reflect.InvocationHandler JavaDoc;
26 import java.lang.reflect.InvocationTargetException JavaDoc;
27 import java.lang.reflect.Method JavaDoc;
28
29 import org.jboss.security.srp.SRPServerInterface;
30
31 /** A serializable proxy that is bound into JNDI with a reference to the
32  RMI implementation of a SRPServerInterface. This allows a client to lookup
33  the interface and not have the RMI stub for the server as it will be downloaded
34  to them when the SRPServerProxy is unserialized.
35
36  @author Scott.Stark@jboss.org
37  @version $Revision: 40096 $
38  */

39 public class SRPServerProxy implements InvocationHandler JavaDoc, Serializable JavaDoc
40 {
41    /** The serial version UID @since 1.3 */
42    private static final long serialVersionUID = 5255628656806648070L;
43
44    private SRPServerInterface server;
45
46    /** Create a SRPServerProxy given the SRPServerInterface that method
47     invocations are to be delegated to.
48     */

49    SRPServerProxy(SRPServerInterface server)
50    {
51       this.server = server;
52    }
53
54    /** The InvocationHandler invoke method. All calls are simply delegated to
55     the SRPServerInterface server object.
56     */

57    public Object JavaDoc invoke(Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args) throws Throwable JavaDoc
58    {
59       Object JavaDoc ret = null;
60       try
61       {
62          ret = method.invoke(server, args);
63       }
64       catch (InvocationTargetException JavaDoc e)
65       {
66          throw e.getTargetException();
67       }
68       catch (Throwable JavaDoc e)
69       {
70          e.printStackTrace();
71          throw e;
72       }
73       return ret;
74    }
75 }
76
Popular Tags