1 22 package org.jboss.ejb; 23 24 import java.io.IOException ; 25 import java.io.Serializable ; 26 import java.io.ObjectInputStream ; 27 import java.io.ObjectOutputStream ; 28 29 import java.rmi.RemoteException ; 30 import java.security.Principal ; 31 import java.util.Date ; 32 33 import javax.ejb.EJBLocalObject ; 34 import javax.ejb.*; 35 import javax.transaction.UserTransaction ; 36 import javax.xml.rpc.handler.MessageContext ; 37 38 39 46 public class StatefulSessionEnterpriseContext 47 extends EnterpriseContext 48 implements Serializable 49 { 50 52 private EJBObject ejbObject; 54 private EJBLocalObject ejbLocalObject; 55 private SessionContext ctx; 56 57 59 61 public StatefulSessionEnterpriseContext(Object instance, Container con) 62 throws RemoteException 63 { 64 super(instance, con); 65 ctx = new StatefulSessionContextImpl(); 66 try 67 { 68 AllowedOperationsAssociation.pushInMethodFlag(IN_SET_SESSION_CONTEXT); 69 ((SessionBean)instance).setSessionContext(ctx); 70 } 71 finally 72 { 73 AllowedOperationsAssociation.popInMethodFlag(); 74 } 75 } 76 77 79 public void discard() throws RemoteException 80 { 81 } 83 84 public EJBContext getEJBContext() 85 { 86 return ctx; 87 } 88 89 93 public void setInstance(Object instance) 94 { 95 this.instance = instance; 96 try 97 { 98 ((SessionBean)instance).setSessionContext(ctx); 99 } 100 catch (Exception x) 101 { 102 log.error("Failed to setSessionContext", x); 103 } 104 } 105 106 public void setEJBObject(EJBObject eo) { 107 ejbObject = eo; 108 } 109 110 public EJBObject getEJBObject() { 111 return ejbObject; 112 } 113 114 public void setEJBLocalObject(EJBLocalObject eo) { 115 ejbLocalObject = eo; 116 } 117 118 public EJBLocalObject getEJBLocalObject() { 119 return ejbLocalObject; 120 } 121 122 public SessionContext getSessionContext() 123 { 124 return ctx; 125 } 126 127 129 131 133 private void writeObject(ObjectOutputStream out) 134 throws IOException , ClassNotFoundException 135 { 136 } 138 139 private void readObject(ObjectInputStream in) 140 throws IOException , ClassNotFoundException 141 { 142 } 144 145 147 protected class StatefulSessionContextImpl 148 extends EJBContextImpl 149 implements SessionContext 150 { 151 152 public EJBHome getEJBHome() 153 { 154 AllowedOperationsAssociation.assertAllowedIn("getEJBHome", 155 IN_SET_SESSION_CONTEXT | 156 IN_EJB_CREATE | IN_EJB_REMOVE | IN_EJB_ACTIVATE | IN_EJB_PASSIVATE | IN_BUSINESS_METHOD | 157 IN_AFTER_BEGIN | IN_BEFORE_COMPLETION | IN_AFTER_COMPLETION); 158 159 return super.getEJBHome(); 160 } 161 162 public EJBLocalHome getEJBLocalHome() 163 { 164 AllowedOperationsAssociation.assertAllowedIn("getEJBLocalHome", 165 IN_SET_SESSION_CONTEXT | 166 IN_EJB_CREATE | IN_EJB_REMOVE | IN_EJB_ACTIVATE | IN_EJB_PASSIVATE | IN_BUSINESS_METHOD | 167 IN_AFTER_BEGIN | IN_BEFORE_COMPLETION | IN_AFTER_COMPLETION); 168 169 return super.getEJBLocalHome(); 170 } 171 172 175 public Principal getCallerPrincipal() 176 { 177 AllowedOperationsAssociation.assertAllowedIn("getCallerPrincipal", 178 IN_EJB_CREATE | IN_EJB_REMOVE | IN_EJB_ACTIVATE | IN_EJB_PASSIVATE | IN_BUSINESS_METHOD | 179 IN_AFTER_BEGIN | IN_BEFORE_COMPLETION | IN_AFTER_COMPLETION); 180 181 return super.getCallerPrincipal(); 182 } 183 184 public boolean isCallerInRole(String id) 185 { 186 AllowedOperationsAssociation.assertAllowedIn("isCallerInRole", 187 IN_EJB_CREATE | IN_EJB_REMOVE | IN_EJB_ACTIVATE | IN_EJB_PASSIVATE | IN_BUSINESS_METHOD | 188 IN_AFTER_BEGIN | IN_BEFORE_COMPLETION | IN_AFTER_COMPLETION); 189 190 return super.isCallerInRole(id); 191 } 192 193 public EJBObject getEJBObject() 194 { 195 AllowedOperationsAssociation.assertAllowedIn("getEJBObject", 196 IN_EJB_CREATE | IN_EJB_REMOVE | IN_EJB_ACTIVATE | IN_EJB_PASSIVATE | IN_BUSINESS_METHOD | 197 IN_AFTER_BEGIN | IN_BEFORE_COMPLETION | IN_AFTER_COMPLETION); 198 199 if (((StatefulSessionContainer)con).getRemoteClass()==null) 200 throw new IllegalStateException ( "No remote interface defined." ); 201 202 if (ejbObject == null) 203 { 204 EJBProxyFactory proxyFactory = con.getProxyFactory(); 205 if(proxyFactory == null) 206 { 207 String defaultInvokerName = con.getBeanMetaData(). 208 getContainerConfiguration().getDefaultInvokerName(); 209 proxyFactory = con.lookupProxyFactory(defaultInvokerName); 210 } 211 ejbObject = (EJBObject) proxyFactory.getStatefulSessionEJBObject(id); 212 } 213 214 return ejbObject; 215 } 216 217 public Object getBusinessObject(Class businessInterface) throws IllegalStateException 218 { 219 throw new RuntimeException ("NOT IMPLEMENTED"); 220 } 221 222 public Class getInvokedBusinessInterface() throws IllegalStateException 223 { 224 throw new RuntimeException ("NOT IMPLEMENTED"); 225 } 226 227 public EJBLocalObject getEJBLocalObject() 228 { 229 AllowedOperationsAssociation.assertAllowedIn("getEJBLocalObject", 230 IN_EJB_CREATE | IN_EJB_REMOVE | IN_EJB_ACTIVATE | IN_EJB_PASSIVATE | IN_BUSINESS_METHOD | 231 IN_AFTER_BEGIN | IN_BEFORE_COMPLETION | IN_AFTER_COMPLETION); 232 233 if (con.getLocalHomeClass()==null) 234 throw new IllegalStateException ( "No local interface for bean." ); 235 if (ejbLocalObject == null) 236 { 237 ejbLocalObject = ((StatefulSessionContainer)con).getLocalProxyFactory().getStatefulSessionEJBLocalObject(id); 238 } 239 return ejbLocalObject; 240 } 241 242 public boolean getRollbackOnly() 243 { 244 AllowedOperationsAssociation.assertAllowedIn("getRollbackOnly", 245 IN_BUSINESS_METHOD | IN_AFTER_BEGIN | IN_BEFORE_COMPLETION); 246 247 return super.getRollbackOnly(); 248 } 249 250 public void setRollbackOnly() 251 { 252 AllowedOperationsAssociation.assertAllowedIn("setRollbackOnly", 253 IN_BUSINESS_METHOD | IN_AFTER_BEGIN | IN_BEFORE_COMPLETION); 254 255 super.setRollbackOnly(); 256 } 257 258 public UserTransaction getUserTransaction() 259 { 260 AllowedOperationsAssociation.assertAllowedIn("getUserTransaction", 261 IN_EJB_CREATE | IN_EJB_REMOVE | IN_EJB_ACTIVATE | IN_EJB_PASSIVATE | IN_BUSINESS_METHOD); 262 263 return super.getUserTransaction(); 264 } 265 266 public TimerService getTimerService() throws IllegalStateException 267 { 268 throw new IllegalStateException ("getTimerService should not be access from a stateful session bean"); 269 } 270 271 public MessageContext getMessageContext() throws IllegalStateException 272 { 273 AllowedOperationsAssociation.assertAllowedIn("getMessageContext", 274 NOT_ALLOWED); 275 return null; 276 } 277 278 public Object getPrimaryKey() 279 { 280 return id; 281 } 282 } 283 } 284 | Popular Tags |