KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > core > stateless > StatelessEjbObjectHandler


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: StatelessEjbObjectHandler.java 1921 2005-06-19 22:40:34Z jlaskowski $
44  */

45
46
47 package org.openejb.core.stateless;
48
49 import java.lang.reflect.Method JavaDoc;
50 import java.rmi.RemoteException JavaDoc;
51
52 import org.openejb.Container;
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 StatelessEjbObjectHandler extends EjbObjectProxyHandler {
67     public Object JavaDoc registryId;
68                      
69     public StatelessEjbObjectHandler(RpcContainer container, Object JavaDoc pk, Object JavaDoc depID){
70         super(container, pk, depID);
71     }
72     
73     public static Object JavaDoc createRegistryId(Object JavaDoc primKey, Object JavaDoc deployId, Container contnr){
74         return ""+deployId+contnr.getContainerID();
75     }
76     public Object JavaDoc getRegistryId(){
77         if(registryId== null)
78             registryId= createRegistryId(primaryKey, deploymentID, container);
79         return registryId;
80     }
81     
82     
83     /**
84      * <B>5.8.3 getPrimaryKey()</B>
85      * <P>
86      * The object identifier of a session object is, in general, opaque
87      * to the client. The result of getPrimaryKey() on a session EJBObject
88      * reference results in java.rmi.RemoteException.
89      * </P>
90      *
91      * @param method
92      * @param args
93      * @param proxy
94      * @return Object
95      * @exception Throwable
96      */

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

136     protected Object JavaDoc isIdentical(Method JavaDoc method, Object JavaDoc[] args, Object JavaDoc proxy) throws Throwable JavaDoc{
137         checkAuthorization(method);
138         
139         try {
140             EjbObjectProxyHandler handler =
141                 (EjbObjectProxyHandler) ProxyManager.getInvocationHandler(args[0]);
142         return new Boolean JavaDoc( deploymentID.equals(handler.deploymentID) );
143         } catch (Throwable JavaDoc t){
144             return Boolean.FALSE;
145             ///System.out.println("\n\n\n[] isIdentical "+identical+"\n this\t"+deploymentID+"\n that\t"+handler.deploymentID +"\n\n");
146
}
147     }
148
149     protected Object JavaDoc remove(Method JavaDoc method, Object JavaDoc[] args, Object JavaDoc proxy) throws Throwable JavaDoc{
150         checkAuthorization(method);
151         invalidateReference();
152         return null;
153     }
154     
155 }
156
Popular Tags