1 25 26 28 package org.objectweb.jonas.jtests.beans.annuaire; 29 30 import java.rmi.RemoteException ; 31 import java.util.Collection ; 32 import java.util.Iterator ; 33 34 import javax.ejb.CreateException ; 35 import javax.ejb.DuplicateKeyException ; 36 import javax.ejb.EntityBean ; 37 import javax.ejb.EntityContext ; 38 import javax.ejb.RemoveException ; 39 import javax.ejb.TimedObject ; 40 import javax.ejb.Timer ; 41 import javax.ejb.TimerService ; 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 51 public abstract class PersonneEC2 implements EntityBean , TimedObject { 52 53 static protected Logger logger = null; 54 EntityContext ejbContext; 55 56 public abstract String getNom(); 60 public abstract void setNom(String n); 61 62 public abstract String getNumero(); public abstract void setNumero(String n); 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 76 86 public void setEntityContext(EntityContext ctx) { 87 if (logger == null) 88 logger = Log.getLogger(Log.JONAS_TESTS_PREFIX); 89 logger.log(BasicLevel.DEBUG, ""); 90 ejbContext = ctx; 91 } 92 93 104 public void unsetEntityContext() { 105 logger.log(BasicLevel.DEBUG, ""); 106 ejbContext = null; 107 } 108 109 122 public void ejbRemove() throws RemoveException { 123 logger.log(BasicLevel.DEBUG, ""); 124 } 125 126 134 public void ejbLoad() { 135 logger.log(BasicLevel.DEBUG, ""); 136 } 137 138 146 public void ejbStore() { 147 logger.log(BasicLevel.DEBUG, ""); 148 } 149 150 155 public void ejbPostCreate(String nom, String numero) throws CreateException { 156 logger.log(BasicLevel.DEBUG, ""); 157 } 158 public void ejbPostCreate(String nom, String numero, boolean t) throws CreateException { 159 logger.log(BasicLevel.DEBUG, ""); 160 } 161 162 163 public java.lang.String ejbCreate(String nom, String numero) throws CreateException , DuplicateKeyException { 164 logger.log(BasicLevel.DEBUG, "ejbCreate(" + nom + ", " + numero + ")"); 165 166 setNom(nom); 168 setNumero(numero); 169 setTimerIdent(0); 170 setTimerCount(0); 171 172 return null; 174 } 175 176 public java.lang.String ejbCreate(String nom, String numero, boolean t) throws CreateException , DuplicateKeyException { 177 logger.log(BasicLevel.DEBUG, "ejbCreate nom numero boolean"); 178 179 setNom(nom); 181 setNumero(numero); 182 setTimerIdent(0); 183 setTimerCount(0); 184 185 return null; 187 } 188 189 201 public void ejbPassivate() { 202 logger.log(BasicLevel.DEBUG, ""); 203 } 204 205 214 public void ejbActivate() { 215 logger.log(BasicLevel.DEBUG, ""); 216 } 217 218 222 225 public String getNumeroNTX() { 226 logger.log(BasicLevel.DEBUG, ""); 227 return getNumero(); 228 } 229 230 233 public void setNumeroNTX(String s) { 234 logger.log(BasicLevel.DEBUG, ""); 235 setNumero(s); 236 } 237 238 244 public boolean isModified() { 245 throw new UnsupportedOperationException (); 246 } 247 248 public void reset() { 249 throw new UnsupportedOperationException (); 250 } 251 252 public boolean isModifiedCalled() { 253 throw new UnsupportedOperationException (); 254 } 255 256 public boolean ejbStoreCalled() { 257 throw new UnsupportedOperationException (); 258 } 259 260 public boolean isDirty() { 261 throw new UnsupportedOperationException (); 262 } 263 264 public int setTimer(int dur, int period) { 265 TimerService timerservice = ejbContext.getTimerService(); 266 Timer mt = null; 267 int ret = getTimerIdent() + 1; 268 setTimerIdent(ret); 269 if (period > 0) { 270 mt = timerservice.createTimer(1000 * dur, 1000 * period, new Integer (ret)); 271 } else { 272 mt = timerservice.createTimer(1000 * dur, new Integer (ret)); 273 } 274 return ret; 275 } 276 277 public void cancelTimer(int ident) throws RemoteException { 278 TimerService timerservice = ejbContext.getTimerService(); 279 Collection timerList = timerservice.getTimers(); 280 for (Iterator i = timerList.iterator(); i.hasNext(); ) { 281 Timer t = (Timer ) i.next(); 282 Integer id = (Integer ) t.getInfo(); 283 if (id.intValue() == ident) { 284 t.cancel(); 285 } 286 } 287 } 288 289 public long getTimeRemaining(int ident) throws RemoteException { 290 TimerService timerservice = ejbContext.getTimerService(); 291 Collection timerList = timerservice.getTimers(); 292 long ret = -1; 293 for (Iterator i = timerList.iterator(); i.hasNext(); ) { 294 Timer t = (Timer ) i.next(); 295 Integer id = (Integer ) t.getInfo(); 296 if (id.intValue() == ident) { 297 ret = t.getTimeRemaining(); 298 } 299 } 300 return ret; 301 } 302 303 304 308 311 public void ejbTimeout(Timer timer) { 312 setTimerCount(getTimerCount() + 1); 313 } 314 } 315 | Popular Tags |