comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/StateFactory.java @ 1119:7c4f81f74c47

merged gnv-artifacts
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:00 +0200
parents f953c9a559d8
children
comparison
equal deleted inserted replaced
1027:fca4b5eb8d2f 1119:7c4f81f74c47
1 /*
2 * Copyright (c) 2010 by Intevation GmbH
3 *
4 * This program is free software under the LGPL (>=v2.1)
5 * Read the file LGPL.txt coming with the software for details
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
7 */
8
9 package de.intevation.gnv.state;
10
11 import de.intevation.gnv.artifacts.GNVArtifactBase;
12
13 import org.apache.log4j.Logger;
14
15 import org.w3c.dom.Node;
16
17 /**
18 * This factory should be used to create new state objects with help of a
19 * configuration segment.
20 *
21 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
22 *
23 */
24 public class StateFactory {
25
26 /**
27 * the logger, used to log exceptions and additonaly information
28 */
29 private static Logger log = Logger.getLogger(GNVArtifactBase.class);
30
31 private static StateFactory instance = null;
32
33 /**
34 * Constructor
35 */
36 public StateFactory() {
37 super();
38 }
39
40 /**
41 * Return the instance of this class.
42 */
43 public static StateFactory getInstance() {
44 if (instance == null) {
45 instance = new StateFactory();
46 }
47 return instance;
48 }
49
50 /**
51 * This method creates a new state with help of the information in <i>
52 * configuration</i> and calls its setup method after creation.
53 *
54 * @return the new state.
55 */
56 public State createState(Node configuration) {
57 log.debug("StateFactory.createState");
58 State state = null;
59 try {
60 String classname = ((org.w3c.dom.Element)configuration).getAttribute("state");
61 state = (State) (Class.forName(classname).newInstance());
62 state.setup(configuration);
63 } catch (InstantiationException e) {
64 log.error(e, e);
65 } catch (IllegalAccessException e) {
66 log.error(e, e);
67 } catch (ClassNotFoundException e) {
68 log.error(e, e);
69 }
70 return state;
71 }
72 }
73 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org