1 45 package org.openejb.test.object; 46 47 import java.io.IOException ; 48 import java.io.ObjectInput ; 49 import java.io.ObjectOutput ; 50 51 55 public class OperationsPolicy implements java.io.Externalizable { 56 57 public static final int Context_getEJBHome = 0; 58 public static final int Context_getCallerPrincipal = 1; 59 public static final int Context_isCallerInRole = 2; 60 public static final int Context_getRollbackOnly = 3; 61 public static final int Context_setRollbackOnly = 4; 62 public static final int Context_getUserTransaction = 5; 63 public static final int Context_getEJBObject = 6; 64 public static final int Context_getPrimaryKey = 7; 65 public static final int JNDI_access_to_java_comp_env = 8; 66 public static final int Resource_manager_access = 9; 67 public static final int Enterprise_bean_access = 10; 68 69 private boolean[] allowedOperations = new boolean[9]; 70 71 public OperationsPolicy() { 72 } 73 74 public OperationsPolicy(int[] operations) { 75 for (int i=0; i < operations.length; i++) { 76 allow( operations[i] ); 77 } 78 } 79 80 public void allow(int i) { 81 if (i < 0 || i > allowedOperations.length - 1 ) return; 82 allowedOperations[i] = true; 83 } 84 85 public boolean equals(Object object) { 86 if ( !(object instanceof OperationsPolicy ) ) return false; 87 88 OperationsPolicy that = (OperationsPolicy)object; 89 for (int i=0; i < allowedOperations.length; i++) { 90 if (this.allowedOperations[i] != that.allowedOperations[i]) return false; 91 } 92 93 return true; 94 } 95 96 public void writeExternal(ObjectOutput out) throws IOException { 97 for (int i=0; i < allowedOperations.length; i++) { 98 out.writeBoolean( allowedOperations[i] ); 99 } 100 } 101 102 public void readExternal(ObjectInput in) throws IOException ,ClassNotFoundException { 103 for (int i=0; i < allowedOperations.length; i++) { 104 allowedOperations[i] = in.readBoolean(); 105 } 106 } 107 108 public String toString() { 109 String str = "["; 110 for (int i=0; i < allowedOperations.length; i++) { 111 str += (allowedOperations[i])? "1": "0"; 112 } 113 str += "]"; 114 return str; 115 116 } 117 } 118 | Popular Tags |