view flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/StateFactory.java @ 108:50273a391e53

Added missing StateFactory class of the last commit. flys-artifacts/trunk@1293 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 04 Feb 2011 11:11:03 +0000
parents
children f077df8ad54c
line wrap: on
line source
package de.intevation.flys.artifacts.states;

import javax.xml.xpath.XPathConstants;

import org.apache.log4j.Logger;

import org.w3c.dom.Node;

import de.intevation.artifactdatabase.state.State;

import de.intevation.artifacts.common.utils.XMLUtils;


/**
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class StateFactory {

    /** The logger used in this class */
    private static Logger logger = Logger.getLogger(StateFactory.class);

    /** The XPath to the classname of the state */
    public static final String XPATH_STATE = "@state";


    /**
     * Creates a new State based on the configured class provided by
     * <code>stateConf</code>.
     *
     * @param stateConf The configuration of the state.
     *
     * @return a State.
     */
    public static State createState(Node stateConf) {
        String clazz = (String) XMLUtils.xpath(
            stateConf, XPATH_STATE, XPathConstants.STRING);

        State state = null;

        try {
            logger.debug("Create a new State for class: " + clazz);
            state = (State) Class.forName(clazz).newInstance();
            state.setup(stateConf);
        }
        catch (InstantiationException ie) {
            logger.error(ie, ie);
        }
        catch (IllegalAccessException iae) {
            logger.error(iae, iae);
        }
        catch (ClassNotFoundException cnfe) {
            logger.error(cnfe, cnfe);
        }

        return state;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org