FileDocCategorySizeDatePackage
UnresolvedPermissionCollection.javaAPI DocAndroid 1.5 API7722Wed May 06 22:41:06 BST 2009java.security

UnresolvedPermissionCollection

public final class UnresolvedPermissionCollection extends PermissionCollection
{@code UnresolvedPermissionCollection} represents a specific {@code PermissionCollection} for storing {@link UnresolvedPermission} instances. Contained elements are grouped by their target type.

Fields Summary
private static final long
serialVersionUID
private static final ObjectStreamField[]
serialPersistentFields
private transient Map
klasses
Constructors Summary
Methods Summary
public voidadd(java.security.Permission permission)
Adds an unresolved permission to this {@code UnresolvedPermissionCollection}.

param
permission the permission to be added.
throws
SecurityException if this collection is read only.
throws
IllegalArgumentException if {@code permission} is {@code null} or not an {@code UnresolvedPermission}.
since
Android 1.0


                                                                                                
        
        if (isReadOnly()) {
            throw new SecurityException(Messages.getString("security.15")); //$NON-NLS-1$
        }
        if (permission == null
            || permission.getClass() != UnresolvedPermission.class) {
            throw new IllegalArgumentException(Messages.getString("security.16", //$NON-NLS-1$
                permission));
        }
        synchronized (klasses) {
            String klass = permission.getName();
            Collection klassMates = (Collection)klasses.get(klass);
            if (klassMates == null) {
                klassMates = new HashSet();
                klasses.put(klass, klassMates);
            }
            klassMates.add(permission);
        }
    
public java.util.Enumerationelements()

        Collection all = new ArrayList();
        for (Iterator iter = klasses.values().iterator(); iter.hasNext();) {
            all.addAll((Collection)iter.next());
        }
        return Collections.enumeration(all);
    
booleanhasUnresolved(java.security.Permission permission)
Returns true if this collection contains unresolved permissions with the same classname as argument permission.

        return klasses.containsKey(permission.getClass().getName());
    
public booleanimplies(java.security.Permission permission)
Always returns {@code false}.

return
always {@code false}
see
UnresolvedPermission#implies(Permission).
since
Android 1.0

        return false;
    
private voidreadObject(java.io.ObjectInputStream in)

com.intel.drl.spec_ref
Reads the object from stream and checks elements grouping for validity.

        ObjectInputStream.GetField fields = in.readFields();
        Map permissions = (Map)fields.get("permissions", null); //$NON-NLS-1$
        klasses = new HashMap();
        synchronized (klasses) {
            for (Iterator iter = permissions.keySet().iterator(); iter
                .hasNext();) {
                String key = (String)iter.next();
                Collection values = (Collection)permissions.get(key);
                for (Iterator iterator = values.iterator(); iterator.hasNext();) {
                    UnresolvedPermission element = (UnresolvedPermission)iterator
                        .next();
                    if (!element.getName().equals(key)) {
                        throw new InvalidObjectException(
                            Messages.getString("security.22")); //$NON-NLS-1$
                    }
                }
                klasses.put(key, new HashSet(values));
            }
        }
    
java.security.PermissionCollectionresolveCollection(java.security.Permission target, java.security.PermissionCollection holder)
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)

        String klass = target.getClass().getName();
        if (klasses.containsKey(klass)) {
            synchronized (klasses) {
                Collection klassMates = (Collection)klasses.get(klass);
                for (Iterator 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;
    
private voidwriteObject(java.io.ObjectOutputStream out)

com.intel.drl.spec_ref
Output fields via default mechanism.

        Hashtable permissions = new Hashtable();
        for (Iterator iter = klasses.keySet().iterator(); iter.hasNext();) {
            String key = (String)iter.next();
            permissions.put(key, new Vector(((Collection)klasses.get(key))));
        }
        ObjectOutputStream.PutField fields = out.putFields();
        fields.put("permissions", permissions); //$NON-NLS-1$
        out.writeFields();