KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > core > entity > EntityEjbHomeHandler


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: EntityEjbHomeHandler.java 2487 2006-02-22 22:05:03Z dblevins $
44  */

45 package org.openejb.core.entity;
46
47 import java.lang.reflect.Method JavaDoc;
48 import java.util.Vector JavaDoc;
49
50 import org.openejb.ProxyInfo;
51 import org.openejb.RpcContainer;
52 import org.openejb.core.ivm.EjbHomeProxyHandler;
53 import org.openejb.core.ivm.EjbObjectProxyHandler;
54 import org.openejb.util.proxy.ProxyManager;
55
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 EntityEjbHomeHandler extends EjbHomeProxyHandler {
67     
68     public EntityEjbHomeHandler(RpcContainer container, Object JavaDoc pk, Object JavaDoc depID){
69         super(container, pk, depID);
70     }
71     
72     protected Object JavaDoc createProxy(ProxyInfo proxyInfo){
73         Object JavaDoc proxy = super.createProxy(proxyInfo);
74         EjbObjectProxyHandler handler = (EjbObjectProxyHandler)ProxyManager.getInvocationHandler(proxy);
75         
76         /*
77         * Register the handle with the BaseEjbProxyHandler.liveHandleRegistry
78         * If the bean is removed by its home or by an identical proxy, then the
79         * this proxy will be automatically invalidated because its properly registered
80         * with the liveHandleRegistry.
81         */

82         registerHandler(handler.getRegistryId(),handler);
83         
84         return proxy;
85     
86     }
87     /**
88      * <P>
89      * Locates and returns a new EJBObject or a collection
90      * of EJBObjects. The EJBObject(s) is a new proxy with
91      * a new handler. This implementation should not be
92      * sent outside the virtual machine.
93      * </P>
94      * <P>
95      * This method propogates to the container
96      * system.
97      * </P>
98      * <P>
99      * The find method is required to be defined
100      * by the bean's home interface of Entity beans.
101      * </P>
102      *
103      * @param method
104      * @param args
105      * @param proxy
106      * @return Returns an new EJBObject proxy and handler
107      * @exception Throwable
108      */

109     protected Object JavaDoc findX(Method JavaDoc method, Object JavaDoc[] args, Object JavaDoc proxy) throws Throwable JavaDoc {
110         Object JavaDoc retValue = container.invoke(deploymentID,method,args,null, getThreadSpecificSecurityIdentity());
111
112         if ( retValue instanceof java.util.Collection JavaDoc ) {
113             Object JavaDoc [] proxyInfos = ((java.util.Collection JavaDoc)retValue).toArray();
114             Vector JavaDoc proxies = new Vector JavaDoc();
115             for ( int i = 0; i < proxyInfos.length; i++ ) {
116                 proxies.addElement( createProxy((ProxyInfo)proxyInfos[i]) );
117             }
118             return proxies;
119         }else if ( retValue instanceof org.openejb.util.ArrayEnumeration ) {
120             org.openejb.util.ArrayEnumeration enumeration = (org.openejb.util.ArrayEnumeration) retValue;
121             for ( int i = enumeration.size()-1; i >=0 ; --i ) {
122                 enumeration.set( i, createProxy((ProxyInfo)enumeration.get(i)) );
123             }
124             return enumeration;
125         }else if ( retValue instanceof java.util.Enumeration JavaDoc ) {
126             java.util.Enumeration JavaDoc enumeration = (java.util.Enumeration JavaDoc) retValue;
127             // Don't use Vector, because it contains unnecessary synchronization
128
java.util.List JavaDoc proxies = new java.util.ArrayList JavaDoc();
129             while ( enumeration.hasMoreElements() ) {
130                 proxies.add( createProxy((ProxyInfo)enumeration.nextElement()) );
131             }
132                 return new org.openejb.util.ArrayEnumeration(proxies);
133         } else {
134             org.openejb.ProxyInfo proxyInfo = (org.openejb.ProxyInfo) retValue;
135
136
137             return createProxy(proxyInfo);
138         }
139
140     }
141     /**
142      * <P>
143      * Attempts to remove an EJBObject from the
144      * container system. The EJBObject to be removed
145      * is represented by the primaryKey passed
146      * into the remove method of the EJBHome.
147      * </P>
148      * <P>
149      * This method propogates to the container system.
150      * </P>
151      * <P>
152      * remove(Object primary) is a method of javax.ejb.EJBHome
153      * </P>
154      * <P>
155      * Checks if the caller is authorized to invoke the
156      * javax.ejb.EJBHome.remove on the EJBHome of the
157      * deployment.
158      * </P>
159      *
160      * @param method
161      * @param args
162      * @return Returns null
163      * @exception Throwable
164      * @see javax.ejb.EJBHome
165      * @see javax.ejb.EJBHome#remove
166      */

167     protected Object JavaDoc removeByPrimaryKey(Method JavaDoc method, Object JavaDoc[] args, Object JavaDoc proxy) throws Throwable JavaDoc{
168         Object JavaDoc primKey = args[0];
169         container.invoke(deploymentID, method, args, primKey, getThreadSpecificSecurityIdentity());
170             
171         /*
172         * This operation takes care of invalidating all the EjbObjectProxyHanders associated with
173         * the same RegistryId. See this.createProxy().
174         */

175         invalidateAllHandlers(EntityEjbObjectHandler.getRegistryId(primKey,deploymentID,container));
176         return null;
177     }
178     
179     protected EjbObjectProxyHandler newEjbObjectHandler(RpcContainer container, Object JavaDoc pk, Object JavaDoc depID) {
180         return new EntityEjbObjectHandler(container, pk, depID);
181     }
182     
183 }
184
Popular Tags