tim@337: package de.intevation.gnv.transition;
tim@337: 
tim@824: import org.apache.log4j.Logger;
tim@824: import org.w3c.dom.Node;
tim@824: 
sascha@779: import de.intevation.gnv.artifacts.GNVArtifactBase;
sascha@779: 
tim@337: /**
tim@824:  * This Factoryclass instantiates Objects of Type Transition.
sascha@780:  * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
sascha@778:  *
tim@337:  */
tim@337: public class TransitionFactory {
tim@337: 
tim@337:     /**
tim@337:      * the logger, used to log exceptions and additonaly information
tim@337:      */
tim@337:     private static Logger log = Logger.getLogger(GNVArtifactBase.class);
tim@337: 
tim@824:     /**
tim@824:      * The Singleton instance of the Transitionfactory.
tim@824:      */
tim@337:     private static TransitionFactory instance = null;
tim@337: 
tim@337:     /**
tim@337:      * Constructor
tim@337:      */
tim@337:     public TransitionFactory() {
tim@337:         super();
tim@337:     }
tim@337: 
tim@824:     /**
tim@824:      * Returns the Instance of this Class.
tim@824:      * @return the Instance of this Class.
tim@824:      */
tim@337:     public static TransitionFactory getInstance() {
tim@337:         if (instance == null) {
tim@337:             instance = new TransitionFactory();
tim@337:         }
tim@337:         return instance;
tim@337:     }
tim@337: 
tim@824:     /**
tim@824:      * Creates a new Transition using the Configuration that is provided by the
tim@824:      * XML-Node.
sascha@835:      * @param configuration The configuration that should be used to initialize
tim@824:      *                      the new Transition
tim@824:      * @return a new Transition.
tim@824:      */
tim@337:     public Transition createTransition(Node configuration) {
tim@337:         log.debug("TransitionFactory.createTransition");
tim@337:         Transition state = null;
tim@337:         try {
tim@337:             String classname = ((org.w3c.dom.Element)configuration).getAttribute("transition");
tim@337:             state = (Transition) (Class.forName(classname).newInstance());
tim@337:             state.setup(configuration);
tim@337:         } catch (InstantiationException e) {
tim@337:             log.error(e, e);
tim@337:         } catch (IllegalAccessException e) {
tim@337:             log.error(e, e);
tim@337:         } catch (ClassNotFoundException e) {
tim@337:             log.error(e, e);
tim@337:         }
tim@337:         return state;
tim@337:     }
tim@337: }
sascha@836: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :