KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > client > 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 "OpenEJB" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of The OpenEJB Group. For written permission,
18  * please contact dev@openejb.org.
19  *
20  * 4. Products derived from this Software may not be called "OpenEJB"
21  * nor may "OpenEJB" appear in their names without prior written
22  * permission of The OpenEJB Group. OpenEJB is a registered
23  * trademark of The OpenEJB Group.
24  *
25  * 5. Due credit should be given to the OpenEJB Project
26  * (http://www.openejb.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP 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  * THE OPENEJB GROUP 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 2001 (C) The OpenEJB Group. All Rights Reserved.
42  *
43  * $Id: StatelessEJBObjectHandler.java 1921 2005-06-19 22:40:34Z jlaskowski $
44  */

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

60 public class StatelessEJBObjectHandler extends EJBObjectHandler {
61     
62     // TODO:2: Registry hashtable should be moved here.
63

64     public Object JavaDoc registryId;
65                      
66     public StatelessEJBObjectHandler(){
67     }
68     
69     public StatelessEJBObjectHandler(EJBMetaDataImpl ejb, ServerMetaData server, ClientMetaData client){
70         super(ejb, server, client);
71     }
72     
73     public StatelessEJBObjectHandler(EJBMetaDataImpl ejb, ServerMetaData server, ClientMetaData client, Object JavaDoc primaryKey){
74         super(ejb, server, client, primaryKey);
75     }
76     
77     // This should only be created at the server side and should not reference Container
78
public static Object JavaDoc createRegistryId(Object JavaDoc primKey, Object JavaDoc deployId, String JavaDoc containerID){
79         return "" + deployId + containerID;
80     }
81     
82     public Object JavaDoc getRegistryId(){
83 // if(registryId== null)
84
// registryId= createRegistryId(primaryKey, deploymentID, container);
85
// return registryId;
86
return null;
87     }
88     
89     
90     /**
91      * <B>5.8.3 getPrimaryKey()</B>
92      * <P>
93      * The object identifier of a session object is, in general, opaque
94      * to the client. The result of getPrimaryKey() on a session EJBObject
95      * reference results in java.rmi.RemoteException.
96      * </P>
97      *
98      * @param method
99      * @param args
100      * @param proxy
101      * @return Object
102      * @exception Throwable
103      */

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

143     protected Object JavaDoc isIdentical(Method JavaDoc method, Object JavaDoc[] args, Object JavaDoc proxy) throws Throwable JavaDoc{
144         // TODO:3: Check Authorization to Invoke method.
145
Object JavaDoc arg = ( args.length == 1 )? args[0]: null;
146         
147         if ( arg == null || !(arg instanceof EJBObjectProxy) ) return Boolean.FALSE;
148         EJBObjectProxy proxy2 = (EJBObjectProxy)arg;
149         EJBObjectHandler that = proxy2.getEJBObjectHandler();
150         return new Boolean JavaDoc( this.ejb.deploymentID.equals(that.ejb.deploymentID) );
151     }
152
153     protected Object JavaDoc remove(Method JavaDoc method, Object JavaDoc[] args, Object JavaDoc proxy) throws Throwable JavaDoc{
154 // checkAuthorization(method);
155
invalidateReference();
156         return null;
157     }
158     
159 }
160
Popular Tags