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 54 import org.openejb.test.ApplicationException; 55 import org.openejb.test.object.OperationsPolicy; 56 57 63 public class BMTStatefulBean implements javax.ejb.SessionBean { 64 65 private String name; 66 private SessionContext ejbContext; 67 private Hashtable allowedOperationsTable = new Hashtable (); 68 69 70 80 public void ejbCreate(String name) 81 throws javax.ejb.CreateException { 82 testAllowedOperations("ejbCreate"); 83 this.name = name; 84 } 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("Don't Panic"); 113 } 114 115 122 public void throwSystemException_NullPointer() { 123 throw new NullPointerException ("Panic"); 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 protected void testAllowedOperations(String methodName){ 200 OperationsPolicy policy = new OperationsPolicy(); 201 202 203 try{ 204 ejbContext.getEJBHome(); 205 policy.allow(policy.Context_getEJBHome); 206 }catch(IllegalStateException ise){} 207 208 209 try{ 210 ejbContext.getCallerPrincipal(); 211 policy.allow( policy.Context_getCallerPrincipal ); 212 }catch(IllegalStateException ise){} 213 214 215 try{ 216 ejbContext.isCallerInRole("ROLE"); 217 policy.allow( policy.Context_isCallerInRole ); 218 }catch(IllegalStateException ise){} 219 220 221 try{ 222 ejbContext.getRollbackOnly(); 223 policy.allow( policy.Context_getRollbackOnly ); 224 }catch(IllegalStateException ise){} 225 226 227 try{ 228 ejbContext.setRollbackOnly(); 229 policy.allow( policy.Context_setRollbackOnly ); 230 }catch(IllegalStateException ise){} 231 232 233 try{ 234 ejbContext.getUserTransaction(); 235 policy.allow( policy.Context_getUserTransaction ); 236 }catch(IllegalStateException ise){} 237 238 239 try{ 240 ejbContext.getEJBObject(); 241 policy.allow( policy.Context_getEJBObject ); 242 }catch(IllegalStateException ise){} 243 244 249 allowedOperationsTable.put(methodName, policy); 250 } 251 } 252 | Popular Tags |