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: */
17:
18: /**
19: * @author Alexey V. Varlamov
20: * @version $Revision$
21: */package java.security;
22:
23: import java.util.Enumeration;
24: import java.util.Hashtable;
25:
26: import org.apache.harmony.security.internal.nls.Messages;
27:
28: /**
29: * A default PermissionCollection implementation that uses a hashtable. Each
30: * hashtable entry stores a Permission object as both the key and the value.
31: * <br>
32: * This PermissionCollection is intended for storing "neutral"
33: * permissions which do not require special collection.
34: *
35: */
36:
37: final class PermissionsHash extends PermissionCollection {
38:
39: /**
40: * @com.intel.drl.spec_ref
41: */
42: private static final long serialVersionUID = -8491988220802933440L;
43:
44: /**
45: * @com.intel.drl.spec_ref
46: */
47: private final Hashtable perms = new Hashtable();
48:
49: /**
50: * Adds the argument to the collection.
51: *
52: *
53: * @param permission
54: * java.security.Permission the permission to add to the
55: * collection
56: */
57: public void add(Permission permission) {
58: perms.put(permission, permission);
59: }
60:
61: /**
62: * Answers an enumeration of the permissions in the receiver.
63: *
64: *
65: * @return Enumeration the permissions in the receiver.
66: */
67: public Enumeration elements() {
68: return perms.elements();
69: }
70:
71: /**
72: * Indicates whether the argument permission is implied by the permissions
73: * contained in the receiver.
74: *
75: *
76: * @return boolean <code>true</code> if the argument permission is implied
77: * by the permissions in the receiver, and <code>false</code> if
78: * it is not.
79: * @param permission
80: * java.security.Permission the permission to check
81: */
82: public boolean implies(Permission permission) {
83: for (Enumeration elements = elements(); elements
84: .hasMoreElements();) {
85: if (((Permission) elements.nextElement())
86: .implies(permission)) {
87: return true;
88: }
89: }
90: return false;
91: }
92: }
|