tim@335: /**
tim@335:  *
tim@335:  */
tim@335: package de.intevation.gnv.state;
tim@335: 
tim@335: import org.apache.log4j.Logger;
tim@335: import org.w3c.dom.Node;
tim@335: 
tim@335: import de.intevation.gnv.artifacts.GNVArtifactBase;
tim@335: 
tim@335: /**
tim@335:  * @author Tim Englich <tim.englich@intevation.de>
tim@335:  * 
tim@335:  */
tim@335: public class StateFactory {
tim@335: 
tim@335:     /**
tim@335:      * the logger, used to log exceptions and additonaly information
tim@335:      */
tim@335:     private static Logger log = Logger.getLogger(GNVArtifactBase.class);
tim@335: 
tim@335:     private static StateFactory instance = null;
tim@335: 
tim@335:     /**
tim@335:      * Constructor
tim@335:      */
tim@335:     public StateFactory() {
tim@335:         super();
tim@335:     }
tim@335: 
tim@335:     public static StateFactory getInstance() {
tim@335:         if (instance == null) {
tim@335:             instance = new StateFactory();
tim@335:         }
tim@335:         return instance;
tim@335:     }
tim@335: 
tim@335:     public State createState(Node configuration) {
tim@335:         log.debug("StateFactory.createState");
tim@335:         State state = null;
tim@335:         try {
tim@335:             String classname = ((org.w3c.dom.Element)configuration).getAttribute("state");
tim@335:             state = (State) (Class.forName(classname).newInstance());
tim@335:             state.setup(configuration);
tim@335:         } catch (InstantiationException e) {
tim@335:             log.error(e, e);
tim@335:         } catch (IllegalAccessException e) {
tim@335:             log.error(e, e);
tim@335:         } catch (ClassNotFoundException e) {
tim@335:             log.error(e, e);
tim@335:         }
tim@335:         return state;
tim@335:     }
tim@335: 
tim@335: }