jdk/src/java.base/share/classes/sun/security/action/GetIntegerAction.java
changeset 37593 824750ada3d6
parent 30374 2abaf49910ea
child 37781 71ed5645f17c
equal deleted inserted replaced
37592:c80f098887f4 37593:824750ada3d6
    22  * or visit www.oracle.com if you need additional information or have any
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package sun.security.action;
    26 package sun.security.action;
       
    27 
       
    28 import java.security.AccessController;
    27 
    29 
    28 /**
    30 /**
    29  * A convenience class for retrieving the integer value of a system property
    31  * A convenience class for retrieving the integer value of a system property
    30  * as a privileged action.
    32  * as a privileged action.
    31  *
    33  *
    65 
    67 
    66 public class GetIntegerAction
    68 public class GetIntegerAction
    67         implements java.security.PrivilegedAction<Integer> {
    69         implements java.security.PrivilegedAction<Integer> {
    68     private String theProp;
    70     private String theProp;
    69     private int defaultVal;
    71     private int defaultVal;
    70     private boolean defaultSet = false;
    72     private boolean defaultSet;
    71 
    73 
    72     /**
    74     /**
    73      * Constructor that takes the name of the system property whose integer
    75      * Constructor that takes the name of the system property whose integer
    74      * value needs to be determined.
    76      * value needs to be determined.
    75      *
    77      *
   108         Integer value = Integer.getInteger(theProp);
   110         Integer value = Integer.getInteger(theProp);
   109         if ((value == null) && defaultSet)
   111         if ((value == null) && defaultSet)
   110             return defaultVal;
   112             return defaultVal;
   111         return value;
   113         return value;
   112     }
   114     }
       
   115 
       
   116     /**
       
   117      * Convenience method to get a property without going through doPrivileged
       
   118      * if no security manager is present. This is unsafe for inclusion in a
       
   119      * public API but allowable here since this class is now encapsulated.
       
   120      *
       
   121      * @param theProp the name of the system property.
       
   122      */
       
   123     public static Integer getProperty(String theProp) {
       
   124         if (System.getSecurityManager() == null) {
       
   125             return Integer.getInteger(theProp);
       
   126         } else {
       
   127             return AccessController.doPrivileged(
       
   128                     new GetIntegerAction(theProp));
       
   129         }
       
   130     }
       
   131 
       
   132     /**
       
   133      * Convenience method to get a property without going through doPrivileged
       
   134      * if no security manager is present. This is unsafe for inclusion in a
       
   135      * public API but allowable here since this class is now encapsulated.
       
   136      *
       
   137      * @param theProp the name of the system property.
       
   138      * @param defaultVal the default value.
       
   139      */
       
   140     public static Integer getProperty(String theProp, int defaultVal) {
       
   141         Integer value;
       
   142         if (System.getSecurityManager() == null) {
       
   143             value = Integer.getInteger(theProp);
       
   144         } else {
       
   145             value = AccessController.doPrivileged(
       
   146                     new GetIntegerAction(theProp));
       
   147         }
       
   148         return (value != null) ? value : defaultVal;
       
   149     }
   113 }
   150 }