1 25 26 package org.objectweb.jonas.jtests.beans.folder; 27 28 import javax.ejb.EJBException ; 29 import javax.ejb.EJBLocalHome ; 30 import javax.ejb.EntityBean ; 31 import javax.ejb.EntityContext ; 32 import javax.ejb.CreateException ; 33 import javax.ejb.RemoveException ; 34 import javax.naming.Context ; 35 import javax.naming.InitialContext ; 36 import javax.naming.NamingException ; 37 import javax.rmi.PortableRemoteObject ; 38 39 import org.objectweb.jonas.common.Log; 40 import org.objectweb.util.monolog.api.Logger; 41 import org.objectweb.util.monolog.api.BasicLevel; 42 43 47 public class PaperEC implements EntityBean { 48 49 static protected Logger logger = null; 50 EntityContext ejbContext; 51 InitialContext ictx; 52 Context myEnv; 53 54 public String name; 59 public int value; 60 61 64 void checkEnv(String method) { 65 66 logger.log(BasicLevel.DEBUG, "Check directly in my context"); 68 try { 69 String value = (String ) myEnv.lookup("myname"); 70 if (!value.equals("myentity")) { 71 logger.log(BasicLevel.ERROR, ": myEnv.lookup failed: myname=" + value); 72 throw new EJBException ("FileEC 1: " + method); 73 } 74 } catch (NamingException e) { 75 logger.log(BasicLevel.ERROR, ": myEnv.lookup raised exception:\n" + e); 76 throw new EJBException ("FileEC 2: " + method); 77 } 78 logger.log(BasicLevel.DEBUG, "Check from initial Context"); 80 try { 81 String value = (String ) ictx.lookup("java:comp/env/myname"); 82 if (!value.equals("myentity")) { 83 logger.log(BasicLevel.ERROR, ": ictx.lookup failed: myname=" + value); 84 throw new EJBException ("FileEC 6: " + method); 85 } 86 } catch (NamingException e) { 87 logger.log(BasicLevel.ERROR, ": ictx.lookup raised exception:\n" + e); 88 throw new EJBException ("FileEC 7: " + method); 89 } 90 logger.log(BasicLevel.DEBUG, ": checkEnv OK"); 91 } 92 93 97 public void setEntityContext(EntityContext ctx) { 98 if (logger == null) { 99 logger = Log.getLogger(Log.JONAS_TESTS_PREFIX); 100 } 101 logger.log(BasicLevel.DEBUG, ""); 102 ejbContext = ctx; 103 try { 104 ictx = new InitialContext (); 106 myEnv = (Context ) ictx.lookup("java:comp/env"); 107 } catch (NamingException e) { 108 throw new EJBException ("PaperEC: Cannot get filehome:" + e); 109 } 110 checkEnv("setEntityContext"); 111 112 EJBLocalHome homel = ctx.getEJBLocalHome(); 114 if (homel == null) { 115 throw new EJBException ("PaperEC: setEntityContext cannot get EJBLocalHome"); 116 } 117 } 118 119 public void unsetEntityContext() { 120 logger.log(BasicLevel.DEBUG, ""); 121 ejbContext = null; 122 } 123 124 public void ejbActivate() { 125 logger.log(BasicLevel.DEBUG, ""); 126 } 127 128 public void ejbPassivate() { 129 logger.log(BasicLevel.DEBUG, ""); 130 } 131 132 public void ejbLoad() { 133 logger.log(BasicLevel.DEBUG, ""); 134 } 135 136 public void ejbStore() { 137 logger.log(BasicLevel.DEBUG, ""); 138 } 139 140 public void ejbRemove() throws RemoveException { 141 logger.log(BasicLevel.DEBUG, ""); 142 } 143 144 148 public String ejbCreate(String name) throws CreateException { 149 logger.log(BasicLevel.DEBUG, ""); 150 this.name = name; 151 this.value = 0; 152 return null; } 154 155 public String ejbPostCreate(String name) throws CreateException { 156 logger.log(BasicLevel.DEBUG, ""); 157 return null; } 159 160 164 public String getName() { 165 logger.log(BasicLevel.DEBUG, ""); 166 return this.name; 167 } 168 169 public int getValue() { 170 logger.log(BasicLevel.DEBUG, ""); 171 return this.value; 172 } 173 174 public void setValue(int v) { 175 logger.log(BasicLevel.DEBUG, ""); 176 this.value = v; 177 } 178 } 179 180 | Popular Tags |