KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > core > stateful > StatefulEjbObjectHandler


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: StatefulEjbObjectHandler.java 1921 2005-06-19 22:40:34Z jlaskowski $
44  */

45
46
47 package org.openejb.core.stateful;
48
49
50 import java.lang.reflect.Method JavaDoc;
51 import java.rmi.RemoteException JavaDoc;
52
53 import org.openejb.RpcContainer;
54 import org.openejb.core.ivm.EjbObjectProxyHandler;
55 import org.openejb.util.proxy.ProxyManager;
56
57 /**
58  * This InvocationHandler and its proxy are serializable and can be used by
59  * HomeHandle, Handle, and MetaData to persist and revive handles. It maintains
60  * its original client identity which allows the container to be more discerning about
61  * allowing the revieed proxy to be used. See StatefulContaer manager for more details.
62  *
63  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
64  * @author <a HREF="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
65  */

66 public class StatefulEjbObjectHandler extends EjbObjectProxyHandler {
67                      
68     public StatefulEjbObjectHandler(RpcContainer container, Object JavaDoc pk, Object JavaDoc depID){
69         super(container, pk, depID);
70     }
71     
72     public Object JavaDoc getRegistryId(){
73         return primaryKey;
74     }
75     
76         
77     /**
78      * <B>5.8.3 getPrimaryKey()</B>
79      * <P>
80      * The object identifier of a session object is, in general, opaque
81      * to the client. The result of getPrimaryKey() on a session EJBObject
82      * reference results in java.rmi.RemoteException.
83      * </P>
84      *
85      * @param method
86      * @param args
87      * @param proxy
88      * @return Object
89      * @exception Throwable
90      */

91     protected Object JavaDoc getPrimaryKey(Method JavaDoc method, Object JavaDoc[] args, Object JavaDoc proxy) throws Throwable JavaDoc{
92         throw new RemoteException JavaDoc("Session objects are private resources and do not have primary keys");
93     }
94     
95     /**
96      * <B><P>5.8.2 Stateless session beans</P></B>
97      * <P>
98      * All session objects of the same stateless session bean within
99      * the same home have the same object identity, which is assigned
100      * by the container. If a stateless session bean is deployed
101      * multiple times (each deployment results in the creation of a
102      * distinct home), session objects from different homes will have a
103      * different identity.
104      * </P>
105      * <P>
106      * The isIdentical(EJBObject otherEJBObject) method always returns
107      * true when used to compare object references of two session
108      * objects of the same stateless session bean. The following example
109      * illustrates the use of the isIdentical method for a stateless
110      * session object.
111      * </P>
112      * <PRE>
113      * FooHome fooHome = ...; // obtain home of a stateless session bean
114      * Foo foo1 = fooHome.create();
115      * Foo foo2 = fooHome.create();
116      * if (foo1.isIdentical(foo1)) {// this test returns true
117      * ...
118      * }
119      * if (foo1.isIdentical(foo2)) {// this test returns true
120      * ...
121      * }
122      * </PRE>
123      *
124      * @param method
125      * @param args
126      * @param proxy
127      * @return Object
128      * @exception Throwable
129      */

130     protected Object JavaDoc isIdentical(Method JavaDoc method, Object JavaDoc[] args, Object JavaDoc proxy) throws Throwable JavaDoc{
131         checkAuthorization(method);
132         EjbObjectProxyHandler handler = (EjbObjectProxyHandler)ProxyManager.getInvocationHandler(proxy);
133         return new Boolean JavaDoc( primaryKey.equals(handler.primaryKey) );
134     }
135     
136     protected Object JavaDoc remove(Method JavaDoc method, Object JavaDoc[] args, Object JavaDoc proxy) throws Throwable JavaDoc{
137         checkAuthorization(method);
138         Object JavaDoc value = container.invoke(deploymentID, method, args, primaryKey, getThreadSpecificSecurityIdentity());
139         // invalidates all the handler's associated with the same bean identity
140
invalidateAllHandlers(getRegistryId());
141         return value;
142     }
143     
144 }
145
Popular Tags