KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > test > stateful > RmiIiopStatefulBean


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

45 package org.openejb.test.stateful;
46
47 import java.rmi.RemoteException JavaDoc;
48
49 import javax.ejb.EJBException JavaDoc;
50 import javax.ejb.EJBHome JavaDoc;
51 import javax.ejb.EJBMetaData JavaDoc;
52 import javax.ejb.EJBObject JavaDoc;
53 import javax.ejb.Handle JavaDoc;
54 import javax.ejb.SessionContext JavaDoc;
55 import javax.naming.InitialContext JavaDoc;
56
57 import org.openejb.test.object.ObjectGraph;
58
59 /**
60  *
61  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
62  * @author <a HREF="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
63  */

64 public class RmiIiopStatefulBean implements javax.ejb.SessionBean JavaDoc{
65     
66     private String JavaDoc name;
67     private SessionContext JavaDoc ejbContext;
68     
69     
70     //=============================
71
// Home interface methods
72
//
73
//
74
// Home interface methods
75
//=============================
76

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

440
441     //================================
442
// SessionBean interface methods
443
//
444
/**
445      * Set the associated session context. The container calls this method
446      * after the instance creation.
447      */

448     public void setSessionContext(SessionContext JavaDoc ctx) throws EJBException JavaDoc,RemoteException JavaDoc {
449         ejbContext = ctx;
450     }
451     /**
452      *
453      * @param name
454      * @exception javax.ejb.CreateException
455      */

456     public void ejbCreate(String JavaDoc name) throws javax.ejb.CreateException JavaDoc{
457         this.name = name;
458     }
459     /**
460      * A container invokes this method before it ends the life of the session
461      * object. This happens as a result of a client's invoking a remove
462      * operation, or when a container decides to terminate the session object
463      * after a timeout.
464      */

465     public void ejbRemove() throws EJBException JavaDoc,RemoteException JavaDoc {
466     }
467
468     /**
469      * The activate method is called when the instance is activated
470      * from its "passive" state. The instance should acquire any resource
471      * that it has released earlier in the ejbPassivate() method.
472      */

473     public void ejbActivate() throws EJBException JavaDoc,RemoteException JavaDoc {
474         // Should never called.
475
}
476     /**
477      * The passivate method is called before the instance enters
478      * the "passive" state. The instance should release any resources that
479      * it can re-acquire later in the ejbActivate() method.
480      */

481     public void ejbPassivate() throws EJBException JavaDoc,RemoteException JavaDoc {
482         // Should never called.
483
}
484
485     //
486
// SessionBean interface methods
487
//================================
488
}
489
Popular Tags