KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > orbutil > GetPropertyAction


1 /*
2  * @(#)GetPropertyAction.java 1.1 04/01/16
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.orbutil ;
9
10 /**
11  * A convenience class for retrieving the string value of a system
12  * property as a privileged action. This class is directly copied
13  * from sun.security.action.GetPropertyAction in order to avoid
14  * depending on the sun.security.action package.
15  *
16  * <p>An instance of this class can be used as the argument of
17  * <code>AccessController.doPrivileged</code>.
18  *
19  * <p>The following code retrieves the value of the system
20  * property named <code>"prop"</code> as a privileged action: <p>
21  *
22  * <pre>
23  * String s = (String) java.security.AccessController.doPrivileged(
24  * new GetPropertyAction("prop"));
25  * </pre>
26  *
27  * @author Roland Schemers
28  * @author Ken Cavanaugh
29  * @see java.security.PrivilegedAction
30  * @see java.security.AccessController
31  */

32
33 public class GetPropertyAction implements java.security.PrivilegedAction JavaDoc {
34     private String JavaDoc theProp;
35     private String JavaDoc defaultVal;
36
37     /**
38      * Constructor that takes the name of the system property whose
39      * string value needs to be determined.
40      *
41      * @param theProp the name of the system property.
42      */

43     public GetPropertyAction(String JavaDoc theProp) {
44     this.theProp = theProp;
45     }
46
47     /**
48      * Constructor that takes the name of the system property and the default
49      * value of that property.
50      *
51      * @param theProp the name of the system property.
52      * @param defaulVal the default value.
53      */

54     public GetPropertyAction(String JavaDoc theProp, String JavaDoc defaultVal) {
55     this.theProp = theProp;
56     this.defaultVal = defaultVal;
57     }
58
59     /**
60      * Determines the string value of the system property whose
61      * name was specified in the constructor.
62      *
63      * @return the string value of the system property,
64      * or the default value if there is no property with that key.
65      */

66     public Object JavaDoc run() {
67     String JavaDoc value = System.getProperty(theProp);
68     return (value == null) ? defaultVal : value;
69     }
70 }
71
Popular Tags