Ejemplo n.º 1
0
        /**
         * Compares the specified object with this {@code UnresolvedPermission} for
         * equality and returns {@code true} if the specified object is equal,
         * {@code false} otherwise. To be equal, the specified object needs to be an
         * instance of {@code UnresolvedPermission}, the two {@code
         * UnresolvedPermission}s must refer to the same type and must have the same
         * name, the same actions and certificates.
         *
         * @param obj
         *            object to be compared for equality with this {@code
         *            UnresolvedPermission}.
         * @return {@code true} if the specified object is equal to this {@code
         *         UnresolvedPermission}, otherwise {@code false}.
         */

        public override bool Equals(Object obj)
        {
            if (obj == this)
            {
                return(true);
            }
            if (obj is UnresolvedPermission)
            {
                UnresolvedPermission that = (UnresolvedPermission)obj;
                if (getName().equals(that.getName()) &&
                    (name == null ? that.name == null : name
                     .equals(that.name)) &&
                    (actions == null ? that.actions == null : actions
                     .equals(that.actions)) &&
                    equalsCertificates(this.targetCerts, that.targetCerts))
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        /*
         * Resolves all permissions of the same class as the specified target
         * permission and adds them to the specified collection. If passed
         * collection is {@code null} and some unresolved permissions were resolved,
         * an appropriate new collection is instantiated and used. All resolved
         * permissions are removed from this unresolved collection, and collection
         * with resolved ones is returned.
         *
         * @param target
         *            a kind of permissions to be resolved.
         * @param holder
         *            an existing collection for storing resolved permissions.
         * @return a collection containing resolved permissions (if any found)
         */
        internal PermissionCollection resolveCollection(Permission target,
                                                        PermissionCollection holder)
        {
            String klass = target.getClass().getName();

            if (klasses.containsKey(klass))
            {
                lock (klasses)
                {
                    java.util.Collection <Object> klassMates = (java.util.Collection <Object>)klasses.get(klass);
                    for (java.util.Iterator <Object> iter = klassMates.iterator(); iter.hasNext();)
                    {
                        UnresolvedPermission element = (UnresolvedPermission)iter
                                                       .next();
                        Permission resolved = element.resolve(target.getClass());
                        if (resolved != null)
                        {
                            if (holder == null)
                            {
                                holder = target.newPermissionCollection();
                                if (holder == null)
                                {
                                    holder = new PermissionsHash();
                                }
                            }
                            holder.add(resolved);
                            iter.remove();
                        }
                    }
                    if (klassMates.size() == 0)
                    {
                        klasses.remove(klass);
                    }
                }
            }
            return(holder);
        }