01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb.test.object;
17:
18: import java.io.IOException;
19: import java.io.ObjectInput;
20: import java.io.ObjectOutput;
21:
22: /**
23: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
24: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
25: */
26: public class OperationsPolicy implements java.io.Externalizable {
27:
28: public static final int Context_getEJBHome = 0;
29: public static final int Context_getCallerPrincipal = 1;
30: public static final int Context_isCallerInRole = 2;
31: public static final int Context_getRollbackOnly = 3;
32: public static final int Context_setRollbackOnly = 4;
33: public static final int Context_getUserTransaction = 5;
34: public static final int Context_getEJBObject = 6;
35: public static final int Context_getPrimaryKey = 7;
36: public static final int JNDI_access_to_java_comp_env = 8;
37: public static final int Context_lookup = 11;
38: public static final int Context_getTimerService = 12;
39:
40: private boolean[] allowedOperations = new boolean[13];
41:
42: public OperationsPolicy() {
43: }
44:
45: public OperationsPolicy(int[] operations) {
46: for (int i = 0; i < operations.length; i++) {
47: allow(operations[i]);
48: }
49: }
50:
51: public void allow(int i) {
52: if (i < 0 || i > allowedOperations.length - 1)
53: return;
54: allowedOperations[i] = true;
55: }
56:
57: public boolean equals(Object object) {
58: if (!(object instanceof OperationsPolicy))
59: return false;
60:
61: OperationsPolicy that = (OperationsPolicy) object;
62: for (int i = 0; i < allowedOperations.length; i++) {
63: if (this .allowedOperations[i] != that.allowedOperations[i])
64: return false;
65: }
66:
67: return true;
68: }
69:
70: public void writeExternal(ObjectOutput out) throws IOException {
71: for (int i = 0; i < allowedOperations.length; i++) {
72: out.writeBoolean(allowedOperations[i]);
73: }
74: }
75:
76: public void readExternal(ObjectInput in) throws IOException,
77: ClassNotFoundException {
78: for (int i = 0; i < allowedOperations.length; i++) {
79: allowedOperations[i] = in.readBoolean();
80: }
81: }
82:
83: public String toString() {
84: String str = "[";
85: for (int i = 0; i < allowedOperations.length; i++) {
86: str += (allowedOperations[i]) ? "1" : "0";
87: }
88: str += "]";
89: return str;
90:
91: }
92: }
|