1 45 package org.openejb.test.entity.cmp; 46 47 import java.rmi.RemoteException ; 48 import java.util.Hashtable ; 49 import java.util.Properties ; 50 import java.util.StringTokenizer ; 51 52 import javax.ejb.EJBException ; 53 import javax.ejb.EntityContext ; 54 import javax.ejb.RemoveException ; 55 56 import org.openejb.test.ApplicationException; 57 import org.openejb.test.object.OperationsPolicy; 58 59 64 public class BasicCmpBean implements javax.ejb.EntityBean { 65 66 public static int key = 1000; 67 68 public int primaryKey; 69 public String firstName; 70 public String lastName; 71 public EntityContext ejbContext; 72 public Hashtable allowedOperationsTable = new Hashtable (); 73 74 75 79 89 public int ejbHomeSum(int x, int y) { 90 testAllowedOperations("ejbHome"); 91 return x+y; 92 } 93 94 102 public Integer ejbCreate(String name) 103 throws javax.ejb.CreateException { 104 StringTokenizer st = new StringTokenizer (name, " "); 105 firstName = st.nextToken(); 106 lastName = st.nextToken(); 107 this.primaryKey = key++; 108 return null; 109 } 110 111 public void ejbPostCreate(String name) 112 throws javax.ejb.CreateException { 113 } 114 115 119 120 124 130 public String businessMethod(String text){ 131 testAllowedOperations("businessMethod"); 132 StringBuffer b = new StringBuffer (text); 133 return b.reverse().toString(); 134 } 135 136 137 141 public void throwApplicationException() throws ApplicationException{ 142 throw new ApplicationException("Testing ability to throw Application Exceptions"); 143 } 144 145 152 public void throwSystemException_NullPointer() { 153 throw new NullPointerException ("Testing ability to throw System Exceptions"); 154 } 155 156 157 166 public Properties getPermissionsReport(){ 167 168 return null; 169 } 170 171 181 public OperationsPolicy getAllowedOperationsReport(String methodName){ 182 return (OperationsPolicy) allowedOperationsTable.get(methodName); 183 } 184 185 189 190 194 199 public void ejbLoad() throws EJBException ,RemoteException { 200 } 201 202 206 public void setEntityContext(EntityContext ctx) throws EJBException ,RemoteException { 207 ejbContext = ctx; 208 testAllowedOperations("setEntityContext"); 209 } 210 211 215 public void unsetEntityContext() throws EJBException ,RemoteException { 216 testAllowedOperations("unsetEntityContext"); 217 } 218 219 224 public void ejbStore() throws EJBException ,RemoteException { 225 } 226 227 235 public void ejbRemove() throws RemoveException ,EJBException ,RemoteException { 236 } 237 238 244 public void ejbActivate() throws EJBException ,RemoteException { 245 testAllowedOperations("ejbActivate"); 246 } 247 248 254 public void ejbPassivate() throws EJBException ,RemoteException { 255 testAllowedOperations("ejbPassivate"); 256 } 257 261 protected void testAllowedOperations(String methodName){ 262 OperationsPolicy policy = new OperationsPolicy(); 263 264 265 try{ 266 ejbContext.getEJBHome(); 267 policy.allow(policy.Context_getEJBHome); 268 }catch(IllegalStateException ise){} 269 270 271 try{ 272 ejbContext.getCallerPrincipal(); 273 policy.allow( policy.Context_getCallerPrincipal ); 274 }catch(IllegalStateException ise){} 275 276 277 try{ 278 ejbContext.isCallerInRole("ROLE"); 279 policy.allow( policy.Context_isCallerInRole ); 280 }catch(IllegalStateException ise){} 281 282 283 try{ 284 ejbContext.getRollbackOnly(); 285 policy.allow( policy.Context_getRollbackOnly ); 286 }catch(IllegalStateException ise){} 287 288 289 try{ 290 ejbContext.setRollbackOnly(); 291 policy.allow( policy.Context_setRollbackOnly ); 292 }catch(IllegalStateException ise){} 293 294 295 try{ 296 ejbContext.getUserTransaction(); 297 policy.allow( policy.Context_getUserTransaction ); 298 }catch(Exception e){} 299 300 301 try{ 302 ejbContext.getEJBObject(); 303 policy.allow( policy.Context_getEJBObject ); 304 }catch(IllegalStateException ise){} 305 306 307 try{ 308 ejbContext.getPrimaryKey(); 309 policy.allow( policy.Context_getPrimaryKey ); 310 }catch(IllegalStateException ise){} 311 312 317 allowedOperationsTable.put(methodName, policy); 318 } 319 320 } 321 | Popular Tags |