KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > test > entity > cmp > RmiIiopCmpBean


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: RmiIiopCmpBean.java 1096 2004-03-26 21:41:16Z dblevins $
44  */

45 package org.openejb.test.entity.cmp;
46
47 import java.rmi.RemoteException JavaDoc;
48 import java.util.StringTokenizer JavaDoc;
49
50 import javax.ejb.EJBException JavaDoc;
51 import javax.ejb.EJBHome JavaDoc;
52 import javax.ejb.EJBMetaData JavaDoc;
53 import javax.ejb.EJBObject JavaDoc;
54 import javax.ejb.EntityContext JavaDoc;
55 import javax.ejb.Handle JavaDoc;
56 import javax.ejb.RemoveException JavaDoc;
57 import javax.naming.InitialContext JavaDoc;
58
59 import org.openejb.test.object.ObjectGraph;
60
61 /**
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 RmiIiopCmpBean implements javax.ejb.EntityBean JavaDoc{
67     
68     public static int key = 20;
69     
70     public int primaryKey;
71     public String JavaDoc firstName;
72     public String JavaDoc lastName;
73     public EntityContext JavaDoc ejbContext;
74     
75     //=============================
76
// Home interface methods
77
//
78

79     /**
80      * Maps to RmiIiopCmpHome.create
81      *
82      * @param name
83      * @return
84      * @exception javax.ejb.CreateException
85      * @see RmiIiopCmpHome.create
86      */

87     public Integer JavaDoc ejbCreate(String JavaDoc name)
88     throws javax.ejb.CreateException JavaDoc{
89         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(name, " ");
90         firstName = st.nextToken();
91         lastName = st.nextToken();
92         this.primaryKey = key++;
93         return null;
94     }
95     
96     public void ejbPostCreate(String JavaDoc name)
97     throws javax.ejb.CreateException JavaDoc{
98     }
99     
100     
101     //
102
// Home interface methods
103
//=============================
104

105
106     //=============================
107
// Remote interface methods
108
//
109
/*-------------------------------------------------*/
110     /* String */
111     /*-------------------------------------------------*/
112     
113     public String JavaDoc returnStringObject(String JavaDoc data) {
114         return data;
115     }
116     
117     public String JavaDoc[] returnStringObjectArray(String JavaDoc[] data) {
118         return data;
119     }
120     
121     /*-------------------------------------------------*/
122     /* Character */
123     /*-------------------------------------------------*/
124
125     public Character JavaDoc returnCharacterObject(Character JavaDoc data) {
126         return data;
127     }
128     
129     public char returnCharacterPrimitive(char data) {
130         return data;
131     }
132     
133     public Character JavaDoc[] returnCharacterObjectArray(Character JavaDoc[] data) {
134         return data;
135     }
136     
137     public char[] returnCharacterPrimitiveArray(char[] data) {
138         return data;
139     }
140
141     /*-------------------------------------------------*/
142     /* Boolean */
143     /*-------------------------------------------------*/
144     
145     public Boolean JavaDoc returnBooleanObject(Boolean JavaDoc data) {
146         return data;
147     }
148     
149     public boolean returnBooleanPrimitive(boolean data) {
150         return data;
151     }
152     
153     public Boolean JavaDoc[] returnBooleanObjectArray(Boolean JavaDoc[] data) {
154         return data;
155     }
156     
157     public boolean[] returnBooleanPrimitiveArray(boolean[] data) {
158         return data;
159     }
160     
161     /*-------------------------------------------------*/
162     /* Byte */
163     /*-------------------------------------------------*/
164     
165     public Byte JavaDoc returnByteObject(Byte JavaDoc data) {
166         return data;
167     }
168     
169     public byte returnBytePrimitive(byte data) {
170         return data;
171     }
172     
173     public Byte JavaDoc[] returnByteObjectArray(Byte JavaDoc[] data) {
174         return data;
175     }
176     
177     public byte[] returnBytePrimitiveArray(byte[] data) {
178         return data;
179     }
180     
181     /*-------------------------------------------------*/
182     /* Short */
183     /*-------------------------------------------------*/
184     
185     public Short JavaDoc returnShortObject(Short JavaDoc data) {
186         return data;
187     }
188     
189     public short returnShortPrimitive(short data) {
190         return data;
191     }
192     
193     public Short JavaDoc[] returnShortObjectArray(Short JavaDoc[] data) {
194         return data;
195     }
196     
197     public short[] returnShortPrimitiveArray(short[] data) {
198         return data;
199     }
200     
201     /*-------------------------------------------------*/
202     /* Integer */
203     /*-------------------------------------------------*/
204     
205     public Integer JavaDoc returnIntegerObject(Integer JavaDoc data) {
206         return data;
207     }
208     
209     public int returnIntegerPrimitive(int data) {
210         return data;
211     }
212     
213     public Integer JavaDoc[] returnIntegerObjectArray(Integer JavaDoc[] data) {
214         return data;
215     }
216     
217     public int[] returnIntegerPrimitiveArray(int[] data) {
218         return data;
219     }
220     
221     /*-------------------------------------------------*/
222     /* Long */
223     /*-------------------------------------------------*/
224     
225     public Long JavaDoc returnLongObject(Long JavaDoc data) {
226         return data;
227     }
228     
229     public long returnLongPrimitive(long data) {
230         return data;
231     }
232     
233     public Long JavaDoc[] returnLongObjectArray(Long JavaDoc[] data) {
234         return data;
235     }
236     
237     public long[] returnLongPrimitiveArray(long[] data) {
238         return data;
239     }
240     
241     /*-------------------------------------------------*/
242     /* Float */
243     /*-------------------------------------------------*/
244     
245     public Float JavaDoc returnFloatObject(Float JavaDoc data) {
246         return data;
247     }
248     
249     public float returnFloatPrimitive(float data) {
250         return data;
251     }
252     
253     public Float JavaDoc[] returnFloatObjectArray(Float JavaDoc[] data) {
254         return data;
255     }
256     
257     public float[] returnFloatPrimitiveArray(float[] data) {
258         return data;
259     }
260     
261     /*-------------------------------------------------*/
262     /* Double */
263     /*-------------------------------------------------*/
264     
265     public Double JavaDoc returnDoubleObject(Double JavaDoc data) {
266         return data;
267     }
268     
269     public double returnDoublePrimitive(double data) {
270         return data;
271     }
272     
273     public Double JavaDoc[] returnDoubleObjectArray(Double JavaDoc[] data) {
274         return data;
275     }
276     
277     public double[] returnDoublePrimitiveArray(double[] data) {
278         return data;
279     }
280     
281     
282     /*-------------------------------------------------*/
283     /* EJBHome */
284     /*-------------------------------------------------*/
285     
286     public EJBHome JavaDoc returnEJBHome(EJBHome JavaDoc data) {
287         return data;
288     }
289     
290     public EJBHome JavaDoc returnEJBHome() throws javax.ejb.EJBException JavaDoc{
291         EJBHome JavaDoc data = null;
292
293         try{
294         InitialContext JavaDoc ctx = new InitialContext JavaDoc();
295
296         data = (EJBHome JavaDoc)ctx.lookup("java:comp/env/cmp/rmi-iiop/home");
297
298         } catch (Exception JavaDoc e){
299             e.printStackTrace();
300             throw new javax.ejb.EJBException JavaDoc(e);
301         }
302         return data;
303     }
304
305     public ObjectGraph returnNestedEJBHome() throws javax.ejb.EJBException JavaDoc{
306         ObjectGraph data = null;
307
308         try{
309         InitialContext JavaDoc ctx = new InitialContext JavaDoc();
310
311         Object JavaDoc object = ctx.lookup("java:comp/env/cmp/rmi-iiop/home");
312         data = new ObjectGraph(object);
313
314         } catch (Exception JavaDoc e){
315             throw new javax.ejb.EJBException JavaDoc(e);
316         }
317         return data;
318     }
319
320     public EJBHome JavaDoc[] returnEJBHomeArray(EJBHome JavaDoc[] data) {
321         return data;
322     }
323     
324     /*-------------------------------------------------*/
325     /* EJBObject */
326     /*-------------------------------------------------*/
327     
328     public EJBObject JavaDoc returnEJBObject(EJBObject JavaDoc data) {
329         return data;
330     }
331     
332     public EJBObject JavaDoc returnEJBObject() throws javax.ejb.EJBException JavaDoc{
333         EncCmpObject data = null;
334
335         try{
336         InitialContext JavaDoc ctx = new InitialContext JavaDoc();
337
338         EncCmpHome home = (EncCmpHome)ctx.lookup("java:comp/env/cmp/rmi-iiop/home");
339         data = home.create("Test01 CmpBean");
340
341         } catch (Exception JavaDoc e){
342             throw new javax.ejb.EJBException JavaDoc(e);
343         }
344         return data;
345     }
346     
347     public ObjectGraph returnNestedEJBObject() throws javax.ejb.EJBException JavaDoc{
348         ObjectGraph data = null;
349
350         try{
351         InitialContext JavaDoc ctx = new InitialContext JavaDoc();
352
353         EncCmpHome home = (EncCmpHome)ctx.lookup("java:comp/env/cmp/rmi-iiop/home");
354         EncCmpObject object = home.create("Test02 CmpBean");
355         data = new ObjectGraph(object);
356
357         } catch (Exception JavaDoc e){
358             throw new javax.ejb.EJBException JavaDoc(e);
359         }
360         return data;
361     }
362     
363     public EJBObject JavaDoc[] returnEJBObjectArray(EJBObject JavaDoc[] data) {
364         return data;
365     }
366     
367     /*-------------------------------------------------*/
368     /* EJBMetaData */
369     /*-------------------------------------------------*/
370     
371     public EJBMetaData JavaDoc returnEJBMetaData(EJBMetaData JavaDoc data) {
372         return data;
373     }
374     
375     public EJBMetaData JavaDoc returnEJBMetaData() throws javax.ejb.EJBException JavaDoc{
376         EJBMetaData JavaDoc data = null;
377
378         try{
379         InitialContext JavaDoc ctx = new InitialContext JavaDoc();
380
381         EncCmpHome home = (EncCmpHome)ctx.lookup("java:comp/env/cmp/rmi-iiop/home");
382         data = home.getEJBMetaData();
383
384         } catch (Exception JavaDoc e){
385             throw new javax.ejb.EJBException JavaDoc(e);
386         }
387         return data;
388     }
389     
390     public ObjectGraph returnNestedEJBMetaData() throws javax.ejb.EJBException JavaDoc{
391         ObjectGraph data = null;
392
393         try{
394         InitialContext JavaDoc ctx = new InitialContext JavaDoc();
395
396         EncCmpHome home = (EncCmpHome)ctx.lookup("java:comp/env/cmp/rmi-iiop/home");
397         EJBMetaData JavaDoc object = home.getEJBMetaData();
398         data = new ObjectGraph(object);
399
400         } catch (Exception JavaDoc e){
401             throw new javax.ejb.EJBException JavaDoc(e);
402         }
403         return data;
404     }
405     
406     public EJBMetaData JavaDoc[] returnEJBMetaDataArray(EJBMetaData JavaDoc[] data) {
407         return data;
408     }
409     
410     /*-------------------------------------------------*/
411     /* Handle */
412     /*-------------------------------------------------*/
413     
414     public Handle JavaDoc returnHandle(Handle JavaDoc data) {
415         return data;
416     }
417     
418     public Handle JavaDoc returnHandle() throws javax.ejb.EJBException JavaDoc{
419         Handle JavaDoc data = null;
420
421         try{
422         InitialContext JavaDoc ctx = new InitialContext JavaDoc();
423
424         EncCmpHome home = (EncCmpHome)ctx.lookup("java:comp/env/cmp/rmi-iiop/home");
425         EncCmpObject object = home.create("Test03 CmpBean");
426         data = object.getHandle();
427
428         } catch (Exception JavaDoc e){
429             throw new javax.ejb.EJBException JavaDoc(e);
430         }
431         return data;
432     }
433     
434     public ObjectGraph returnNestedHandle() throws javax.ejb.EJBException JavaDoc{
435         ObjectGraph data = null;
436
437         try{
438         InitialContext JavaDoc ctx = new InitialContext JavaDoc();
439
440         EncCmpHome home = (EncCmpHome)ctx.lookup("java:comp/env/cmp/rmi-iiop/home");
441         EncCmpObject object = home.create("Test04 CmpBean");
442         data = new ObjectGraph(object.getHandle());
443
444         } catch (Exception JavaDoc e){
445             throw new javax.ejb.EJBException JavaDoc(e);
446         }
447         return data;
448     }
449     
450     public Handle JavaDoc[] returnHandleArray(Handle JavaDoc[] data) {
451         return data;
452     }
453     
454     /*-------------------------------------------------*/
455     /* ObjectGraph */
456     /*-------------------------------------------------*/
457     
458     public ObjectGraph returnObjectGraph(ObjectGraph data) {
459         return data;
460     }
461     
462     public ObjectGraph[] returnObjectGraphArray(ObjectGraph[] data) {
463         return data;
464     }
465     //
466
// Remote interface methods
467
//=============================
468

469
470     //================================
471
// EntityBean interface methods
472
//
473

474     /**
475      * A container invokes this method to instruct the
476      * instance to synchronize its state by loading it state from the
477      * underlying database.
478      */

479     public void ejbLoad() throws EJBException JavaDoc,RemoteException JavaDoc {
480     }
481     
482     /**
483      * Set the associated entity context. The container invokes this method
484      * on an instance after the instance has been created.
485      */

486     public void setEntityContext(EntityContext JavaDoc ctx) throws EJBException JavaDoc,RemoteException JavaDoc {
487         ejbContext = ctx;
488     }
489     
490     /**
491      * Unset the associated entity context. The container calls this method
492      * before removing the instance.
493      */

494     public void unsetEntityContext() throws EJBException JavaDoc,RemoteException JavaDoc {
495     }
496     
497     /**
498      * A container invokes this method to instruct the
499      * instance to synchronize its state by storing it to the underlying
500      * database.
501      */

502     public void ejbStore() throws EJBException JavaDoc,RemoteException JavaDoc {
503     }
504     
505     /**
506      * A container invokes this method before it removes the EJB object
507      * that is currently associated with the instance. This method
508      * is invoked when a client invokes a remove operation on the
509      * enterprise Bean's home interface or the EJB object's remote interface.
510      * This method transitions the instance from the ready state to the pool
511      * of available instances.
512      */

513     public void ejbRemove() throws RemoveException JavaDoc,EJBException JavaDoc,RemoteException JavaDoc {
514     }
515     
516     /**
517      * A container invokes this method when the instance
518      * is taken out of the pool of available instances to become associated
519      * with a specific EJB object. This method transitions the instance to
520      * the ready state.
521      */

522     public void ejbActivate() throws EJBException JavaDoc,RemoteException JavaDoc {
523     }
524     
525     /**
526      * A container invokes this method on an instance before the instance
527      * becomes disassociated with a specific EJB object. After this method
528      * completes, the container will place the instance into the pool of
529      * available instances.
530      */

531     public void ejbPassivate() throws EJBException JavaDoc,RemoteException JavaDoc {
532     }
533
534     //
535
// EntityBean interface methods
536
//================================
537
}
538
Popular Tags