1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * 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 18package java.security; 19 20import java.util.Enumeration; 21import java.util.Hashtable; 22 23import org.apache.harmony.security.internal.nls.Messages; 24 25/** 26 * A default {@code PermissionCollection} implementation that uses a hashtable. 27 * Each hashtable entry stores a Permission object as both the key and the 28 * value. 29 * <p> 30 * This {@code PermissionCollection} is intended for storing "neutral" 31 * permissions which do not require special collection. 32 */ 33 34final class PermissionsHash extends PermissionCollection { 35 36 private static final long serialVersionUID = -8491988220802933440L; 37 38 private final Hashtable perms = new Hashtable(); 39 40 /** 41 * Adds the argument to the collection. 42 * 43 * @param permission 44 * the permission to add to the collection. 45 */ 46 public void add(Permission permission) { 47 perms.put(permission, permission); 48 } 49 50 /** 51 * Returns an enumeration of the permissions in the receiver. 52 * 53 * @return Enumeration the permissions in the receiver. 54 */ 55 public Enumeration elements() { 56 return perms.elements(); 57 } 58 59 /** 60 * Indicates whether the argument permission is implied by the permissions 61 * contained in the receiver. 62 * 63 * @return boolean <code>true</code> if the argument permission is implied 64 * by the permissions in the receiver, and <code>false</code> if 65 * it is not. 66 * @param permission 67 * java.security.Permission the permission to check 68 */ 69 public boolean implies(Permission permission) { 70 for (Enumeration elements = elements(); elements.hasMoreElements();) { 71 if (((Permission)elements.nextElement()).implies(permission)) { 72 return true; 73 } 74 } 75 return false; 76 } 77} 78