001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.test.stateful;
017:
018: import java.rmi.RemoteException;
019:
020: import javax.ejb.EJBException;
021: import javax.ejb.EJBHome;
022: import javax.ejb.EJBMetaData;
023: import javax.ejb.EJBObject;
024: import javax.ejb.Handle;
025: import javax.ejb.SessionContext;
026: import javax.naming.InitialContext;
027:
028: import org.apache.openejb.test.object.ObjectGraph;
029:
030: /**
031: *
032: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
033: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
034: */
035: public class RmiIiopStatefulBean implements javax.ejb.SessionBean {
036:
037: private String name;
038: private SessionContext ejbContext;
039:
040: //=============================
041: // Home interface methods
042: //
043: //
044: // Home interface methods
045: //=============================
046:
047: //=============================
048: // Remote interface methods
049: //
050: /*-------------------------------------------------*/
051: /* String */
052: /*-------------------------------------------------*/
053:
054: public String returnStringObject(String data) {
055: return data;
056: }
057:
058: public String[] returnStringObjectArray(String[] data) {
059: return data;
060: }
061:
062: /*-------------------------------------------------*/
063: /* Character */
064: /*-------------------------------------------------*/
065:
066: public Character returnCharacterObject(Character data) {
067: return data;
068: }
069:
070: public char returnCharacterPrimitive(char data) {
071: return data;
072: }
073:
074: public Character[] returnCharacterObjectArray(Character[] data) {
075: return data;
076: }
077:
078: public char[] returnCharacterPrimitiveArray(char[] data) {
079: return data;
080: }
081:
082: /*-------------------------------------------------*/
083: /* Boolean */
084: /*-------------------------------------------------*/
085:
086: public Boolean returnBooleanObject(Boolean data) {
087: return data;
088: }
089:
090: public boolean returnBooleanPrimitive(boolean data) {
091: return data;
092: }
093:
094: public Boolean[] returnBooleanObjectArray(Boolean[] data) {
095: return data;
096: }
097:
098: public boolean[] returnBooleanPrimitiveArray(boolean[] data) {
099: return data;
100: }
101:
102: /*-------------------------------------------------*/
103: /* Byte */
104: /*-------------------------------------------------*/
105:
106: public Byte returnByteObject(Byte data) {
107: return data;
108: }
109:
110: public byte returnBytePrimitive(byte data) {
111: return data;
112: }
113:
114: public Byte[] returnByteObjectArray(Byte[] data) {
115: return data;
116: }
117:
118: public byte[] returnBytePrimitiveArray(byte[] data) {
119: return data;
120: }
121:
122: /*-------------------------------------------------*/
123: /* Short */
124: /*-------------------------------------------------*/
125:
126: public Short returnShortObject(Short data) {
127: return data;
128: }
129:
130: public short returnShortPrimitive(short data) {
131: return data;
132: }
133:
134: public Short[] returnShortObjectArray(Short[] data) {
135: return data;
136: }
137:
138: public short[] returnShortPrimitiveArray(short[] data) {
139: return data;
140: }
141:
142: /*-------------------------------------------------*/
143: /* Integer */
144: /*-------------------------------------------------*/
145:
146: public Integer returnIntegerObject(Integer data) {
147: return data;
148: }
149:
150: public int returnIntegerPrimitive(int data) {
151: return data;
152: }
153:
154: public Integer[] returnIntegerObjectArray(Integer[] data) {
155: return data;
156: }
157:
158: public int[] returnIntegerPrimitiveArray(int[] data) {
159: return data;
160: }
161:
162: /*-------------------------------------------------*/
163: /* Long */
164: /*-------------------------------------------------*/
165:
166: public Long returnLongObject(Long data) {
167: return data;
168: }
169:
170: public long returnLongPrimitive(long data) {
171: return data;
172: }
173:
174: public Long[] returnLongObjectArray(Long[] data) {
175: return data;
176: }
177:
178: public long[] returnLongPrimitiveArray(long[] data) {
179: return data;
180: }
181:
182: /*-------------------------------------------------*/
183: /* Float */
184: /*-------------------------------------------------*/
185:
186: public Float returnFloatObject(Float data) {
187: return data;
188: }
189:
190: public float returnFloatPrimitive(float data) {
191: return data;
192: }
193:
194: public Float[] returnFloatObjectArray(Float[] data) {
195: return data;
196: }
197:
198: public float[] returnFloatPrimitiveArray(float[] data) {
199: return data;
200: }
201:
202: /*-------------------------------------------------*/
203: /* Double */
204: /*-------------------------------------------------*/
205:
206: public Double returnDoubleObject(Double data) {
207: return data;
208: }
209:
210: public double returnDoublePrimitive(double data) {
211: return data;
212: }
213:
214: public Double[] returnDoubleObjectArray(Double[] data) {
215: return data;
216: }
217:
218: public double[] returnDoublePrimitiveArray(double[] data) {
219: return data;
220: }
221:
222: /*-------------------------------------------------*/
223: /* EJBHome */
224: /*-------------------------------------------------*/
225:
226: public EJBHome returnEJBHome(EJBHome data) {
227: return data;
228: }
229:
230: public EJBHome returnEJBHome() throws javax.ejb.EJBException {
231: EJBHome data = null;
232:
233: try {
234: InitialContext ctx = new InitialContext();
235:
236: data = (EJBHome) ctx
237: .lookup("java:comp/env/stateful/rmi-iiop/home");
238:
239: } catch (Exception e) {
240: e.printStackTrace();
241: throw new javax.ejb.EJBException(e);
242: }
243: return data;
244: }
245:
246: public ObjectGraph returnNestedEJBHome()
247: throws javax.ejb.EJBException {
248: ObjectGraph data = null;
249:
250: try {
251: InitialContext ctx = new InitialContext();
252:
253: Object object = ctx
254: .lookup("java:comp/env/stateful/rmi-iiop/home");
255: data = new ObjectGraph(object);
256:
257: } catch (Exception e) {
258: throw new javax.ejb.EJBException(e);
259: }
260: return data;
261: }
262:
263: public EJBHome[] returnEJBHomeArray(EJBHome[] data) {
264: return data;
265: }
266:
267: /*-------------------------------------------------*/
268: /* EJBObject */
269: /*-------------------------------------------------*/
270:
271: public EJBObject returnEJBObject(EJBObject data) {
272: return data;
273: }
274:
275: public EJBObject returnEJBObject() throws javax.ejb.EJBException {
276: EncStatefulObject data = null;
277:
278: try {
279: InitialContext ctx = new InitialContext();
280:
281: EncStatefulHome home = (EncStatefulHome) ctx
282: .lookup("java:comp/env/stateful/rmi-iiop/home");
283: data = home.create("Test01 StatefulBean");
284:
285: } catch (Exception e) {
286: throw new javax.ejb.EJBException(e);
287: }
288: return data;
289: }
290:
291: public ObjectGraph returnNestedEJBObject()
292: throws javax.ejb.EJBException {
293: ObjectGraph data = null;
294:
295: try {
296: InitialContext ctx = new InitialContext();
297:
298: EncStatefulHome home = (EncStatefulHome) ctx
299: .lookup("java:comp/env/stateful/rmi-iiop/home");
300: EncStatefulObject object = home
301: .create("Test02 StatefulBean");
302: data = new ObjectGraph(object);
303:
304: } catch (Exception e) {
305: throw new javax.ejb.EJBException(e);
306: }
307: return data;
308: }
309:
310: public EJBObject[] returnEJBObjectArray(EJBObject[] data) {
311: return data;
312: }
313:
314: /*-------------------------------------------------*/
315: /* EJBMetaData */
316: /*-------------------------------------------------*/
317:
318: public EJBMetaData returnEJBMetaData(EJBMetaData data) {
319: return data;
320: }
321:
322: public EJBMetaData returnEJBMetaData()
323: throws javax.ejb.EJBException {
324: EJBMetaData data = null;
325:
326: try {
327: InitialContext ctx = new InitialContext();
328:
329: EncStatefulHome home = (EncStatefulHome) ctx
330: .lookup("java:comp/env/stateful/rmi-iiop/home");
331: data = home.getEJBMetaData();
332:
333: } catch (Exception e) {
334: throw new javax.ejb.EJBException(e);
335: }
336: return data;
337: }
338:
339: public ObjectGraph returnNestedEJBMetaData()
340: throws javax.ejb.EJBException {
341: ObjectGraph data = null;
342:
343: try {
344: InitialContext ctx = new InitialContext();
345:
346: EncStatefulHome home = (EncStatefulHome) ctx
347: .lookup("java:comp/env/stateful/rmi-iiop/home");
348: EJBMetaData object = home.getEJBMetaData();
349: data = new ObjectGraph(object);
350:
351: } catch (Exception e) {
352: throw new javax.ejb.EJBException(e);
353: }
354: return data;
355: }
356:
357: public EJBMetaData[] returnEJBMetaDataArray(EJBMetaData[] data) {
358: return data;
359: }
360:
361: /*-------------------------------------------------*/
362: /* Handle */
363: /*-------------------------------------------------*/
364:
365: public Handle returnHandle(Handle data) {
366: return data;
367: }
368:
369: public Handle returnHandle() throws javax.ejb.EJBException {
370: Handle data = null;
371:
372: try {
373: InitialContext ctx = new InitialContext();
374:
375: EncStatefulHome home = (EncStatefulHome) ctx
376: .lookup("java:comp/env/stateful/rmi-iiop/home");
377: EncStatefulObject object = home
378: .create("Test03 StatefulBean");
379: data = object.getHandle();
380:
381: } catch (Exception e) {
382: throw new javax.ejb.EJBException(e);
383: }
384: return data;
385: }
386:
387: public ObjectGraph returnNestedHandle()
388: throws javax.ejb.EJBException {
389: ObjectGraph data = null;
390:
391: try {
392: InitialContext ctx = new InitialContext();
393:
394: EncStatefulHome home = (EncStatefulHome) ctx
395: .lookup("java:comp/env/stateful/rmi-iiop/home");
396: EncStatefulObject object = home
397: .create("Test04 StatefulBean");
398: data = new ObjectGraph(object.getHandle());
399:
400: } catch (Exception e) {
401: throw new javax.ejb.EJBException(e);
402: }
403: return data;
404: }
405:
406: public Handle[] returnHandleArray(Handle[] data) {
407: return data;
408: }
409:
410: /*-------------------------------------------------*/
411: /* ObjectGraph */
412: /*-------------------------------------------------*/
413:
414: public ObjectGraph returnObjectGraph(ObjectGraph data) {
415: return data;
416: }
417:
418: public ObjectGraph[] returnObjectGraphArray(ObjectGraph[] data) {
419: return data;
420: }
421:
422: public String remove(String arg) {
423: return arg;
424: }
425:
426: //
427: // Remote interface methods
428: //=============================
429:
430: //================================
431: // SessionBean interface methods
432: //
433: /**
434: * Set the associated session context. The container calls this method
435: * after the instance creation.
436: */
437: public void setSessionContext(SessionContext ctx)
438: throws EJBException, RemoteException {
439: ejbContext = ctx;
440: }
441:
442: /**
443: *
444: * @param name
445: * @exception javax.ejb.CreateException
446: */
447: public void ejbCreate(String name) throws javax.ejb.CreateException {
448: this .name = name;
449: }
450:
451: /**
452: * A container invokes this method before it ends the life of the session
453: * object. This happens as a result of a client's invoking a remove
454: * operation, or when a container decides to terminate the session object
455: * after a timeout.
456: */
457: public void ejbRemove() throws EJBException, RemoteException {
458: }
459:
460: /**
461: * The activate method is called when the instance is activated
462: * from its "passive" state. The instance should acquire any resource
463: * that it has released earlier in the ejbPassivate() method.
464: */
465: public void ejbActivate() throws EJBException, RemoteException {
466: // Should never called.
467: }
468:
469: /**
470: * The passivate method is called before the instance enters
471: * the "passive" state. The instance should release any resources that
472: * it can re-acquire later in the ejbActivate() method.
473: */
474: public void ejbPassivate() throws EJBException, RemoteException {
475: // Should never called.
476: }
477:
478: //
479: // SessionBean interface methods
480: //================================
481: }
|