GetPropertyAction.java revision 608:7e06bf1dcb09
1139826Simp/* 256723Sshin * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. 356723Sshin * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 456723Sshin * 556723Sshin * This code is free software; you can redistribute it and/or modify it 656723Sshin * under the terms of the GNU General Public License version 2 only, as 756723Sshin * published by the Free Software Foundation. Oracle designates this 856723Sshin * particular file as subject to the "Classpath" exception as provided 956723Sshin * by Oracle in the LICENSE file that accompanied this code. 1056723Sshin * 1156723Sshin * This code is distributed in the hope that it will be useful, but WITHOUT 1256723Sshin * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1356723Sshin * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1456723Sshin * version 2 for more details (a copy is included in the LICENSE file that 1556723Sshin * accompanied this code). 1656723Sshin * 1756723Sshin * You should have received a copy of the GNU General Public License version 1856723Sshin * 2 along with this work; if not, write to the Free Software Foundation, 1956723Sshin * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2056723Sshin * 2156723Sshin * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2256723Sshin * or visit www.oracle.com if you need additional information or have any 2356723Sshin * questions. 2456723Sshin */ 2556723Sshin 2656723Sshinpackage com.sun.corba.se.impl.orbutil ; 2756723Sshin 28174510Sobrien/** 29174510Sobrien * A convenience class for retrieving the string value of a system 3056723Sshin * property as a privileged action. This class is directly copied 3156723Sshin * from sun.security.action.GetPropertyAction in order to avoid 32139826Simp * depending on the sun.security.action package. 33120913Sume * 34120913Sume * <p>An instance of this class can be used as the argument of 35120913Sume * <code>AccessController.doPrivileged</code>. 36120913Sume * 37120913Sume * <p>The following code retrieves the value of the system 38120913Sume * property named <code>"prop"</code> as a privileged action: <p> 39120913Sume * 40120913Sume * <pre> 41120913Sume * String s = (String) java.security.AccessController.doPrivileged( 42120913Sume * new GetPropertyAction("prop")); 43120913Sume * </pre> 44120913Sume * 45120913Sume * @author Roland Schemers 46120913Sume * @author Ken Cavanaugh 47120913Sume * @see java.security.PrivilegedAction 48120913Sume * @see java.security.AccessController 49120913Sume */ 50120913Sume 51120913Sumepublic class GetPropertyAction implements java.security.PrivilegedAction { 52120913Sume private String theProp; 53120913Sume private String defaultVal; 54120913Sume 55120913Sume /** 56120913Sume * Constructor that takes the name of the system property whose 57120913Sume * string value needs to be determined. 58120913Sume * 59120913Sume * @param theProp the name of the system property. 60120913Sume */ 61120913Sume public GetPropertyAction(String theProp) { 62120913Sume this.theProp = theProp; 63120913Sume } 64174510Sobrien 65174510Sobrien /** 66120913Sume * Constructor that takes the name of the system property and the default 67120913Sume * value of that property. 68120913Sume * 6956723Sshin * @param theProp the name of the system property. 7056723Sshin * @param defaulVal the default value. 7156723Sshin */ 7256723Sshin public GetPropertyAction(String theProp, String defaultVal) { 7356723Sshin this.theProp = theProp; 7456723Sshin this.defaultVal = defaultVal; 7556723Sshin } 76120913Sume 7756723Sshin /** 7856723Sshin * Determines the string value of the system property whose 7956723Sshin * name was specified in the constructor. 8056723Sshin * 81174510Sobrien * @return the string value of the system property, 82174510Sobrien * or the default value if there is no property with that key. 83174510Sobrien */ 8462587Sitojun public Object run() { 85254889Smarkj String value = System.getProperty(theProp); 8656723Sshin return (value == null) ? defaultVal : value; 8756723Sshin } 8878064Sume} 8995759Stanimura