ingo@1115: /* ingo@1115: * Copyright (c) 2010 by Intevation GmbH ingo@1115: * ingo@1115: * This program is free software under the LGPL (>=v2.1) ingo@1115: * Read the file LGPL.txt coming with the software for details ingo@1115: * or visit http://www.gnu.org/licenses/ if it does not exist. ingo@1115: */ ingo@1115: tim@335: package de.intevation.gnv.state; tim@335: sascha@779: import de.intevation.gnv.artifacts.GNVArtifactBase; sascha@779: tim@335: import org.apache.log4j.Logger; sascha@779: tim@335: import org.w3c.dom.Node; tim@335: tim@335: /** ingo@796: * This factory should be used to create new state objects with help of a ingo@796: * configuration segment. sascha@803: * sascha@780: * @author Tim Englich sascha@778: * 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: ingo@796: /** ingo@796: * Return the instance of this class. ingo@796: */ 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: ingo@796: /** ingo@796: * This method creates a new state with help of the information in ingo@796: * configuration and calls its setup method after creation. ingo@796: * ingo@796: * @return the new state. ingo@796: */ 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: } sascha@836: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :