/*
 * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
package org.mandarax.kernel;

import java.util.Enumeration;
import java.util.Properties;

/**
 * Abstract class implementing PropertySupport
 * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
 * @version 3.3.1 <9 August 2004>
 * @since 2.0
 */

public abstract class AbstractPropertiesSupport implements PropertiesSupport, java.io.Serializable {
	
	private Properties delegate = null;
	
	/**
	 * Set a property.
	 * @param key the key
	 * @param value the value
	 * @return the previous value of the specified key in this property list, or null if it did not have one.
	 */
	public Object setProperty(String key,String value) {
		if (delegate==null) delegate = new Properties();
		return delegate.setProperty(key,value);	
	}
	/**
	 * Get a property.
	 * @param key the property key
	 * @return the respective value. The method returns null if the property is not found. 
	 */
	public String getProperty(String key) {
		if (delegate==null) delegate = new Properties();
		return delegate.getProperty(key);		
	}
	/** 
	 * Returns an enumeration of all the keys in this property list, including distinct 
	 * keys in the default property list if a key of the same name has not already been 
	 * found from the main properties list. 
	 * @return an enumeration of all the keys in this property list, including the keys in 
	 * the default property list
	 */
	public Enumeration propertyNames() {
		if (delegate==null) delegate = new Properties();
		return delegate.propertyNames();	
	}
	/**
	 * Remove a property.
	 * @param key the property key
	 * @return the value to which the key had been mapped, or null if the key did not have a mapping.
	 */
	public Object removeProperty(String key) {
		if (delegate!=null) return delegate.remove(key);
		return null;
	}
	/**
	 * Get the properties as one "properties" instance.
	 * @return a properties instance
	 */
	public Properties getProperties() {
		if (delegate==null) delegate = new Properties();
		return delegate;
	};
	/**
	 * Set the properties. Not required by the interface, but useful for bean (introspection-) based
	 * tools.
	 * @param properties the properties
	 */
	public void setProperties(Properties properties) {
		delegate = properties;
	};
}
