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

com.googlecode.jpattern.ioc.property.AbstractPropertyReader Maven / Gradle / Ivy

package com.googlecode.jpattern.ioc.property;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import com.googlecode.jpattern.ioc.IPropertyReader;
import com.googlecode.jpattern.ioc.exception.ConfigException;
/**
 * 
 * @author Claudio Quaresima - [email protected] - 26/ott/08 11:58:39
 * @version $Id: $
 */
public abstract class AbstractPropertyReader implements IPropertyReader {

    protected Properties _properties = new Properties();
    
    private String location;
    
    public AbstractPropertyReader() {
        super();
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public void load() throws ConfigException {
            try {
                _properties.load(  new FileInputStream(  new File(getLocation())  ) );
            }
            catch (FileNotFoundException e) {
                throw new ConfigException(e);
            }
            catch (IOException e) {
                throw new ConfigException(e);
            }
    }

    public abstract String property(String aProperty);
    
    protected String parse(String aProperty, String prefix, String suffix) {
        int start = aProperty.indexOf(prefix);
        int stop = aProperty.indexOf(suffix);
        aProperty = aProperty.substring(start + (prefix.length()),stop);
        return aProperty ;
    }    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy