public class GetIntegerAction
extends java.lang.Object
implements java.security.PrivilegedAction<java.lang.Integer>
An instance of this class can be used as the argument of
AccessController.doPrivileged.
The following code retrieves the integer value of the system
property named "prop" as a privileged action. Since it does
not pass a default value to be used in case the property
"prop" is not defined, it has to check the result for
null:
Integer tmp = java.security.AccessController.doPrivileged
(new sun.security.action.GetIntegerAction("prop"));
int i;
if (tmp != null) {
i = tmp.intValue();
}
The following code retrieves the integer value of the system
property named "prop" as a privileged action, and also passes
a default value to be used in case the property "prop" is not
defined:
int i = ((Integer)java.security.AccessController.doPrivileged(
new GetIntegerAction("prop", 3))).intValue();
PrivilegedAction,
AccessController| Constructor and Description |
|---|
GetIntegerAction(java.lang.String theProp)
Constructor that takes the name of the system property whose integer
value needs to be determined.
|
GetIntegerAction(java.lang.String theProp,
int defaultVal)
Constructor that takes the name of the system property and the default
value of that property.
|
| Modifier and Type | Method and Description |
|---|---|
static java.lang.Integer |
privilegedGetProperty(java.lang.String theProp)
Convenience method to get a property without going through doPrivileged
if no security manager is present.
|
static java.lang.Integer |
privilegedGetProperty(java.lang.String theProp,
int defaultVal)
Convenience method to get a property without going through doPrivileged
if no security manager is present.
|
java.lang.Integer |
run()
Determines the integer value of the system property whose name was
specified in the constructor.
|
public GetIntegerAction(java.lang.String theProp)
theProp - the name of the system property.public GetIntegerAction(java.lang.String theProp,
int defaultVal)
theProp - the name of the system property.defaultVal - the default value.public java.lang.Integer run()
If there is no property of the specified name, or if the property
does not have the correct numeric format, then an Integer
object representing the default value that was specified in the
constructor is returned, or null if no default value was
specified.
run in interface java.security.PrivilegedAction<java.lang.Integer>Integer value of the property.public static java.lang.Integer privilegedGetProperty(java.lang.String theProp)
theProp - the name of the system property.public static java.lang.Integer privilegedGetProperty(java.lang.String theProp,
int defaultVal)
theProp - the name of the system property.defaultVal - the default value.