1 25 26 package org.objectweb.jonas.jtests.beans.ffolder; 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 40 44 public class PaperEC implements EntityBean { 45 46 EntityContext ejbContext; 48 InitialContext ictx; 49 Context myEnv; 50 51 public String name; 56 public int value; 57 58 61 void checkEnv(String method) { 62 63 try { 66 String value = (String ) myEnv.lookup("myname"); 67 if (!value.equals("myentity")) { 68 throw new EJBException ("FileEC 1: " + method); 70 } 71 } catch (NamingException e) { 72 throw new EJBException ("FileEC 2: " + method); 74 } 75 try { 78 String value = (String ) ictx.lookup("java:comp/env/myname"); 79 if (!value.equals("myentity")) { 80 throw new EJBException ("FileEC 6: " + method); 82 } 83 } catch (NamingException e) { 84 throw new EJBException ("FileEC 7: " + method); 86 } 87 } 89 90 94 public void setEntityContext(EntityContext ctx) { 95 ejbContext = ctx; 100 try { 101 ictx = new InitialContext (); 103 myEnv = (Context ) ictx.lookup("java:comp/env"); 104 } catch (NamingException e) { 105 throw new EJBException ("PaperEC: Cannot get filehome:" + e); 106 } 107 checkEnv("setEntityContext"); 108 109 EJBLocalHome homel = ctx.getEJBLocalHome(); 111 if (homel == null) { 112 throw new EJBException ("PaperEC: setEntityContext cannot get EJBLocalHome"); 113 } 114 } 115 116 public void unsetEntityContext() { 117 ejbContext = null; 119 } 120 121 public void ejbActivate() { 122 } 124 125 public void ejbPassivate() { 126 } 128 129 public void ejbLoad() { 130 } 132 133 public void ejbStore() { 134 } 136 137 public void ejbRemove() throws RemoveException { 138 } 140 141 145 public String ejbCreate(String name) throws CreateException { 146 this.name = name; 148 this.value = 0; 149 return null; } 151 152 public String ejbPostCreate(String name) throws CreateException { 153 return null; } 156 157 161 public String getName() { 162 return this.name; 164 } 165 166 public int getValue() { 167 return this.value; 169 } 170 171 public void setValue(int v) { 172 this.value = v; 174 } 175 } 176 177 | Popular Tags |