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