01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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;
25: import java.lang.reflect.Method;
26: import java.rmi.RemoteException;
27: import javax.naming.InitialContext;
28: import javax.ejb.EJBObject;
29: import javax.ejb.EJBLocalObject;
30: import javax.ejb.EJBException;
31:
32: /** The EJBLocal proxy for a stateless session
33:
34: @author <a href="mailto:scott.stark@jboss.org">Scott Stark</a>
35: @version $Revision: 57209 $
36: */
37: class StatelessSessionProxy extends LocalProxy implements
38: InvocationHandler {
39: static final long serialVersionUID = 5677941766264344565L;
40:
41: StatelessSessionProxy(String jndiName, BaseLocalProxyFactory factory) {
42: super (jndiName, factory);
43: }
44:
45: protected Object getId() {
46: return jndiName;
47: }
48:
49: public final Object invoke(final Object proxy, final Method m,
50: Object[] args) throws Throwable {
51: Object retValue = null;
52: if (args == null)
53: args = EMPTY_ARGS;
54:
55: // Implement local methods
56: if (m.equals(TO_STRING)) {
57: retValue = jndiName + ":Stateless";
58: } else if (m.equals(EQUALS)) {
59: retValue = invoke(proxy, IS_IDENTICAL, args);
60: } else if (m.equals(HASH_CODE)) {
61: // We base the stateless hash on the hash of the proxy...
62: // MF XXX: it could be that we want to return the hash of the name?
63: retValue = new Integer(this .hashCode());
64: } else if (m.equals(GET_PRIMARY_KEY)) {
65: // The object identifier of a session object is, in general, opaque to the client.
66: // The result of getPrimaryKey() on a session EJBObject reference results in java.rmi.RemoteException.
67: // The result of getPrimaryKey() on a session EJBLocalObject reference results in javax.ejb.EJBException.
68: if (proxy instanceof EJBObject) {
69: throw new RemoteException(
70: "Call to getPrimaryKey not allowed on session bean");
71: }
72: if (proxy instanceof EJBLocalObject) {
73: throw new EJBException(
74: "Call to getPrimaryKey not allowed on session bean");
75: }
76: } else if (m.equals(GET_EJB_HOME)) {
77: InitialContext ctx = new InitialContext();
78: return ctx.lookup(jndiName);
79: } else if (m.equals(IS_IDENTICAL)) {
80: // All stateless beans are identical within a home,
81: // if the names are equal we are equal
82: retValue = isIdentical(args[0], jndiName + ":Stateless");
83: }
84: // If not taken care of, go on and call the container
85: else {
86: retValue = factory.invoke(jndiName, m, args);
87: }
88:
89: return retValue;
90: }
91: }
|