KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > annuaire > PersonneEC2


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@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: PersonneEC2.java,v 1.5 2004/03/19 11:57:15 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 // PersonneEC2.java
27

28 package org.objectweb.jonas.jtests.beans.annuaire;
29
30 import java.rmi.RemoteException JavaDoc;
31 import java.util.Collection JavaDoc;
32 import java.util.Iterator JavaDoc;
33
34 import javax.ejb.CreateException JavaDoc;
35 import javax.ejb.DuplicateKeyException JavaDoc;
36 import javax.ejb.EntityBean JavaDoc;
37 import javax.ejb.EntityContext JavaDoc;
38 import javax.ejb.RemoveException JavaDoc;
39 import javax.ejb.TimedObject JavaDoc;
40 import javax.ejb.Timer JavaDoc;
41 import javax.ejb.TimerService JavaDoc;
42
43 import org.objectweb.jonas.common.Log;
44 import org.objectweb.util.monolog.api.BasicLevel;
45 import org.objectweb.util.monolog.api.Logger;
46
47 /**
48  * This is an entity bean with "container managed persistence version 2.x".
49  * @author Philippe Durieux, Helene Joanin (jonas team)
50  */

51 public abstract class PersonneEC2 implements EntityBean JavaDoc, TimedObject JavaDoc {
52
53     static protected Logger logger = null;
54     EntityContext JavaDoc ejbContext;
55
56     // ------------------------------------------------------------------
57
// Get and Set accessor methods of the bean's abstract schema
58
// ------------------------------------------------------------------
59
public abstract String JavaDoc getNom();
60     public abstract void setNom(String JavaDoc n);
61
62     public abstract String JavaDoc getNumero(); // Tx Attribute = Required
63
public abstract void setNumero(String JavaDoc n); // Tx Attribute = Required
64

65     public abstract int getTimerIdent();
66     public abstract void setTimerIdent(int id);
67
68     public abstract int getTimerCount();
69     public abstract void setTimerCount(int cnt);
70
71
72     // ------------------------------------------------------------------
73
// EntityBean implementation
74
// ------------------------------------------------------------------
75

76     /**
77      * Set the associated entity context. The container invokes this method
78      * on an instance after the instance has been created.
79      * This method is called in an unspecified transaction context.
80      *
81      * @param ctx - An EntityContext interface for the instance. The instance
82      * should store the reference to the context in an instance variable.
83      * @throws EJBException Thrown by the method to indicate a failure caused by a
84      * system-level error.
85      */

86     public void setEntityContext(EntityContext JavaDoc ctx) {
87         if (logger == null)
88             logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
89         logger.log(BasicLevel.DEBUG, "");
90         ejbContext = ctx;
91     }
92
93     /**
94      * Unset the associated entity context. The container calls this method
95      * before removing the instance.
96      * This is the last method that the container invokes on the instance.
97      * The Java garbage collector will eventually invoke the finalize() method
98      * on the instance.
99      * This method is called in an unspecified transaction context.
100      *
101      * @throws EJBException Thrown by the method to indicate a failure caused by a
102      * system-level error.
103      */

104     public void unsetEntityContext() {
105         logger.log(BasicLevel.DEBUG, "");
106         ejbContext = null;
107     }
108     
109     /**
110      * A container invokes this method before it removes the EJB object
111      * that is currently associated with the instance. This method is
112      * invoked when a client invokes a remove operation on the enterprise Bean's
113      * home interface or the EJB object's remote interface. This method
114      * transitions the instance from the ready state to the pool of available
115      * instances.
116      *
117      * This method is called in the transaction context of the remove operation.
118      * @throws RemoveException The enterprise Bean does not allow destruction of the object.
119      * @throws EJBException - Thrown by the method to indicate a failure caused by a system-level
120      * error.
121      */

122     public void ejbRemove() throws RemoveException JavaDoc {
123         logger.log(BasicLevel.DEBUG, "");
124     }
125
126     /**
127      * A container invokes this method to instruct the instance to synchronize
128      * its state by loading it state from the underlying database.
129      * This method always executes in the proper transaction context.
130      *
131      * @throws EJBException Thrown by the method to indicate a failure caused by
132      * a system-level error.
133      */

134     public void ejbLoad() {
135         logger.log(BasicLevel.DEBUG, "");
136     }
137
138     /**
139      * A container invokes this method to instruct the instance to synchronize
140      * its state by storing it to the underlying database.
141      * This method always executes in the proper transaction context.
142      *
143      * @throws EJBException Thrown by the method to indicate a failure caused by
144      * a system-level error.
145      */

146     public void ejbStore() {
147         logger.log(BasicLevel.DEBUG, "");
148     }
149     
150     /**
151      * There must be an ejbPostCreate par ejbCreate method
152      *
153      * @throws CreateException Failure to create an entity EJB object.
154      */

155     public void ejbPostCreate(String JavaDoc nom, String JavaDoc numero) throws CreateException JavaDoc {
156         logger.log(BasicLevel.DEBUG, "");
157     }
158     public void ejbPostCreate(String JavaDoc nom, String JavaDoc numero, boolean t) throws CreateException JavaDoc {
159         logger.log(BasicLevel.DEBUG, "");
160     }
161     
162
163     public java.lang.String JavaDoc ejbCreate(String JavaDoc nom, String JavaDoc numero) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
164         logger.log(BasicLevel.DEBUG, "ejbCreate(" + nom + ", " + numero + ")");
165
166         // Init here the bean fields
167
setNom(nom);
168         setNumero(numero);
169         setTimerIdent(0);
170         setTimerCount(0);
171
172         // In CMP, should return null.
173
return null;
174     }
175
176     public java.lang.String JavaDoc ejbCreate(String JavaDoc nom, String JavaDoc numero, boolean t) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
177         logger.log(BasicLevel.DEBUG, "ejbCreate nom numero boolean");
178
179         // Init here the bean fields
180
setNom(nom);
181         setNumero(numero);
182         setTimerIdent(0);
183         setTimerCount(0);
184
185         // In CMP, should return null.
186
return null;
187     }
188
189     /**
190      * This method is called before the instance enters the "passive" state.
191      * The instance should release any resources that it can re-acquire later in the
192      * ejbActivate() method.
193      * After the passivate method completes, the instance must be in a state that
194      * allows the container to use the Java Serialization protocol to externalize
195      * and store away the instance's state.
196      * This method is called with no transaction context.
197      *
198      * @exception EJBException - Thrown if the instance could not perform the
199      * function requested by the container
200      */

201     public void ejbPassivate() {
202         logger.log(BasicLevel.DEBUG, "");
203     }
204
205     /**
206      * This method is called when the instance is activated from its "passive" state.
207      * The instance should acquire any resource that it has released earlier in the
208      * ejbPassivate() method.
209      * This method is called with no transaction context.
210      *
211      * @exception EJBException - Thrown if the instance could not perform the
212      * function requested by the container
213      */

214     public void ejbActivate() {
215         logger.log(BasicLevel.DEBUG, "");
216     }
217     
218     // ------------------------------------------------------------------
219
// Personne implementation
220
// ------------------------------------------------------------------
221

222     /**
223      * getNumeroNTX / Tx Attribute = Supports
224      */

225     public String JavaDoc getNumeroNTX() {
226         logger.log(BasicLevel.DEBUG, "");
227         return getNumero();
228     }
229
230     /**
231      * setNumeroNTX / Tx Attribute = Supports
232      */

233     public void setNumeroNTX(String JavaDoc s) {
234         logger.log(BasicLevel.DEBUG, "");
235         setNumero(s);
236     }
237
238     //
239
// Methods only implemented in the entity bean with "CMP version 1.x"
240
// used to test the isModified extension for CMP version 1 Entity Bean.
241
// (defined here to have a common interface)
242
//
243

244     public boolean isModified() {
245         throw new UnsupportedOperationException JavaDoc();
246     }
247
248     public void reset() {
249         throw new UnsupportedOperationException JavaDoc();
250     }
251
252     public boolean isModifiedCalled() {
253         throw new UnsupportedOperationException JavaDoc();
254     }
255
256     public boolean ejbStoreCalled() {
257         throw new UnsupportedOperationException JavaDoc();
258     }
259
260     public boolean isDirty() {
261         throw new UnsupportedOperationException JavaDoc();
262     }
263
264     public int setTimer(int dur, int period) {
265         TimerService JavaDoc timerservice = ejbContext.getTimerService();
266         Timer JavaDoc mt = null;
267         int ret = getTimerIdent() + 1;
268         setTimerIdent(ret);
269         if (period > 0) {
270             mt = timerservice.createTimer(1000 * dur, 1000 * period, new Integer JavaDoc(ret));
271         } else {
272             mt = timerservice.createTimer(1000 * dur, new Integer JavaDoc(ret));
273         }
274         return ret;
275     }
276
277     public void cancelTimer(int ident) throws RemoteException JavaDoc {
278         TimerService JavaDoc timerservice = ejbContext.getTimerService();
279         Collection JavaDoc timerList = timerservice.getTimers();
280         for (Iterator JavaDoc i = timerList.iterator(); i.hasNext(); ) {
281             Timer JavaDoc t = (Timer JavaDoc) i.next();
282             Integer JavaDoc id = (Integer JavaDoc) t.getInfo();
283             if (id.intValue() == ident) {
284                 t.cancel();
285             }
286         }
287     }
288
289     public long getTimeRemaining(int ident) throws RemoteException JavaDoc {
290         TimerService JavaDoc timerservice = ejbContext.getTimerService();
291         Collection JavaDoc timerList = timerservice.getTimers();
292         long ret = -1;
293         for (Iterator JavaDoc i = timerList.iterator(); i.hasNext(); ) {
294             Timer JavaDoc t = (Timer JavaDoc) i.next();
295             Integer JavaDoc id = (Integer JavaDoc) t.getInfo();
296             if (id.intValue() == ident) {
297                 ret = t.getTimeRemaining();
298             }
299         }
300         return ret;
301     }
302
303
304     // -----------------------------------------------------------
305
// TimedObject implementation
306
// -----------------------------------------------------------
307

308     /**
309      * A timer is expired.
310      */

311     public void ejbTimeout(Timer JavaDoc timer) {
312         setTimerCount(getTimerCount() + 1);
313     }
314 }
315
Popular Tags