Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/StateFactory.java @ 108:50273a391e53
Added missing StateFactory class of the last commit.
flys-artifacts/trunk@1293 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 04 Feb 2011 11:11:03 +0000 |
parents | |
children | f077df8ad54c |
rev | line source |
---|---|
108
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.states; |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import javax.xml.xpath.XPathConstants; |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import org.apache.log4j.Logger; |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import org.w3c.dom.Node; |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import de.intevation.artifactdatabase.state.State; |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.artifacts.common.utils.XMLUtils; |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 /** |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 */ |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 public class StateFactory { |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 /** The logger used in this class */ |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 private static Logger logger = Logger.getLogger(StateFactory.class); |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 /** The XPath to the classname of the state */ |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 public static final String XPATH_STATE = "@state"; |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 /** |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 * Creates a new State based on the configured class provided by |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 * <code>stateConf</code>. |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 * |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 * @param stateConf The configuration of the state. |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 * |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 * @return a State. |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 */ |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 public static State createState(Node stateConf) { |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 String clazz = (String) XMLUtils.xpath( |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 stateConf, XPATH_STATE, XPathConstants.STRING); |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 State state = null; |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 try { |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 logger.debug("Create a new State for class: " + clazz); |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 state = (State) Class.forName(clazz).newInstance(); |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 state.setup(stateConf); |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 } |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 catch (InstantiationException ie) { |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 logger.error(ie, ie); |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 } |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 catch (IllegalAccessException iae) { |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 logger.error(iae, iae); |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 } |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 catch (ClassNotFoundException cnfe) { |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 logger.error(cnfe, cnfe); |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 } |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 return state; |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 } |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 } |
50273a391e53
Added missing StateFactory class of the last commit.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |