KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > stateless > containermanaged > listeners > SLSBListenerTester00


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: SLSBListenerTester00.java 591 2006-06-05 14:44:15Z pinheirg $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.listeners;
26
27 import javax.ejb.Remote JavaDoc;
28 import javax.ejb.Stateless JavaDoc;
29 import javax.persistence.EntityManager;
30 import javax.persistence.PersistenceContext;
31
32 import org.objectweb.easybeans.tests.common.ejbs.entity.geometricforms.FormType;
33 import org.objectweb.easybeans.tests.common.ejbs.entity.geometricforms.Trapezoid;
34 import org.objectweb.easybeans.tests.common.listeners.FormsListener00;
35
36 /**
37  * Verifies if the container manages the listener invocation for a entity that
38  * has an listeners specified in the superclass and other listeners specified in
39  * the entity class.
40  * @author Gisele Pinheiro Souza
41  * @author Eduardo Studzinski Estima de Castro
42  */

43 @Stateless JavaDoc
44 @Remote JavaDoc(ItfListenerTester.class)
45 public class SLSBListenerTester00 extends ListenerTesterBase {
46
47     /**
48      * The persistence context used to manipulate the entity.
49      */

50     @PersistenceContext
51     private EntityManager entityManager;
52
53     /**
54      * Creates an entity Trapezoid and modifies it.
55      */

56     @Override JavaDoc
57     protected void createAndModifyEntity() {
58         //creates a trapezoid
59
Trapezoid trapezoid = new Trapezoid();
60         trapezoid.setSide1(1);
61         trapezoid.setSide2(2);
62         trapezoid.setFormType(FormType.TRAPEZOID);
63         entityManager.persist(trapezoid);
64         entityManager.flush();
65
66         //modifies the trapezoid
67
trapezoid.setSide1(2);
68         trapezoid.setSide2(1);
69         entityManager.flush();
70     }
71
72     /**
73      * Creates an entity Trapezoid, modifies and refreshes it.
74      */

75     @Override JavaDoc
76     protected void createAndRefreshEntity() {
77         //creates a trapezoid
78
Trapezoid trapezoid = new Trapezoid();
79         trapezoid.setSide1(1);
80         trapezoid.setSide2(2);
81         trapezoid.setFormType(FormType.TRAPEZOID);
82         entityManager.persist(trapezoid);
83         entityManager.flush();
84
85         //refresh the trapezoid
86
trapezoid.setSide1(2);
87         trapezoid.setSide2(1);
88         entityManager.refresh(trapezoid);
89
90     }
91
92     /**
93      * Creates an entity Trapezoid and removes it.
94      */

95     @Override JavaDoc
96     protected void createAndRemoveEntity() {
97         //creates a trapezoid
98
Trapezoid trapezoid = new Trapezoid();
99         trapezoid.setSide1(1);
100         trapezoid.setSide2(2);
101         trapezoid.setFormType(FormType.TRAPEZOID);
102         entityManager.persist(trapezoid);
103         entityManager.flush();
104
105         //removes the trapezoid
106
entityManager.remove(trapezoid);
107         entityManager.flush();
108     }
109
110     /**
111      * Creates an entity Trapezoid.
112      */

113     @Override JavaDoc
114     protected void createEntity() {
115         //creates a trapezoid
116
Trapezoid trapezoid = new Trapezoid();
117         trapezoid.setSide1(1);
118         trapezoid.setSide2(2);
119         trapezoid.setFormType(FormType.TRAPEZOID);
120         entityManager.persist(trapezoid);
121         entityManager.flush();
122     }
123
124     /**
125      * Creates the list of listeners that are called for the entity Trapezoid.
126      * The list is order by the callback invocation order.
127      * @return the list of listeners ordered by the invocation order.
128      */

129     private String JavaDoc[] createListenersList(){
130         String JavaDoc[] strListeners = new String JavaDoc[2];
131         strListeners[0] = FormsListener00.class.getName();
132         strListeners[1] = Trapezoid.class.getName();
133         return strListeners;
134     }
135
136
137     /**
138      * Creates the list of listeners that are called for the entity Trapezoid.
139      * The list is order by the callback invocation order.
140      * @return the list of listeners ordered by the invocation order.
141      */

142     @Override JavaDoc
143     protected String JavaDoc[] createListLoadListeners() {
144         return createListenersList();
145     }
146
147     /**
148      * Creates the list of listeners that are called for the entity Trapezoid.
149      * The list is order by the callback invocation order.
150      * @return the list of listeners ordered by the invocation order.
151      */

152     @Override JavaDoc
153     protected String JavaDoc[] createListPersistListeners() {
154         return createListenersList();
155     }
156
157     /**
158      * Creates the list of listeners that are called for the entity Trapezoid.
159      * The list is order by the callback invocation order.
160      * @return the list of listeners ordered by the invocation order.
161      */

162     @Override JavaDoc
163     protected String JavaDoc[] createListRemoveListeners() {
164         return createListenersList();
165     }
166
167     /**
168      * Creates the list of listeners that are called for the entity Trapezoid.
169      * The list is order by the callback invocation order.
170      * @return the list of listeners ordered by the invocation order.
171      */

172     @Override JavaDoc
173     protected String JavaDoc[] createListUpdateListeners() {
174         return createListenersList();
175     }
176
177     /**
178      * Returns the name of the entity class that the listeners are defined, in
179      * this case Trapezoid.
180      * @return the class name.
181      */

182     @Override JavaDoc
183     protected String JavaDoc getFormName() {
184         return Trapezoid.class.getName();
185     }
186
187 }
188
Popular Tags