1 25 26 package org.objectweb.jonas.jtests.beans.folder; 27 28 import java.io.Serializable ; 29 import java.rmi.RemoteException ; 30 import javax.ejb.EJBException ; 31 import javax.ejb.EJBHome ; 32 import javax.ejb.EJBLocalHome ; 33 import javax.ejb.EJBMetaData ; 34 import javax.ejb.EntityBean ; 35 import javax.ejb.EntityContext ; 36 import javax.ejb.FinderException ; 37 import javax.ejb.RemoveException ; 38 import javax.ejb.CreateException ; 39 import javax.ejb.TimedObject ; 40 import javax.ejb.Timer ; 41 import javax.ejb.TimerHandle ; 42 import javax.ejb.TimerService ; 43 import javax.naming.Context ; 44 import javax.naming.InitialContext ; 45 import javax.naming.NamingException ; 46 import javax.rmi.PortableRemoteObject ; 47 48 import org.objectweb.jonas.common.Log; 49 import org.objectweb.util.monolog.api.Logger; 50 import org.objectweb.util.monolog.api.BasicLevel; 51 52 56 public class FileEC implements EntityBean , TimedObject { 57 58 protected static Logger logger = null; 59 EntityContext ejbContext; 60 InitialContext ictx; 61 Context myEnv; 62 PaperLocalHome phome; 63 PaperLocal p1; 64 PaperLocal p2; 65 66 public String name; 71 public String p1pk; 72 public String p2pk; 73 public int count; 74 75 78 void checkEnv(String method) { 79 80 logger.log(BasicLevel.DEBUG, "Check directly in my context"); 82 try { 83 String value = (String ) myEnv.lookup("myname"); 84 if (!value.equals("myentity")) { 85 logger.log(BasicLevel.ERROR, ": myEnv.lookup failed: myname=" + value); 86 throw new EJBException ("FileEC 1: " + method); 87 } 88 } catch (NamingException e) { 89 logger.log(BasicLevel.ERROR, ": myEnv.lookup raised exception:\n" + e); 90 throw new EJBException ("FileEC 2: " + method); 91 } 92 logger.log(BasicLevel.DEBUG, "Check from initial Context"); 94 try { 95 String value = (String ) ictx.lookup("java:comp/env/myname"); 96 if (!value.equals("myentity")) { 97 logger.log(BasicLevel.ERROR, ": ictx.lookup failed: myname=" + value); 98 throw new EJBException ("FileEC 6: " + method); 99 } 100 } catch (NamingException e) { 101 logger.log(BasicLevel.ERROR, ": ictx.lookup raised exception:\n" + e); 102 throw new EJBException ("FileEC 7: " + method); 103 } 104 logger.log(BasicLevel.DEBUG, ": checkEnv OK"); 105 } 106 107 111 115 public void ejbTimeout(Timer timer) { 116 logger.log(BasicLevel.DEBUG, ""); 117 Serializable sz = timer.getInfo(); 118 if (!(sz instanceof Integer )) { 119 logger.log(BasicLevel.ERROR, "Bad Info"); 120 return; 121 } 122 int action = ((Integer )sz).intValue(); 123 boolean ok = true; 124 } 125 126 130 133 public void setEntityContext(EntityContext ctx) { 134 if (logger == null) { 135 logger = Log.getLogger(Log.JONAS_TESTS_PREFIX); 136 } 137 logger.log(BasicLevel.DEBUG, ""); 138 ejbContext = ctx; 139 try { 140 ictx = new InitialContext (); 142 myEnv = (Context ) ictx.lookup("java:comp/env"); 143 } catch (NamingException e) { 144 throw new EJBException ("FileEC: Cannot get filehome:" + e); 145 } 146 checkEnv("setEntityContext"); 147 148 EJBHome home = ctx.getEJBHome(); 150 if (home == null) { 151 throw new EJBException ("FileEC: setEntityContext cannot get EJBHome"); 152 } 153 EJBLocalHome homel = ctx.getEJBLocalHome(); 155 if (homel == null) { 156 throw new EJBException ("FileEC: setEntityContext cannot get EJBLocalHome"); 157 } 158 try { 160 EJBMetaData md = home.getEJBMetaData(); 161 } catch (RemoteException e) { 162 throw new EJBException ("FileEC: setEntityContext cannot get EJBMetaData"); 163 } 164 } 165 166 public void unsetEntityContext() { 167 logger.log(BasicLevel.DEBUG, ""); 168 ejbContext = null; 169 } 170 171 public void ejbActivate() { 172 logger.log(BasicLevel.DEBUG, ""); 173 try { 174 stateUpdate(); 175 } catch (NamingException e) { 176 logger.log(BasicLevel.ERROR, "FileEC ejbActivate raised exception " + e); 177 throw new EJBException ("Error in ejbActivate:" + e); 178 } 179 } 180 181 public void ejbPassivate() { 182 logger.log(BasicLevel.DEBUG, ""); 183 phome = null; 185 p1 = null; 186 p2 = null; 187 } 188 189 194 public void ejbLoad() { 195 logger.log(BasicLevel.DEBUG, ""); 196 p1 = null; 197 if (p1pk.length() > 0) { 198 try { 199 p1 = phome.findByPrimaryKey(p1pk); 200 } catch (FinderException e) { 201 } 202 } 203 p2 = null; 204 if (p2pk.length() > 0) { 205 try { 206 p2 = phome.findByPrimaryKey(p2pk); 207 } catch (FinderException e) { 208 } 209 } 210 } 211 212 public void ejbStore() { 213 logger.log(BasicLevel.DEBUG, ""); 214 } 215 216 public void ejbRemove() throws RemoveException { 217 logger.log(BasicLevel.DEBUG, ""); 218 } 219 220 224 public String ejbCreate(String name) throws CreateException { 225 logger.log(BasicLevel.DEBUG, ""); 226 this.name = name; 227 return null; } 229 230 public String ejbPostCreate(String name) throws CreateException { 231 logger.log(BasicLevel.DEBUG, ""); 232 try { 233 stateUpdate(); 234 } catch (NamingException e) { 235 logger.log(BasicLevel.ERROR, "FileEC ejbPostCreate raised exception " + e); 236 throw new CreateException ("Error in ejbPostCreate:" + e); 237 } 238 return null; } 240 241 245 public TimerHandle getTimerHandle() throws RemoteException { 246 logger.log(BasicLevel.DEBUG, ""); 247 TimerService timerservice = ejbContext.getTimerService(); 248 Timer mt = timerservice.createTimer(300 * 1000, new Integer (1)); 249 TimerHandle th = mt.getHandle(); 250 return th; 251 } 252 253 public void cancelTimer(TimerHandle th) throws RemoteException { 254 logger.log(BasicLevel.DEBUG, ""); 255 Timer mt = th.getTimer(); 256 mt.cancel(); 257 } 258 259 public int getP1Value() { 260 logger.log(BasicLevel.DEBUG, ""); 261 int ret = p1.getValue(); 262 return ret; 263 } 264 265 public int getP2Value() { 266 logger.log(BasicLevel.DEBUG, ""); 267 int ret = p2.getValue(); 268 return ret; 269 } 270 271 public String getName() { 272 logger.log(BasicLevel.DEBUG, ""); 273 return this.name; 274 } 275 276 public int getCount() { 277 logger.log(BasicLevel.DEBUG, ""); 278 return this.count; 279 } 280 281 public PaperLocal getP1() { 282 logger.log(BasicLevel.DEBUG, ""); 283 return p1; 284 } 285 286 public PaperLocal getP2() { 287 logger.log(BasicLevel.DEBUG, ""); 288 return p2; 289 } 290 291 295 299 private void stateUpdate() throws NamingException { 300 phome = (PaperLocalHome) ictx.lookup("java:comp/env/ejb/paper"); 302 } 303 304 } 305 306 | Popular Tags |