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

src.main.java.com.eva.properties.Reference 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: Reference.java 22 2007-02-12 21:57:00Z 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;

/**
 * is a reference of the form ${house.room.chair.0.color}.
 * 
 * @author Max Antoni
 * @version $Revision: 22 $
 */
public class Reference implements Replaceable {
    private String reference;

    /**
     * creates a reference with a reference string.
     * 
     * @param inReference the reference.
     */
    public Reference(String inReference) {
        super();
        if(inReference == null) {
            throw new NullPointerException("Reference cannot be null.");
        }
        if("".equals(inReference)) {
            throw new IllegalArgumentException("Reference cannot be empty.");
        }
        reference = inReference;
    }
    
    /*
     * @see com.eva.properties.Replaceable#copy(com.eva.properties.Properties)
     */
    public Replaceable copy(Properties inParent) {
        return new Reference(reference);
    }

    /* 
     * @see com.eva.properties.Replaceable#replace(com.eva.properties.Context)
     */
    public Object replace(Context inContext) throws PropertiesException {
        return inContext.lookup(reference);
    }

    /* 
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return "${" + reference + "}";
    }

    /*
     * @see com.eva.properties.Replaceable#toString(java.lang.StringBuffer,
     *      java.lang.String)
     */
    public void write(Writer inoutWriter) {
        inoutWriter.append("${");
        inoutWriter.append(reference);
        inoutWriter.append("}");
        inoutWriter.appendNewline();
    }

    /**
     * returns the reference string for this reference.
     * 
     * @return the reference string.
     */
    String getReference() {
        return reference;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy