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: /**
20: * @author Mikhail A. Markov
21: * @version $Revision: 1.1.2.2 $
22: */package org.apache.harmony.rmi.common;
23:
24: import java.security.PrivilegedAction;
25:
26: /**
27: * Action for obtaining boolean value from properties.
28: *
29: * @author Mikhail A. Markov
30: * @version $Revision: 1.1.2.2 $
31: */
32: public class GetBooleanPropAction implements PrivilegedAction {
33:
34: // the name of the property to be obtained
35: private String propName;
36:
37: // default value for the property
38: private Boolean defaultVal;
39:
40: /**
41: * Constructs GetBooleanPropAction to read property with the given name.
42: *
43: * @param propName the name of the property to be read
44: */
45: public GetBooleanPropAction(String propName) {
46: this .propName = propName;
47: defaultVal = new Boolean(false);
48: }
49:
50: /**
51: * Constructs GetBooleanPropAction to read property with the given name
52: * and the specified default value.
53: *
54: * @param propName the name of the property to be read
55: * @param defaultVal default value for the property
56: */
57: public GetBooleanPropAction(String propName, boolean defaultVal) {
58: this .propName = propName;
59: this .defaultVal = new Boolean(defaultVal);
60: }
61:
62: /**
63: * Obtains boolean value from the property with the name specified in
64: * constructor and returns it as a result (if this property does not
65: * exist - the default value will be returned).
66: *
67: * @return value read or the default value if property to be read is not set
68: */
69: public Object run() {
70: String propVal = System.getProperty(propName);
71: return (propVal == null) ? defaultVal : Boolean
72: .valueOf(propVal);
73: }
74: }
|