コード例 #1
0
        private bool allEnabled; // = false;

        /**
         * Adds the given {@code Permission} to this heterogeneous {@code
         * PermissionCollection}. The {@code permission} is stored in its
         * appropriate {@code PermissionCollection}.
         *
         * @param permission
         *            the {@code Permission} to be added.
         * @throws SecurityException
         *             if this collection's {@link #isReadOnly()} method returns
         *             {@code true}.
         * @throws NullPointerException
         *             if {@code permission} is {@code null}.
         */
        public override void add(Permission permission)
        {
            if (isReadOnly())
            {
                throw new java.lang.SecurityException("collection is read-only"); //$NON-NLS-1$
            }

            if (permission == null)
            {
                throw new java.lang.NullPointerException("invalid null permission"); //$NON-NLS-1$
            }

            java.lang.Class      klass      = permission.getClass();
            PermissionCollection klassMates = (PermissionCollection)klasses
                                              .get(klass);

            if (klassMates == null)
            {
                lock (klasses) {
                    klassMates = (PermissionCollection)klasses.get(klass);
                    if (klassMates == null)
                    {
                        klassMates = permission.newPermissionCollection();
                        if (klassMates == null)
                        {
                            klassMates = new PermissionsHash();
                        }
                        klasses.put(klass, klassMates);
                    }
                }
            }
            klassMates.add(permission);

            if (klass == typeof(AllPermission).getClass())
            {
                allEnabled = true;
            }
        }
コード例 #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);
        }
コード例 #3
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;
 }