001: /*
002: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package org.mandarax.kernel;
020:
021: import java.util.Enumeration;
022: import java.util.Properties;
023:
024: /**
025: * Abstract class implementing PropertySupport
026: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
027: * @version 3.4 <7 March 05>
028: * @since 2.0
029: */
030:
031: public abstract class AbstractPropertiesSupport implements
032: PropertiesSupport, java.io.Serializable {
033:
034: private Properties delegate = null;
035:
036: /**
037: * Set a property.
038: * @param key the key
039: * @param value the value
040: * @return the previous value of the specified key in this property list, or null if it did not have one.
041: */
042: public Object setProperty(String key, String value) {
043: if (delegate == null)
044: delegate = new Properties();
045: return delegate.setProperty(key, value);
046: }
047:
048: /**
049: * Get a property.
050: * @param key the property key
051: * @return the respective value. The method returns null if the property is not found.
052: */
053: public String getProperty(String key) {
054: if (delegate == null)
055: delegate = new Properties();
056: return delegate.getProperty(key);
057: }
058:
059: /**
060: * Returns an enumeration of all the keys in this property list, including distinct
061: * keys in the default property list if a key of the same name has not already been
062: * found from the main properties list.
063: * @return an enumeration of all the keys in this property list, including the keys in
064: * the default property list
065: */
066: public Enumeration propertyNames() {
067: if (delegate == null)
068: delegate = new Properties();
069: return delegate.propertyNames();
070: }
071:
072: /**
073: * Remove a property.
074: * @param key the property key
075: * @return the value to which the key had been mapped, or null if the key did not have a mapping.
076: */
077: public Object removeProperty(String key) {
078: if (delegate != null)
079: return delegate.remove(key);
080: return null;
081: }
082:
083: /**
084: * Get the properties as one "properties" instance.
085: * @return a properties instance
086: */
087: public Properties getProperties() {
088: if (delegate == null)
089: delegate = new Properties();
090: return delegate;
091: };
092:
093: /**
094: * Set the properties. Not required by the interface, but useful for bean (introspection-) based
095: * tools.
096: * @param properties the properties
097: */
098: public void setProperties(Properties properties) {
099: delegate = properties;
100: };
101: }
|