home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / security / UnresolvedPermissionCollection.java < prev   
Encoding:
Java Source  |  1998-03-20  |  2.7 KB  |  116 lines

  1. /*
  2.  * @(#)UnresolvedPermissionCollection.java    1.2 98/03/18
  3.  *
  4.  * Copyright 1997 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.security;
  16.  
  17. import java.util.*;
  18.  
  19. /**
  20.  * A UnresolvedPermissionCollection stores a collection
  21.  * of UnresolvedPermission permissions.
  22.  * 
  23.  * @see java.security.Permission
  24.  * @see java.security.Permissions
  25.  * @see java.security.UnresolvedPermission
  26.  *
  27.  * @version 1.2 98/03/18
  28.  *
  29.  * @author Roland Schemers
  30.  */
  31.  
  32. final class UnresolvedPermissionCollection
  33. extends PermissionCollection 
  34. implements java.io.Serializable 
  35. {
  36.  
  37.     private Hashtable permissions; // keyed on type
  38.  
  39.     /**
  40.      * Create an empty BasicPermissions object.
  41.      *
  42.      */
  43.  
  44.     public UnresolvedPermissionCollection() {
  45.     permissions = new Hashtable();
  46.     }
  47.  
  48.     /**
  49.      * Adds a permission to the BasicPermissions. The key for the hash is
  50.      * permission.path.
  51.      *
  52.      * @param permission the Permission object to add.
  53.      */
  54.  
  55.     public void add(Permission permission)
  56.     {
  57.     if (! (permission instanceof UnresolvedPermission))
  58.         throw new IllegalArgumentException("invalid permission: "+
  59.                            permission);
  60.     UnresolvedPermission up = (UnresolvedPermission) permission;
  61.  
  62.     synchronized(permissions) {
  63.         Vector v = (Vector) permissions.get(up.getName());
  64.         if (v == null) {
  65.         v = new Vector();
  66.         permissions.put(up.getName(), v);
  67.         }
  68.         v.addElement(up);
  69.     }
  70.     }
  71.  
  72.     /**
  73.      * Remove any unresolved permissions of the same type as p,
  74.      * and return the Vector containing them.
  75.      */
  76.     synchronized Vector removeUnresolvedPermissions(Permission p) {
  77.     return (Vector) permissions.remove(p.getClass().getName());
  78.     }
  79.  
  80.     /**
  81.      * always returns false for unresolved permissions
  82.      *
  83.      */
  84.     public boolean implies(Permission permission) 
  85.     {
  86.     return false;
  87.     }
  88.  
  89.     /**
  90.      * Returns an enumeration of all the UnresolvedPermission vectors in the 
  91.      * container.
  92.      *
  93.      * @return an enumeration of all the UnresolvedPermission objects.
  94.      */
  95.  
  96.     public synchronized Enumeration elements()
  97.     {
  98.     Vector perms = new Vector();
  99.  
  100.     Enumeration enum = permissions.elements();
  101.  
  102.     while (enum.hasMoreElements()) {
  103.         try {
  104.         Vector urp = (Vector) enum.nextElement();
  105.         Enumeration ue = urp.elements();
  106.         while (ue.hasMoreElements()) {
  107.             perms.addElement(ue.nextElement());
  108.         }
  109.         } catch (NoSuchElementException e){
  110.         // ignore
  111.         }
  112.     }
  113.     return perms.elements();
  114.     }
  115. }
  116.