1 45 package org.openejb.test.stateful; 46 47 import java.rmi.RemoteException ; 48 import java.util.Hashtable ; 49 import java.util.Properties ; 50 51 import javax.ejb.EJBException ; 52 import javax.ejb.SessionContext ; 53 import javax.ejb.SessionSynchronization ; 54 55 import org.openejb.test.ApplicationException; 56 import org.openejb.test.object.OperationsPolicy; 57 58 63 public class BasicStatefulBean implements javax.ejb.SessionBean , SessionSynchronization { 64 65 66 private String name; 67 private SessionContext ejbContext; 68 private Hashtable allowedOperationsTable = new Hashtable (); 69 70 71 81 public void ejbCreate(String name) 82 throws javax.ejb.CreateException { 83 testAllowedOperations("ejbCreate"); 84 this.name = name; 85 } 86 90 91 95 101 public String businessMethod(String text){ 102 testAllowedOperations("businessMethod"); 103 StringBuffer b = new StringBuffer (text); 104 return b.reverse().toString(); 105 } 106 107 111 public void throwApplicationException() throws ApplicationException{ 112 throw new ApplicationException("Testing ability to throw Application Exceptions"); 113 } 114 115 122 public void throwSystemException_NullPointer() { 123 throw new NullPointerException ("Testing ability to throw System Exceptions"); 124 } 125 126 135 public Properties getPermissionsReport(){ 136 137 return null; 138 } 139 140 150 public OperationsPolicy getAllowedOperationsReport(String methodName){ 151 return (OperationsPolicy) allowedOperationsTable.get(methodName); 152 } 153 154 158 159 166 public void setSessionContext(SessionContext ctx) throws EJBException ,RemoteException { 167 ejbContext = ctx; 168 testAllowedOperations("setSessionContext"); 169 } 170 176 public void ejbRemove() throws EJBException ,RemoteException { 177 testAllowedOperations("ejbRemove"); 178 } 179 184 public void ejbActivate() throws EJBException ,RemoteException { 185 testAllowedOperations("ejbActivate"); 186 } 187 192 public void ejbPassivate() throws EJBException ,RemoteException { 193 testAllowedOperations("ejbPassivate"); 194 } 195 199 200 208 public void afterBegin() throws EJBException ,RemoteException { 209 testAllowedOperations("afterBegin"); 210 } 211 216 public void beforeCompletion() throws EJBException ,RemoteException { 217 testAllowedOperations("beforeCompletion"); 218 } 219 224 public void afterCompletion(boolean committed) throws EJBException ,RemoteException { 225 testAllowedOperations("afterCompletion"); 226 } 227 231 protected void testAllowedOperations(String methodName){ 232 OperationsPolicy policy = new OperationsPolicy(); 233 234 235 try{ 236 ejbContext.getEJBHome(); 237 policy.allow(policy.Context_getEJBHome); 238 }catch(IllegalStateException ise){} 239 240 241 try{ 242 ejbContext.getCallerPrincipal(); 243 policy.allow( policy.Context_getCallerPrincipal ); 244 }catch(IllegalStateException ise){} 245 246 247 try{ 248 ejbContext.isCallerInRole("ROLE"); 249 policy.allow( policy.Context_isCallerInRole ); 250 }catch(IllegalStateException ise){} 251 252 253 try{ 254 ejbContext.getRollbackOnly(); 255 policy.allow( policy.Context_getRollbackOnly ); 256 }catch(IllegalStateException ise){} 257 258 259 try{ 260 ejbContext.setRollbackOnly(); 261 policy.allow( policy.Context_setRollbackOnly ); 262 }catch(IllegalStateException ise){} 263 264 265 try{ 266 ejbContext.getUserTransaction(); 267 policy.allow( policy.Context_getUserTransaction ); 268 }catch(IllegalStateException ise){} 269 270 271 try{ 272 ejbContext.getEJBObject(); 273 policy.allow( policy.Context_getEJBObject ); 274 }catch(IllegalStateException ise){} 275 276 281 allowedOperationsTable.put(methodName, policy); 282 } 283 284 } 285 | Popular Tags |