1. /*
  2. * @(#)UnresolvedPermissionCollection.java 1.7 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.security;
  8. import java.util.*;
  9. /**
  10. * A UnresolvedPermissionCollection stores a collection
  11. * of UnresolvedPermission permissions.
  12. *
  13. * @see java.security.Permission
  14. * @see java.security.Permissions
  15. * @see java.security.UnresolvedPermission
  16. *
  17. * @version 1.7 01/11/29
  18. *
  19. * @author Roland Schemers
  20. */
  21. final class UnresolvedPermissionCollection
  22. extends PermissionCollection
  23. implements java.io.Serializable
  24. {
  25. private Hashtable permissions; // keyed on type
  26. /**
  27. * Create an empty BasicPermissions object.
  28. *
  29. */
  30. public UnresolvedPermissionCollection() {
  31. permissions = new Hashtable(11);
  32. }
  33. /**
  34. * Adds a permission to the BasicPermissions. The key for the hash is
  35. * permission.path.
  36. *
  37. * @param permission the Permission object to add.
  38. */
  39. public void add(Permission permission)
  40. {
  41. if (! (permission instanceof UnresolvedPermission))
  42. throw new IllegalArgumentException("invalid permission: "+
  43. permission);
  44. UnresolvedPermission up = (UnresolvedPermission) permission;
  45. synchronized(permissions) {
  46. Vector v = (Vector) permissions.get(up.getName());
  47. if (v == null) {
  48. v = new Vector();
  49. permissions.put(up.getName(), v);
  50. }
  51. v.addElement(up);
  52. }
  53. }
  54. /**
  55. * get any unresolved permissions of the same type as p,
  56. * and return the Vector containing them.
  57. */
  58. synchronized Vector getUnresolvedPermissions(Permission p) {
  59. return (Vector) permissions.get(p.getClass().getName());
  60. }
  61. /**
  62. * always returns false for unresolved permissions
  63. *
  64. */
  65. public boolean implies(Permission permission)
  66. {
  67. return false;
  68. }
  69. /**
  70. * Returns an enumeration of all the UnresolvedPermission vectors in the
  71. * container.
  72. *
  73. * @return an enumeration of all the UnresolvedPermission objects.
  74. */
  75. public synchronized Enumeration elements()
  76. {
  77. Vector perms = new Vector();
  78. Enumeration enum = permissions.elements();
  79. while (enum.hasMoreElements()) {
  80. try {
  81. Vector urp = (Vector) enum.nextElement();
  82. Enumeration ue = urp.elements();
  83. while (ue.hasMoreElements()) {
  84. perms.addElement(ue.nextElement());
  85. }
  86. } catch (NoSuchElementException e){
  87. // ignore
  88. }
  89. }
  90. return perms.elements();
  91. }
  92. }