KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > test > stateless > RmiIiopStatelessBean


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

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

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

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

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

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

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

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