001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.util;
017:
018: import java.util.HashMap;
019: import java.util.Map;
020: import java.util.Properties;
021:
022: /**
023: * Manages properties so any property modifications are handled here.
024: *
025: * It lets us track the properties used and possibly remove some. They are all
026: * scattered in many places and it's so hard to keep track of them.
027: *
028: * The class holds all OpenEJB properties and optionally can amend the
029: * environment.
030: *
031: * The aim of this class is to establish one place to keep the properties and
032: * eventually remove the need to set System properties to communicate between
033: * parts and possibly yet lay out a foundation for setting them up in JNDI or
034: * some other means
035: *
036: * TODO: Should this class be concerned with concurrency issues?
037: *
038: * @org.apache.xbean.XBean element="propertiesService"
039: *
040: * @version $Rev: 494654 $ $Date: 2007-01-09 15:45:36 -0800 $
041: */
042: public class PropertiesService {
043: private Properties props = new Properties();
044:
045: /**
046: * Should properties be passed on to the environment?
047: */
048: private boolean passOn = true;
049:
050: /**
051: * Should the service query environment properties upon initialization?
052: */
053: private boolean queryEnvOnInit = true;
054:
055: public PropertiesService() {
056: if (queryEnvOnInit) {
057: props.putAll(System.getProperties());
058: }
059: }
060:
061: /**
062: * Set value to a property. Optionally set System property via
063: * {@link System#setProperty(String, String)}
064: *
065: * @param name
066: * property name
067: * @param value
068: * property value
069: * @return previous property value or null if the value hasn't been assigned
070: * yet
071: */
072: public String setProperty(String name, String value) {
073: if (passOn) {
074: System.setProperty(name, value);
075: }
076: return (String) props.setProperty(name, value);
077: }
078:
079: public String getProperty(String name) {
080: return (String) props.get(name);
081: }
082:
083: /**
084: * ISSUE: It might be of help to differentiate between unavailable property
085: * and boolean property set to false
086: *
087: * @param name
088: * property name
089: * @return true if property keyed by name is set; false otherwise
090: */
091: public boolean isSet(String name) {
092: return props.containsKey(name);
093: }
094:
095: public void putAll(Properties props) {
096: props.putAll(props);
097: }
098:
099: public Properties getProperties() {
100: return props;
101: }
102:
103: public boolean isPassOn() {
104: return passOn;
105: }
106:
107: public void setPassOn(boolean passOn) {
108: this .passOn = passOn;
109: }
110:
111: public boolean isQueryEnvOnInit() {
112: return queryEnvOnInit;
113: }
114:
115: public void setQueryEnvOnInit(boolean queryEnvOnInit) {
116: this.queryEnvOnInit = queryEnvOnInit;
117: }
118: }
|