1 22 package org.jboss.test.testbean2.bean; 23 24 import java.rmi.*; 25 import javax.ejb.*; 26 import java.util.Collection ; 27 import java.util.ArrayList ; 28 29 import org.jboss.test.testbean.interfaces.StatefulSession; 30 import org.jboss.test.testbean.interfaces.StatefulSessionHome; 31 import org.jboss.test.testbean.interfaces.StatelessSession; 32 import org.jboss.test.testbean.interfaces.StatelessSessionHome; 33 import org.jboss.test.testbean.interfaces.EnterpriseEntity; 34 import org.jboss.test.testbean.interfaces.EnterpriseEntityHome; 35 import javax.naming.Context ; 36 import javax.naming.InitialContext ; 37 import java.sql.Date ; 38 import java.sql.Timestamp ; 39 import org.jboss.test.testbean2.interfaces.MyObject; 40 41 42 public class AllTypesBean implements EntityBean { 43 44 static org.jboss.logging.Logger log = 45 org.jboss.logging.Logger.getLogger(AllTypesBean.class); 46 47 public boolean aBoolean; 48 public byte aByte; 49 public short aShort; 50 public int anInt; 51 public long aLong; 52 public float aFloat; 53 public double aDouble; 54 public String aString; 56 public Date aDate; 57 public Timestamp aTimestamp; 58 59 public MyObject anObject; 60 61 public StatefulSession statefulSession; 62 public StatelessSession statelessSession; 63 public EnterpriseEntity enterpriseEntity; 64 65 public Collection aList; 66 67 private EntityContext entityContext; 68 69 70 public String ejbCreate(String pk) throws RemoteException, CreateException { 71 return ejbCreate(true, (byte)1, (short)2, (int)3, (long)4, (float)5.6, 72 (double)7.8, pk, new Date (System.currentTimeMillis()), 73 new Timestamp (System.currentTimeMillis()), new MyObject()); 74 } 75 76 public void ejbPostCreate(String pk) 77 throws RemoteException, CreateException {} 78 79 80 public String ejbCreate(boolean aBoolean, byte aByte, short aShort, int anInt, 81 long aLong, float aFloat, double aDouble, String aString, 82 Date aDate, Timestamp aTimestamp, MyObject anObject ) 83 84 throws RemoteException, CreateException { 85 86 this.aBoolean = aBoolean; 87 this.aByte = aByte; 88 this.aShort = aShort; 89 this.anInt = anInt; 90 this.aLong = aLong; 91 this.aFloat = aFloat; 92 this.aDouble = aDouble; 93 this.aString = aString; 95 this.aDate = aDate; 96 this.aTimestamp = aTimestamp; 97 this.anObject = anObject; 98 99 try { 100 Context ctx = new InitialContext (); 101 102 StatefulSessionHome sfHome = (StatefulSessionHome)ctx.lookup("java:comp/env/ejb/stateful"); 103 statefulSession = sfHome.create(); 104 105 StatelessSessionHome slHome = (StatelessSessionHome)ctx.lookup("java:comp/env/ejb/stateless"); 106 statelessSession = slHome.create(); 107 108 EnterpriseEntityHome eeHome = (EnterpriseEntityHome)ctx.lookup("java:comp/env/ejb/entity"); 109 try { 110 enterpriseEntity = eeHome.findByPrimaryKey(aString); 111 } catch (FinderException e) { 112 enterpriseEntity = eeHome.create(aString); 113 } 114 115 } catch (Exception e) { 116 log.debug("failed", e); 117 throw new CreateException(e.getMessage()); 118 } 119 120 aList = new ArrayList (); 121 122 return null; 123 } 124 125 126 public void ejbPostCreate(boolean aBoolean, byte aByte, short aShort, int anInt, 127 long aLong, float aFloat, double aDouble, String aString, 128 Date aDate, Timestamp aTimestamp, MyObject anObject ) 129 130 throws RemoteException, CreateException {} 131 132 public void ejbActivate() throws RemoteException {} 133 134 public void ejbLoad() throws RemoteException {} 135 136 public void ejbPassivate() throws RemoteException {} 137 138 public void ejbRemove() throws RemoteException, RemoveException {} 139 140 public void ejbStore() throws RemoteException {} 141 142 143 public void setEntityContext(EntityContext context) throws RemoteException { 144 entityContext = context; 145 } 146 147 public void unsetEntityContext() throws RemoteException { 148 entityContext = null; 149 } 150 151 152 public String callBusinessMethodA() throws RemoteException { 153 return statefulSession.callBusinessMethodA(); 155 } 156 157 158 159 public void updateAllValues(boolean aBoolean, byte aByte, short aShort, int anInt, 160 long aLong, float aFloat, double aDouble, String aString, 161 Date aDate, Timestamp aTimestamp, MyObject anObject ) { 162 163 this.aBoolean = aBoolean; 164 this.aByte = aByte; 165 this.aShort = aShort; 166 this.anInt = anInt; 167 this.aLong = aLong; 168 this.aFloat = aFloat; 169 this.aDouble = aDouble; 170 this.aString = aString; 172 this.aDate = aDate; 173 this.aTimestamp = aTimestamp; 174 this.anObject = anObject; 175 176 try { 177 Context ctx = new InitialContext (); 178 179 EnterpriseEntityHome eeHome = (EnterpriseEntityHome)ctx.lookup("java:comp/env/ejb/entity"); 180 try { 181 enterpriseEntity = eeHome.findByPrimaryKey(aString); 182 } catch (FinderException e) { 183 enterpriseEntity = eeHome.create(aString); 184 } 185 186 } catch (Exception e) { 187 } 189 190 } 191 192 196 public void addObjectToList(Object anObject) throws RemoteException { 197 aList = new ArrayList (aList); 198 aList.add(anObject); 199 } 200 201 205 public void removeObjectFromList(Object anObject) throws RemoteException { 206 aList = new ArrayList (aList); 207 aList.remove(anObject); 208 } 209 210 public Collection getObjectList() throws RemoteException { return aList; } 211 212 public boolean getBoolean() throws RemoteException { return aBoolean; } 213 public byte getByte() throws RemoteException { return aByte; } 214 public short getShort() throws RemoteException { return aShort; } 215 public int getInt() throws RemoteException { return anInt; } 216 public long getLong() throws RemoteException { return aLong; } 217 public float getFloat() throws RemoteException { return aFloat; } 218 public double getDouble() throws RemoteException { return aDouble; } 219 public String getString() throws RemoteException { return aString; } 221 public Date getDate() throws RemoteException { return aDate; } 222 public Timestamp getTimestamp() throws RemoteException { return aTimestamp; } 223 224 public MyObject getObject() throws RemoteException { return anObject; } 225 226 public Handle getStateful() throws RemoteException { 227 return statefulSession.getHandle(); 228 } 229 230 public Handle getStateless() throws RemoteException { 231 return statelessSession.getHandle(); 232 } 233 234 public Handle getEntity() throws RemoteException { 235 return enterpriseEntity.getHandle(); 236 } 237 238 239 } 240 | Popular Tags |