KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > core > ivm > IntraVmHandle


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

45 package org.openejb.core.ivm;
46
47 import java.io.ObjectStreamException JavaDoc;
48
49 import javax.ejb.EJBHome JavaDoc;
50 import javax.ejb.EJBObject JavaDoc;
51
52 import org.openejb.util.proxy.ProxyManager;
53
54 /**
55  * IntraVM implementation of the interface javax.ejb.Handle
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 IntraVmHandle implements java.io.Serializable JavaDoc, javax.ejb.HomeHandle JavaDoc, javax.ejb.Handle JavaDoc {
61     /**
62      * The Proxy subclass that represents the bean
63      * deployment's EJBHome or EJBObject.
64      *
65      * @see org.openejb.util.proxy.Proxy
66      */

67     protected Object JavaDoc theProxy;
68
69     /**
70      * Constructs an IntraVmHandle that has no refernce to
71      * an EJBHome or EJBObject.
72      */

73     public IntraVmHandle() {
74         this(null);
75     }
76
77     /**
78      * Constructs an IntraVmHandle that has a refernce to
79      * the specified EJBHome or EJBObject stub/proxy.
80      *
81      * @param proxy
82      */

83     public IntraVmHandle(Object JavaDoc proxy) {
84         this.theProxy = proxy;
85     }
86
87     /**
88      * Sets the EJBHome or EJBObject stub/proxy that this
89      * handle is a reference to.
90      *
91      * @param prxy The proxy object that this handle will reference.
92      */

93     protected void setProxy(Object JavaDoc prxy) {
94         theProxy = prxy;
95     }
96     
97     /**
98      * Returns the stub/proxy referenced by this handle as an EJBHome.
99      *
100      * @return the proxy object this handle is a reference to.
101      */

102     public EJBHome JavaDoc getEJBHome( ) {
103         return(EJBHome JavaDoc)theProxy;
104     }
105     
106     /**
107      * Returns the stub/proxy referenced by this handle as an EJBObject.
108      *
109      * @return the proxy object this handle is a reference to.
110      */

111     public EJBObject JavaDoc getEJBObject( ) {
112         return(EJBObject JavaDoc)theProxy;
113     }
114
115     public Object JavaDoc getPrimaryKey() {
116         return ((BaseEjbProxyHandler) org.openejb.util.proxy.ProxyManager.getInvocationHandler(theProxy)).primaryKey;
117     }
118     
119     /**
120      * If the handle is being copied between bean instances in a RPC
121      * call we use the IntraVmArtifact
122      *
123      * If the handle is referenced by a stateful bean that is being
124      * passivated by the container, we allow this object to be serialized.
125      *
126      * If the handle is serialized outside the core container system, we
127      * allow the application server to handle it.
128      *
129      * @return Object
130      * @exception ObjectStreamException
131      */

132     protected Object JavaDoc writeReplace() throws ObjectStreamException JavaDoc{
133         /*
134          * If the handle is being copied between bean instances in a RPC
135          * call we use the IntraVmArtifact
136          */

137         if(IntraVmCopyMonitor.isIntraVmCopyOperation()){
138             return new IntraVmArtifact(this);
139         /*
140          * If the handle is referenced by a stateful bean that is being
141          * passivated by the container, we allow this object to be serialized.
142          */

143         }else if(IntraVmCopyMonitor.isStatefulPassivationOperation()){
144             return this;
145         /*
146          * If the handle is serialized outside the core container system, we
147          * allow the application server to handle it.
148          */

149         }else{
150             BaseEjbProxyHandler handler = (BaseEjbProxyHandler)ProxyManager.getInvocationHandler(theProxy);
151             if(theProxy instanceof javax.ejb.EJBObject JavaDoc) {
152                 return org.openejb.OpenEJB.getApplicationServer().getHandle(handler.getProxyInfo());
153             } else if(theProxy instanceof javax.ejb.EJBHome JavaDoc) {
154                 return org.openejb.OpenEJB.getApplicationServer().getHomeHandle(handler.getProxyInfo());
155             }else {
156                 throw new RuntimeException JavaDoc("Invalid proxy type. Handles are only supported by EJBObject types in EJB 1.1");
157             }
158         }
159     }
160
161 }
Popular Tags