KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > test > entity > bmp > EncBmpBean


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

45 package org.openejb.test.entity.bmp;
46
47 import java.rmi.RemoteException JavaDoc;
48
49 import javax.ejb.EJBException JavaDoc;
50 import javax.ejb.EntityContext JavaDoc;
51 import javax.ejb.RemoveException JavaDoc;
52 import javax.naming.InitialContext JavaDoc;
53
54 import junit.framework.Assert;
55 import junit.framework.AssertionFailedError;
56
57 import org.openejb.test.TestFailureException;
58 import org.openejb.test.stateful.BasicStatefulHome;
59 import org.openejb.test.stateful.BasicStatefulObject;
60 import org.openejb.test.stateless.BasicStatelessHome;
61 import org.openejb.test.stateless.BasicStatelessObject;
62
63 /**
64  *
65  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
66  * @author <a HREF="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
67  */

68 public class EncBmpBean implements javax.ejb.EntityBean JavaDoc{
69     
70     private int primaryKey;
71     private String JavaDoc firstName;
72     private String JavaDoc lastName;
73     private EntityContext JavaDoc ejbContext;
74     
75     
76     //=============================
77
// Home interface methods
78
//
79

80     /**
81      * Maps to EncBmpHome.findEmptyCollection
82      *
83      * @param primaryKey
84      * @return
85      * @exception javax.ejb.FinderException
86      * @see EncBmpHome.sum
87      */

88     public java.util.Collection JavaDoc ejbFindEmptyCollection()
89     throws javax.ejb.FinderException JavaDoc, java.rmi.RemoteException JavaDoc {
90         return new java.util.Vector JavaDoc();
91     }
92
93     /**
94      * Maps to EncBmpHome.findByPrimaryKey
95      *
96      * @param primaryKey
97      * @return
98      * @exception javax.ejb.FinderException
99      * @see EncBmpHome.sum
100      */

101     public Integer JavaDoc ejbFindByPrimaryKey(Integer JavaDoc primaryKey)
102     throws javax.ejb.FinderException JavaDoc{
103         return new Integer JavaDoc(-1);
104     }
105
106     /**
107      * Maps to EncBmpHome.create
108      *
109      * @param name
110      * @return
111      * @exception javax.ejb.CreateException
112      * @see EncBmpHome.create
113      */

114     public Integer JavaDoc ejbCreate(String JavaDoc name)
115     throws javax.ejb.CreateException JavaDoc{
116         return new Integer JavaDoc(-1);
117     }
118     
119     public void ejbPostCreate(String JavaDoc name)
120     throws javax.ejb.CreateException JavaDoc{
121     }
122     
123     
124     //
125
// Home interface methods
126
//=============================
127

128
129     //=============================
130
// Remote interface methods
131
//
132

133
134     public void lookupEntityBean() throws TestFailureException{
135         try{
136             try{
137             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
138             Assert.assertNotNull("The InitialContext is null", ctx );
139             
140             BasicBmpHome home = (BasicBmpHome) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/entity/bmp/beanReferences/bmp_entity"), BasicBmpHome.class );
141             Assert.assertNotNull("The EJBHome looked up is null",home);
142
143             BasicBmpObject object = home.create("Enc Bean");
144             Assert.assertNotNull("The EJBObject is null", object );
145             } catch (Exception JavaDoc e){
146                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
147             }
148         } catch (AssertionFailedError afe){
149             throw new TestFailureException(afe);
150         }
151     }
152     
153     public void lookupStatefulBean() throws TestFailureException{
154         try{
155             try{
156             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
157             Assert.assertNotNull("The InitialContext is null", ctx );
158             
159             BasicStatefulHome home = (BasicStatefulHome) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/entity/bmp/beanReferences/stateful"), BasicStatefulHome.class );
160             Assert.assertNotNull("The EJBHome looked up is null",home);
161
162             BasicStatefulObject object = home.create("Enc Bean");
163             Assert.assertNotNull("The EJBObject is null", object );
164             } catch (Exception JavaDoc e){
165                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
166             }
167         } catch (AssertionFailedError afe){
168             throw new TestFailureException(afe);
169         }
170     }
171     
172     public void lookupStatelessBean() throws TestFailureException{
173         try{
174             try{
175             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
176             Assert.assertNotNull("The InitialContext is null", ctx );
177             
178             BasicStatelessHome home = (BasicStatelessHome) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/entity/bmp/beanReferences/stateless"), BasicStatelessHome.class );
179             Assert.assertNotNull("The EJBHome looked up is null",home);
180
181             BasicStatelessObject object = home.create();
182             Assert.assertNotNull("The EJBObject is null", object );
183             } catch (Exception JavaDoc e){
184                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
185             }
186         } catch (AssertionFailedError afe){
187             throw new TestFailureException(afe);
188         }
189     }
190
191     public void lookupStringEntry() throws TestFailureException{
192         try{
193             try{
194             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
195             Assert.assertNotNull("The InitialContext is null", ctx );
196             
197             String JavaDoc expected = new String JavaDoc("1");
198             String JavaDoc actual = (String JavaDoc)ctx.lookup("java:comp/env/entity/bmp/references/String");
199             
200             Assert.assertNotNull("The String looked up is null", actual );
201             Assert.assertEquals(expected, actual );
202
203             } catch (Exception JavaDoc e){
204                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
205             }
206         } catch (AssertionFailedError afe){
207             throw new TestFailureException(afe);
208         }
209     }
210     
211     public void lookupDoubleEntry() throws TestFailureException{
212         try{
213             try{
214             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
215             Assert.assertNotNull("The InitialContext is null", ctx );
216             
217             Double JavaDoc expected = new Double JavaDoc(1.0D);
218             Double JavaDoc actual = (Double JavaDoc)ctx.lookup("java:comp/env/entity/bmp/references/Double");
219             
220             Assert.assertNotNull("The Double looked up is null", actual );
221             Assert.assertEquals(expected, actual );
222
223             } catch (Exception JavaDoc e){
224                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
225             }
226         } catch (AssertionFailedError afe){
227             throw new TestFailureException(afe);
228         }
229     }
230     
231     public void lookupLongEntry() throws TestFailureException{
232         try{
233             try{
234             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
235             Assert.assertNotNull("The InitialContext is null", ctx );
236             
237             Long JavaDoc expected = new Long JavaDoc(1L);
238             Long JavaDoc actual = (Long JavaDoc)ctx.lookup("java:comp/env/entity/bmp/references/Long");
239             
240             Assert.assertNotNull("The Long looked up is null", actual );
241             Assert.assertEquals(expected, actual );
242
243             } catch (Exception JavaDoc e){
244                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
245             }
246         } catch (AssertionFailedError afe){
247             throw new TestFailureException(afe);
248         }
249     }
250     
251     public void lookupFloatEntry() throws TestFailureException{
252         try{
253             try{
254             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
255             Assert.assertNotNull("The InitialContext is null", ctx );
256             
257             Float JavaDoc expected = new Float JavaDoc(1.0F);
258             Float JavaDoc actual = (Float JavaDoc)ctx.lookup("java:comp/env/entity/bmp/references/Float");
259             
260             Assert.assertNotNull("The Float looked up is null", actual );
261             Assert.assertEquals(expected, actual );
262
263             } catch (Exception JavaDoc e){
264                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
265             }
266         } catch (AssertionFailedError afe){
267             throw new TestFailureException(afe);
268         }
269     }
270     
271     public void lookupIntegerEntry() throws TestFailureException{
272         try{
273             try{
274             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
275             Assert.assertNotNull("The InitialContext is null", ctx );
276             
277             Integer JavaDoc expected = new Integer JavaDoc(1);
278             Integer JavaDoc actual = (Integer JavaDoc)ctx.lookup("java:comp/env/entity/bmp/references/Integer");
279             
280             Assert.assertNotNull("The Integer looked up is null", actual );
281             Assert.assertEquals(expected, actual );
282
283             } catch (Exception JavaDoc e){
284                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
285             }
286         } catch (AssertionFailedError afe){
287             throw new TestFailureException(afe);
288         }
289     }
290     
291     public void lookupShortEntry() throws TestFailureException{
292         try{
293             try{
294             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
295             Assert.assertNotNull("The InitialContext is null", ctx );
296             
297             Short JavaDoc expected = new Short JavaDoc((short)1);
298             Short JavaDoc actual = (Short JavaDoc)ctx.lookup("java:comp/env/entity/bmp/references/Short");
299             
300             Assert.assertNotNull("The Short looked up is null", actual );
301             Assert.assertEquals(expected, actual );
302
303             } catch (Exception JavaDoc e){
304                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
305             }
306         } catch (AssertionFailedError afe){
307             throw new TestFailureException(afe);
308         }
309     }
310     
311     public void lookupBooleanEntry() throws TestFailureException{
312         try{
313             try{
314             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
315             Assert.assertNotNull("The InitialContext is null", ctx );
316             
317             Boolean JavaDoc expected = new Boolean JavaDoc(true);
318             Boolean JavaDoc actual = (Boolean JavaDoc)ctx.lookup("java:comp/env/entity/bmp/references/Boolean");
319             
320             Assert.assertNotNull("The Boolean looked up is null", actual );
321             Assert.assertEquals(expected, actual );
322
323             } catch (Exception JavaDoc e){
324                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
325             }
326         } catch (AssertionFailedError afe){
327             throw new TestFailureException(afe);
328         }
329     }
330     
331     public void lookupByteEntry() throws TestFailureException{
332         try{
333             try{
334             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
335             Assert.assertNotNull("The InitialContext is null", ctx );
336             
337             Byte JavaDoc expected = new Byte JavaDoc((byte)1);
338             Byte JavaDoc actual = (Byte JavaDoc)ctx.lookup("java:comp/env/entity/bmp/references/Byte");
339             
340             Assert.assertNotNull("The Byte looked up is null", actual );
341             Assert.assertEquals(expected, actual );
342
343             } catch (Exception JavaDoc e){
344                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
345             }
346         } catch (AssertionFailedError afe){
347             throw new TestFailureException(afe);
348         }
349     }
350
351     public void lookupResource() throws TestFailureException{
352         try{
353             try{
354             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
355             Assert.assertNotNull("The InitialContext is null", ctx );
356             } catch (Exception JavaDoc e){
357                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
358             }
359         } catch (AssertionFailedError afe){
360             throw new TestFailureException(afe);
361         }
362     }
363     //
364
// Remote interface methods
365
//=============================
366

367
368     //================================
369
// EntityBean interface methods
370
//
371

372     /**
373      * A container invokes this method to instruct the
374      * instance to synchronize its state by loading it state from the
375      * underlying database.
376      */

377     public void ejbLoad() throws EJBException JavaDoc,RemoteException JavaDoc {
378     }
379     
380     /**
381      * Set the associated entity context. The container invokes this method
382      * on an instance after the instance has been created.
383      */

384     public void setEntityContext(EntityContext JavaDoc ctx) throws EJBException JavaDoc,RemoteException JavaDoc {
385         ejbContext = ctx;
386     }
387     
388     /**
389      * Unset the associated entity context. The container calls this method
390      * before removing the instance.
391      */

392     public void unsetEntityContext() throws EJBException JavaDoc,RemoteException JavaDoc {
393     }
394     
395     /**
396      * A container invokes this method to instruct the
397      * instance to synchronize its state by storing it to the underlying
398      * database.
399      */

400     public void ejbStore() throws EJBException JavaDoc,RemoteException JavaDoc {
401     }
402     
403     /**
404      * A container invokes this method before it removes the EJB object
405      * that is currently associated with the instance. This method
406      * is invoked when a client invokes a remove operation on the
407      * enterprise Bean's home interface or the EJB object's remote interface.
408      * This method transitions the instance from the ready state to the pool
409      * of available instances.
410      */

411     public void ejbRemove() throws RemoveException JavaDoc,EJBException JavaDoc,RemoteException JavaDoc {
412     }
413     
414     /**
415      * A container invokes this method when the instance
416      * is taken out of the pool of available instances to become associated
417      * with a specific EJB object. This method transitions the instance to
418      * the ready state.
419      */

420     public void ejbActivate() throws EJBException JavaDoc,RemoteException JavaDoc {
421     }
422     
423     /**
424      * A container invokes this method on an instance before the instance
425      * becomes disassociated with a specific EJB object. After this method
426      * completes, the container will place the instance into the pool of
427      * available instances.
428      */

429     public void ejbPassivate() throws EJBException JavaDoc,RemoteException JavaDoc {
430     }
431     //
432
// EntityBean interface methods
433
//================================
434
}
435
Popular Tags