All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.main.java.com.eva.properties.Properties Maven / Gradle / Ivy

Go to download

Advanced properties with object factories, references and inheritance.

There is a newer version: 0.3
Show newest version
/*
 * $Id: Properties.java 23 2007-02-16 07:44:41Z max $
 * 
 * Copyright (c) 2006-2007 Maximilian Antoni. All rights reserved.
 * 
 * This software is licensed as described in the file LICENSE.txt, which you
 * should have received as part of this distribution. The terms are also
 * available at http://www.maxantoni.de/projects/eva-properties/license.txt.
 */
package com.eva.properties;

/**
 * @author Max Antoni
 * @version $Revision: 23 $
 */
abstract class Properties {
    private Properties parent;
    
    /**
     * creates new properties with parent properties. The parent properties may
     * be null, indicating that there is no parent for these
     * properties.
     * 
     * @param inParent the parent properties.
     */
    Properties(Properties inParent) {
        super();
        parent = inParent;
    }
    
    /* 
     * @see java.lang.Object#toString()
     */
    public String toString() {
        Writer writer = new Writer();
        write(writer);
        return writer.toString();
    }
    
    /**
     * creates a deep copy of this properties object.
     * 
     * @param inParent the parent to use for the copy.
     * @return the new properties.
     */
    abstract Properties copy(Properties inParent);
    
    /**
     * returns the parent properties for this properties object.
     * 
     * @return the parent properties.
     */
    Properties getParent() {
        return parent;
    }
    
    /**
     * sets the parent of this properties object.
     * 
     * @param inParent the parent.
     */
    void setParent(Properties inParent) {
        if(parent != null) {
            throw new PropertiesException(
                    "Properties object has already a parent.");
        }
        parent = inParent;
    }
    
    /**
     * reads a property spcified by the given key from this properties object.
     * 
     * @param inContext the context.
     * @param inKey the key.
     * @return the value.
     * @throws PropertiesException
     */
    abstract Object getProperty(Context inContext, String inKey)
            throws PropertiesException;
    
    /**
     * associates an object with a key in this properties object.
     * 
     * @param inContext the context.
     * @param inKey the key.
     * @param inValue the value.
     * @return the previous object stored under the given key, or
     *         null if no such object exists.
     * @throws PropertiesException
     */
    abstract Object putProperty(Context inContext, String inKey, Object inValue)
            throws PropertiesException;

    /**
     * writes this properties object to the given writer.
     * 
     * @param inoutWriter the writer.
     */
    abstract void write(Writer inoutWriter);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy