KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > client > EJBMetaDataImpl


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

45 package org.openejb.client;
46
47 import java.io.IOException JavaDoc;
48 import java.io.ObjectInput JavaDoc;
49 import java.io.ObjectOutput JavaDoc;
50
51 import javax.ejb.EJBHome JavaDoc;
52
53
54 /**
55  * -------------------------------------------------
56  * EJB 1.1
57  *
58  * 9.3.6 Meta-data class
59  *
60  * The deployment tools are responsible for implementing the class that
61  * provides meta-data information to the client view contract. The class must
62  * be a valid RMI-IIOP Value Type, and must implement the
63  * javax.ejb.EJBMetaData interface.
64  *
65  * Because the meta-data class is not entity bean specific, the container may, but is not required to, use a
66  * single class for all deployed enterprise beans.
67  * -------------------------------------------------
68  *
69  * The OpenEJB implementation of the javax.ejb.EJBMetaData interface.
70  *
71  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
72  * @since 11/25/2001
73  */

74 public class EJBMetaDataImpl implements javax.ejb.EJBMetaData JavaDoc, java.io.Externalizable JavaDoc {
75     
76     /**
77      * The constant that will be returned from the <code>getComponentType</code>
78      * method if this bean is a stateful session bean.
79      */

80     public static final byte STATEFUL = (byte)6;
81
82     /**
83      * The constant that will be returned from the <code>getComponentType</code>
84      * method if this bean is a stateless session bean.
85      */

86     public static final byte STATELESS = (byte)7;
87
88     /**
89      * The constant that will be returned from the <code>getComponentType</code>
90      * method if this bean is an enitity bean with bean-managed persistence.
91      */

92     public static final byte BMP_ENTITY = (byte)8;
93
94     /**
95      * The constant that will be returned from the <code>getComponentType</code>
96      * method if this bean is a enitity bean with container-managed persistence.
97      */

98     public static final byte CMP_ENTITY = (byte)9;
99     
100
101     protected transient byte type;
102
103     protected transient String JavaDoc deploymentID;
104     protected transient int deploymentCode;
105                                                         
106     /**
107      * The home interface of the enterprise Bean.
108      */

109     protected transient Class JavaDoc homeClass;
110     
111     /**
112      * The Class object for the enterprise Bean's remote interface.
113      */

114     protected transient Class JavaDoc remoteClass;
115     
116     /**
117      * The Class object for the enterprise Bean's primary key class.
118      */

119     protected transient Class JavaDoc keyClass;
120     
121     protected transient EJBHomeProxy ejbHomeProxy;
122
123     /** Public no-arg constructor required by Externalizable API */
124     public EJBMetaDataImpl() {
125     
126     }
127
128     public EJBMetaDataImpl(Class JavaDoc homeInterface, Class JavaDoc remoteInterface, byte typeOfBean) {
129         this.type = typeOfBean;
130         this.homeClass = homeInterface;
131         this.remoteClass = remoteInterface;
132     }
133
134     public EJBMetaDataImpl(Class JavaDoc homeInterface, Class JavaDoc remoteInterface, Class JavaDoc primaryKeyClass, byte typeOfBean) {
135         this(homeInterface, remoteInterface, typeOfBean);
136         if ( type == CMP_ENTITY || type == BMP_ENTITY ) {
137             this.keyClass = primaryKeyClass;
138         }
139     }
140     
141     public EJBMetaDataImpl(Class JavaDoc homeInterface, Class JavaDoc remoteInterface, Class JavaDoc primaryKeyClass, byte typeOfBean, String JavaDoc deploymentID) {
142         this(homeInterface, remoteInterface, primaryKeyClass, typeOfBean);
143         this.deploymentID = deploymentID;
144     }
145     
146     public EJBMetaDataImpl(Class JavaDoc homeInterface, Class JavaDoc remoteInterface, Class JavaDoc primaryKeyClass, byte typeOfBean, String JavaDoc deploymentID, int deploymentCode) {
147         this(homeInterface, remoteInterface, primaryKeyClass, typeOfBean, deploymentID);
148         this.deploymentCode = deploymentCode;
149     }
150     /**
151      * Obtain the Class object for the enterprise Bean's primary key class.
152      */

153     public Class JavaDoc getPrimaryKeyClass() {
154         if ( type != BMP_ENTITY && type != CMP_ENTITY ){
155             // TODO: Return a message
156
throw new java.lang.UnsupportedOperationException JavaDoc();
157         }
158         return keyClass;
159     }
160     
161     /**
162      * Obtain the home interface of the enterprise Bean.
163      */

164     public EJBHome JavaDoc getEJBHome() {
165         return ejbHomeProxy;
166     }
167     
168     /**
169      * Obtain the Class object for the enterprise Bean's home interface.
170      */

171     public Class JavaDoc getHomeInterfaceClass() {
172         return homeClass;
173     }
174     
175     /**
176      * Test if the enterprise Bean's type is "stateless session".
177      *
178      * @return True if the type of the enterprise Bean is stateless
179      * session.
180      */

181     public boolean isStatelessSession() {
182         return type == STATELESS;
183     }
184     
185     /**
186      * Obtain the Class object for the enterprise Bean's remote interface.
187      */

188     public Class JavaDoc getRemoteInterfaceClass() {
189         return remoteClass;
190     }
191     
192     /**
193      * Test if the enterprise Bean's type is "session".
194      *
195      * @return True if the type of the enterprise Bean is session bean.
196      */

197     public boolean isSession() {
198         return ( type == STATEFUL || type == STATELESS );
199     }
200     
201     protected void setEJBHomeProxy(EJBHomeProxy home) {
202         ejbHomeProxy = home;
203     }
204
205     //========================================
206
// Externalizable object implementation
207
//
208
public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
209         out.writeObject( homeClass );
210         out.writeObject( remoteClass );
211         out.writeObject( keyClass );
212         out.writeObject( ejbHomeProxy );
213         out.writeByte( type );
214         out.writeUTF( deploymentID );
215         out.writeShort( (short)deploymentCode );
216     }
217
218     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc,ClassNotFoundException JavaDoc {
219         homeClass = (Class JavaDoc) in.readObject();
220         remoteClass = (Class JavaDoc) in.readObject();
221         keyClass = (Class JavaDoc) in.readObject();
222         ejbHomeProxy = (EJBHomeProxy) in.readObject();
223         type = in.readByte();
224         deploymentID = in.readUTF();
225         deploymentCode = in.readShort();
226     }
227
228 }
Popular Tags