KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > plugins > local > StatelessSessionProxy


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.ejb.plugins.local;
23
24 import java.lang.reflect.InvocationHandler JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26 import java.rmi.RemoteException JavaDoc;
27 import javax.naming.InitialContext JavaDoc;
28 import javax.ejb.EJBObject JavaDoc;
29 import javax.ejb.EJBLocalObject JavaDoc;
30 import javax.ejb.EJBException JavaDoc;
31
32
33 /** The EJBLocal proxy for a stateless session
34
35  @author <a HREF="mailto:scott.stark@jboss.org">Scott Stark</a>
36  @version $Revision: 37459 $
37  */

38 class StatelessSessionProxy extends LocalProxy
39    implements InvocationHandler JavaDoc
40 {
41    static final long serialVersionUID = 5677941766264344565L;
42
43    StatelessSessionProxy(String JavaDoc jndiName, BaseLocalProxyFactory factory)
44    {
45       super(jndiName, factory);
46    }
47    
48    protected Object JavaDoc getId()
49    {
50       return jndiName;
51    }
52    
53    public final Object JavaDoc invoke(final Object JavaDoc proxy, final Method JavaDoc m, Object JavaDoc[] args)
54       throws Throwable JavaDoc
55    {
56       Object JavaDoc retValue = null;
57       if (args == null)
58          args = EMPTY_ARGS;
59       
60       // Implement local methods
61
if (m.equals(TO_STRING))
62       {
63          retValue = jndiName + ":Stateless";
64       }
65       else if (m.equals(EQUALS))
66       {
67          retValue = invoke(proxy, IS_IDENTICAL, args);
68       }
69       else if (m.equals(HASH_CODE))
70       {
71          // We base the stateless hash on the hash of the proxy...
72
// MF XXX: it could be that we want to return the hash of the name?
73
retValue = new Integer JavaDoc(this.hashCode());
74       }
75       else if (m.equals(GET_PRIMARY_KEY))
76       {
77          // The object identifier of a session object is, in general, opaque to the client.
78
// The result of getPrimaryKey() on a session EJBObject reference results in java.rmi.RemoteException.
79
// The result of getPrimaryKey() on a session EJBLocalObject reference results in javax.ejb.EJBException.
80
if (proxy instanceof EJBObject JavaDoc)
81          {
82             throw new RemoteException JavaDoc("Call to getPrimaryKey not allowed on session bean");
83          }
84          if (proxy instanceof EJBLocalObject JavaDoc)
85          {
86             throw new EJBException JavaDoc("Call to getPrimaryKey not allowed on session bean");
87          }
88       }
89       else if (m.equals(GET_EJB_HOME))
90       {
91          InitialContext JavaDoc ctx = new InitialContext JavaDoc();
92          return ctx.lookup(jndiName);
93       }
94       else if (m.equals(IS_IDENTICAL))
95       {
96          // All stateless beans are identical within a home,
97
// if the names are equal we are equal
98
retValue = isIdentical(args[0], jndiName + ":Stateless");
99       }
100       // If not taken care of, go on and call the container
101
else
102       {
103          retValue = factory.invoke(jndiName, m, args);
104       }
105
106       return retValue;
107    }
108 }
109
Popular Tags