KickJava   Java API By Example, From Geeks To Geeks.

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


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: IntraVmMetaData.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
51 import org.openejb.DeploymentInfo;
52 import org.openejb.util.proxy.ProxyManager;
53
54 /**
55  * IntraVM server implementation of the javax.ejb.EJBMetaData interface.
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 IntraVmMetaData implements javax.ejb.EJBMetaData JavaDoc, java.io.Serializable JavaDoc {
61     
62     /**
63      * Constant held by the {@link #type} member variable to
64      * specify that this MetaData implementation represents
65      * an EntityBean.
66      *
67      * @see #type
68      */

69     final public static byte ENTITY = DeploymentInfo.BMP_ENTITY;
70     
71     /**
72      * Constant held by the {@link #type} member variable to
73      * specify that this MetaData implementation represents
74      * a stateful SessionBean.
75      *
76      * @see #type
77      */

78     final public static byte STATEFUL = DeploymentInfo.STATEFUL;
79     
80     /**
81      * Constant held by the {@link #type} member variable to
82      * specify that this MetaData implementation represents
83      * a stateless SessionBean.
84      *
85      * @see #type
86      */

87     final public static byte STATELESS = DeploymentInfo.STATELESS;
88
89     /**
90      * The Class of the bean's home interface.
91      */

92     protected Class JavaDoc homeClass;
93     
94     /**
95      * The Class of the bean's remote interface.
96      */

97     protected Class JavaDoc remoteClass;
98     
99     /**
100      * The Class of the bean's primary key or null if the
101      * bean is of a type that does not require a primary key.
102      */

103     protected Class JavaDoc keyClass;
104     
105     /**
106      * The EJBHome stub/proxy for this bean deployment.
107      */

108     protected EJBHome JavaDoc homeStub;
109
110     /**
111      * The type of bean that this MetaData implementation represents.
112      *
113      * @see #ENTITY
114      * @see #STATEFUL
115      * @see #STATELESS
116      */

117     protected byte type;
118
119     /**
120      * Constructs a IntraVmMetaData object to represent the
121      * MetaData of a bean deployment of the specified type
122      * with the specified home and remote interfaces.
123      *
124      * @param homeInterface
125      * The Class of the bean's home interface.
126      * @param remoteInterface
127      * The Class of the bean's remote interface.
128      * @param typeOfBean One of the {@link #ENTITY}, {@link #STATEFUL} or {@link #STATELESS} constants that specify the type of bean this MetaData will represent.
129      */

130     public IntraVmMetaData(Class JavaDoc homeInterface, Class JavaDoc remoteInterface, byte typeOfBean) {
131         this(homeInterface,remoteInterface, null, typeOfBean);
132     }
133     
134     /**
135      * Constructs a IntraVmMetaData object to represent the
136      * MetaData of a bean deployment of the specified type,
137      * with the specified home and remote interfaces and
138      * primary key class.
139      *
140      * @param homeInterface
141      * The Class of the bean's home interface.
142      * @param remoteInterface
143      * The Class of the bean's remote interface.
144      * @param primaryKeyClass
145      * The primary key class of the bean that this MetaData will represent.
146      * @param typeOfBean One of the {@link #ENTITY}, {@link #STATEFUL} or {@link #STATELESS} constants that specify the type of bean this MetaData will represent.
147      */

148     public IntraVmMetaData(Class JavaDoc homeInterface, Class JavaDoc remoteInterface, Class JavaDoc primaryKeyClass, byte typeOfBean) {
149         if(typeOfBean!=ENTITY && typeOfBean!=STATEFUL && typeOfBean!=STATELESS) {
150             if(typeOfBean==DeploymentInfo.CMP_ENTITY) {
151                 typeOfBean=ENTITY;
152             }else {
153                 throw new IllegalArgumentException JavaDoc("typeOfBean parameter not in range: "+typeOfBean);
154             }
155         }
156         if(homeInterface==null || remoteInterface==null) {
157             throw new IllegalArgumentException JavaDoc();
158         }
159         if(typeOfBean==ENTITY && primaryKeyClass==null) {
160             throw new IllegalArgumentException JavaDoc();
161         }
162         type = typeOfBean;
163         homeClass = homeInterface;
164         remoteClass = remoteInterface;
165             keyClass = primaryKeyClass;
166         }
167     
168     /**
169      * Returns the Class of the bean's home interface.
170      *
171      * @return the Class of the bean's home interface
172      */

173     public Class JavaDoc getHomeInterfaceClass( ) {
174         return homeClass;
175     }
176     
177     /**
178      * Returns the Class of the bean's remote interface.
179      *
180      * @return the Class of the bean's remote interface
181      */

182     public Class JavaDoc getRemoteInterfaceClass() {
183         return remoteClass;
184     }
185     
186     /**
187      * Returns the Class of the bean's primary key or null
188      * if the bean is of a type that does not require a primary key.
189      *
190      * EJB 1.1, section 5.5:
191      * If the EJBMetaData.getPrimaryKeyClass() method is invoked on a
192      * EJBMetaData object for a Session bean, the method throws the
193      * java.lang.RuntimeException.
194      * UnsupportedOperationException is a java.lang.RuntimeException
195      *
196      * @return Class
197      */

198     public Class JavaDoc getPrimaryKeyClass( ) {
199         if ( type == ENTITY )
200             return keyClass;
201         else
202             throw new UnsupportedOperationException JavaDoc("Session objects are private resources and do not have primary keys");
203     }
204     
205     /**
206      * Returns true if this MetaData represents a bean
207      * deployment of type SessionBean.
208      *
209      * @return boolean
210      */

211     public boolean isSession( ) {
212         return(type == STATEFUL || type ==STATELESS);
213     }
214     
215     /**
216      * Returns true if this MetaData represents a bean
217      * deployment that is a stateless SessionBean.
218      *
219      * @return boolean
220      */

221     public boolean isStatelessSession() {
222         return type == STATELESS;
223     }
224     
225     /**
226      * Sets the EJBHome stub/proxy for this bean deployment.
227      *
228      * @param home The EJBHome stub/proxy for this bean deployment.
229      */

230     public void setEJBHome(EJBHome JavaDoc home) {
231         homeStub = home;
232     }
233     
234     /**
235      * Gets the EJBHome stub/proxy for this bean deployment.
236      *
237      * @return The EJBHome stub/proxy for this bean deployment.
238      */

239     public javax.ejb.EJBHome JavaDoc getEJBHome() {
240         return homeStub;
241     }
242
243     /**
244      * If the meta data is being copied between bean instances in a RPC
245      * call we use the IntraVmArtifact
246      * <P>
247      * If the meta data is referenced by a stateful bean that is being
248      * passivated by the container, we allow this object to be serialized.
249      * <P>
250      * If the meta data is serialized outside the core container system,
251      * we allow the application server to handle it.
252      *
253      * @return Object
254      * @exception ObjectStreamException
255      */

256     protected Object JavaDoc writeReplace() throws ObjectStreamException JavaDoc{
257
258         /*
259          * If the meta data is being copied between bean instances in a RPC
260          * call we use the IntraVmArtifact
261          */

262         if(IntraVmCopyMonitor.isIntraVmCopyOperation()){
263             return new IntraVmArtifact(this);
264         /*
265          * If the meta data is referenced by a stateful bean that is being
266          * passivated by the container, we allow this object to be serialized.
267          */

268         }else if(IntraVmCopyMonitor.isStatefulPassivationOperation()){
269             return this;
270         /*
271          * If the meta data is serialized outside the core container system,
272          * we allow the application server to handle it.
273          */

274         }else{
275             BaseEjbProxyHandler handler = (BaseEjbProxyHandler)ProxyManager.getInvocationHandler(homeStub);
276             return org.openejb.OpenEJB.getApplicationServer().getEJBMetaData(handler.getProxyInfo());
277         }
278     }
279 }
Popular Tags