01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: *
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: package org.apache.harmony.rmi.common;
20:
21: import java.security.PrivilegedAction;
22:
23: /**
24: * Action for obtaining properties holding string values.
25: */
26: public class GetStringPropAction implements PrivilegedAction<String> {
27: // the name of the property to be obtained
28: private final String propName;
29:
30: // default value for the property
31: private final String defaultVal;
32:
33: /**
34: * Constructs GetStringPropAction to read property with the given name.
35: *
36: * @param propName the name of the property to be read
37: */
38: public GetStringPropAction(String propName) {
39: this (propName, null);
40: }
41:
42: /**
43: * Constructs GetStringPropAction to read property with the given name
44: * and the specified default value.
45: *
46: * @param propName the name of the property to be read
47: * @param defaultVal default value for the property
48: */
49: public GetStringPropAction(String propName, String defaultVal) {
50: this .propName = propName;
51: this .defaultVal = defaultVal;
52: }
53:
54: /**
55: * Reads the property with the name specified in constructor and returns it
56: * as a result; if value read is null, then default value (possibly
57: * null) will be returned.
58: *
59: * @return property read or defaultValue if property read is null
60: */
61: public String run() {
62: return System.getProperty(propName, defaultVal);
63: }
64: }
|