comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/StateFactory.java @ 875:5e9efdda6894

merged gnv-artifacts/1.0
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:13:56 +0200
parents 05bf8534a35a
children f953c9a559d8
comparison
equal deleted inserted replaced
722:bb3ffe7d719e 875:5e9efdda6894
1 package de.intevation.gnv.state;
2
3 import de.intevation.gnv.artifacts.GNVArtifactBase;
4
5 import org.apache.log4j.Logger;
6
7 import org.w3c.dom.Node;
8
9 /**
10 * This factory should be used to create new state objects with help of a
11 * configuration segment.
12 *
13 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
14 *
15 */
16 public class StateFactory {
17
18 /**
19 * the logger, used to log exceptions and additonaly information
20 */
21 private static Logger log = Logger.getLogger(GNVArtifactBase.class);
22
23 private static StateFactory instance = null;
24
25 /**
26 * Constructor
27 */
28 public StateFactory() {
29 super();
30 }
31
32 /**
33 * Return the instance of this class.
34 */
35 public static StateFactory getInstance() {
36 if (instance == null) {
37 instance = new StateFactory();
38 }
39 return instance;
40 }
41
42 /**
43 * This method creates a new state with help of the information in <i>
44 * configuration</i> and calls its setup method after creation.
45 *
46 * @return the new state.
47 */
48 public State createState(Node configuration) {
49 log.debug("StateFactory.createState");
50 State state = null;
51 try {
52 String classname = ((org.w3c.dom.Element)configuration).getAttribute("state");
53 state = (State) (Class.forName(classname).newInstance());
54 state.setup(configuration);
55 } catch (InstantiationException e) {
56 log.error(e, e);
57 } catch (IllegalAccessException e) {
58 log.error(e, e);
59 } catch (ClassNotFoundException e) {
60 log.error(e, e);
61 }
62 return state;
63 }
64 }
65 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org