KickJava   Java API By Example, From Geeks To Geeks.

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


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

36 class StatefulSessionProxy extends LocalProxy
37    implements InvocationHandler JavaDoc
38 {
39    static final long serialVersionUID = -3113762511947535929L;
40    private Object JavaDoc id;
41
42    StatefulSessionProxy(String JavaDoc jndiName, Object JavaDoc id, BaseLocalProxyFactory factory)
43    {
44       super(jndiName, factory);
45       this.id = id;
46    }
47
48    protected Object JavaDoc getId()
49    {
50       return id;
51    }
52
53    public final Object JavaDoc invoke(final Object JavaDoc proxy, final Method JavaDoc m,
54       Object JavaDoc[] args)
55       throws Throwable JavaDoc
56    {
57       if (args == null)
58          args = EMPTY_ARGS;
59
60       // The object identifier of a session object is, in general, opaque to the client.
61
// The result of getPrimaryKey() on a session EJBObject reference results in java.rmi.RemoteException.
62
// The result of getPrimaryKey() on a session EJBLocalObject reference results in javax.ejb.EJBException.
63
if (m.equals(GET_PRIMARY_KEY))
64       {
65          if (proxy instanceof EJBObject JavaDoc)
66          {
67             throw new RemoteException JavaDoc("Call to getPrimaryKey not allowed on session bean");
68          }
69          if (proxy instanceof EJBLocalObject JavaDoc)
70          {
71             throw new EJBException JavaDoc("Call to getPrimaryKey not allowed on session bean");
72          }
73       }
74
75       Object JavaDoc retValue = super.invoke( proxy, m, args );
76       if (retValue == null)
77       {
78          // If not taken care of, go on and call the container
79
retValue = factory.invoke(id, m, args);
80       }
81
82       return retValue;
83    }
84 }
85
Popular Tags