--- /home/tromey/gnu/Nightly/classpath/classpath/java/security/AccessControlContext.java 2004-07-05 02:22:23.000000000 -0600 +++ java/security/AccessControlContext.java 2004-07-10 02:19:15.000000000 -0600 @@ -37,8 +37,6 @@ package java.security; -import java.util.HashSet; - /** * AccessControlContext makes system resource access decsion * based on permission rights. @@ -55,8 +53,8 @@ */ public final class AccessControlContext { - private final ProtectionDomain[] protectionDomains; - private final DomainCombiner combiner; + private ProtectionDomain protectionDomain[]; + private DomainCombiner combiner; /** * Construct a new AccessControlContext with the specified @@ -67,12 +65,29 @@ */ public AccessControlContext(ProtectionDomain[]context) { - HashSet domains = new HashSet (context.length); - for (int i = 0; i < context.length; i++) - domains.add (context[i]); - protectionDomains = (ProtectionDomain[]) - domains.toArray (new ProtectionDomain[domains.size()]); - combiner = null; + int i, j, k, count = context.length, count2 = 0; + for (i = 0, j = 0; i < count; i++) + { + for (k = 0; k < i; k++) + if (context[k] == protectionDomain[i]) + break; + if (k != i) //it means previous loop did not complete + continue; + + count2++; + } + + protectionDomain = new ProtectionDomain[count2]; + for (i = 0, j = 0; i < count2; i++) + { + for (k = 0; k < i; k++) + if (context[k] == protectionDomain[i]) + break; + if (k != i) //it means previous loop did not complete + continue; + + protectionDomain[j++] = context[i]; + } } /** @@ -84,17 +99,7 @@ public AccessControlContext(AccessControlContext acc, DomainCombiner combiner) { - // XXX check permission to call this. - AccessControlContext acc2 = AccessController.getContext(); - protectionDomains = combiner.combine (acc2.protectionDomains, - acc.protectionDomains); - this.combiner = combiner; - } - - AccessControlContext (ProtectionDomain[] domains, AccessControlContext acc, - DomainCombiner combiner) - { - protectionDomains = combiner.combine (domains, acc.protectionDomains); + this(acc.protectionDomain); this.combiner = combiner; } @@ -118,11 +123,11 @@ */ public void checkPermission(Permission perm) throws AccessControlException { - if (protectionDomains.length == 0) - throw new AccessControlException ("permission not granted"); - for (int i = 0; i < protectionDomains.length; i++) - if (!protectionDomains[i].implies(perm)) - throw new AccessControlException ("permission not granted"); + for (int i = 0; i < protectionDomain.length; i++) + if (protectionDomain[i].implies(perm) == true) + return; + + throw new AccessControlException("Permission not granted"); } /** @@ -141,21 +146,13 @@ { AccessControlContext acc = (AccessControlContext) obj; - if (acc.protectionDomains.length != protectionDomains.length) + if (acc.protectionDomain.length != protectionDomain.length) return false; - int i, j; - for (i = 0; i < protectionDomains.length; i++) - { - for (j = 0; j < acc.protectionDomains.length; j++) - { - if (acc.protectionDomains[j].equals (protectionDomains[i])) - break; - } - if (j == acc.protectionDomains.length) - return false; - } - return true; + for (int i = 0; i < protectionDomain.length; i++) + if (acc.protectionDomain[i] != protectionDomain[i]) + return false; + return true; } return false; } @@ -168,8 +165,8 @@ public int hashCode() { int h = 0; - for (int i = 0; i < protectionDomains.length; i++) - h ^= protectionDomains[i].hashCode(); + for (int i = 0; i < protectionDomain.length; i++) + h ^= protectionDomain[i].hashCode(); return h; }