FileDocCategorySizeDatePackage
PriviAction.javaAPI DocAndroid 1.5 API4145Wed May 06 22:41:04 BST 2009org.apache.harmony.luni.util

PriviAction

public class PriviAction extends Object implements PrivilegedAction
Helper class to avoid multiple anonymous inner class for {@link java.security.AccessController#doPrivileged(PrivilegedAction)} calls.

Fields Summary
private Object
arg1
private Object
arg2
private int
action
private static final int
GET_SYSTEM_PROPERTY
private static final int
GET_SECURITY_POLICY
private static final int
SET_ACCESSIBLE
private static final int
GET_SECURITY_PROPERTY
Constructors Summary
private PriviAction(int action, Object arg)

        this.action = action;
        this.arg1 = arg;
    
public PriviAction()
Creates a PrivilegedAction to get the current security policy object.

see
Policy#getPolicy

        action = GET_SECURITY_POLICY;
    
public PriviAction(AccessibleObject object)
Creates a PrivilegedAction to disable the access checks to the given object.

param
object the object whose accessible flag will be set to true
see
AccessibleObject#setAccessible(boolean)

        action = SET_ACCESSIBLE;
        arg1 = object;
    
public PriviAction(String property)
Creates a PrivilegedAction to return the value of the system property with the given key.

param
property the key of the system property
see
System#getProperty(String)

        action = GET_SYSTEM_PROPERTY;
        arg1 = property;
    
public PriviAction(String property, String defaultAnswer)
Creates a PrivilegedAction to return the value of the system property with the given key.

param
property the key of the system property
param
defaultAnswer the return value if the system property does not exist
see
System#getProperty(String, String)

        action = GET_SYSTEM_PROPERTY;
        arg1 = property;
        arg2 = defaultAnswer;
    
Methods Summary
public static java.security.PrivilegedActiongetSecurityProperty(java.lang.String property)
Creates a PrivilegedAction to get the security property with the given name.

param
property the name of the property
see
Security#getProperty


                                           
         
        return new PriviAction<String>(GET_SECURITY_PROPERTY, property);
    
public Trun()
Performs the actual privileged computation as defined by the constructor.

see
java.security.PrivilegedAction#run()

        switch (action) {
        case GET_SYSTEM_PROPERTY:
            return (T)System.getProperty((String) arg1, (String) arg2);
        case GET_SECURITY_PROPERTY:
            return (T)Security.getProperty((String) arg1);
        case GET_SECURITY_POLICY:
            return (T)Policy.getPolicy();
        case SET_ACCESSIBLE:
            ((AccessibleObject) arg1).setAccessible(true);
        }
        return null;