Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/transitions/TransitionFactory.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/artifacts/transitions/TransitionFactory.java@542f280d72c3 |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.artifacts.transitions; | |
2 | |
3 import javax.xml.xpath.XPathConstants; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import org.w3c.dom.Node; | |
8 | |
9 import org.dive4elements.artifactdatabase.transition.Transition; | |
10 | |
11 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
12 | |
13 | |
14 /** | |
15 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
16 */ | |
17 public class TransitionFactory { | |
18 | |
19 /** The logger used in this class */ | |
20 private static Logger logger = Logger.getLogger(TransitionFactory.class); | |
21 | |
22 /** The XPath to the classname of the transition */ | |
23 public static final String XPATH_TRANSITION = "@transition"; | |
24 | |
25 /** The XPath to the current state ID */ | |
26 public static final String XPATH_CURRENT_STATE = "from/@state"; | |
27 | |
28 /** The XPath to the target state ID */ | |
29 public static final String XPATH_TARGET_STATE = "to/@state"; | |
30 | |
31 | |
32 /** | |
33 * Creates a new Transition based on the configured class provided by | |
34 * <code>transitionConf</code>. | |
35 * | |
36 * @param transitionConf The configuration of the transition. | |
37 * | |
38 * @return a Transition. | |
39 */ | |
40 public static Transition createTransition(Node transitionConf) { | |
41 String clazz = (String) XMLUtils.xpath( | |
42 transitionConf, XPATH_TRANSITION, XPathConstants.STRING); | |
43 | |
44 Transition transition = null; | |
45 | |
46 try { | |
47 transition = (Transition) Class.forName(clazz).newInstance(); | |
48 | |
49 String from = (String) XMLUtils.xpath( | |
50 transitionConf, XPATH_CURRENT_STATE, XPathConstants.STRING); | |
51 String to = (String) XMLUtils.xpath( | |
52 transitionConf, XPATH_TARGET_STATE, XPathConstants.STRING); | |
53 | |
54 transition.init(transitionConf); | |
55 transition.setFrom(from); | |
56 transition.setTo(to); | |
57 } | |
58 catch (InstantiationException ie) { | |
59 logger.error(ie, ie); | |
60 } | |
61 catch (IllegalAccessException iae) { | |
62 logger.error(iae, iae); | |
63 } | |
64 catch (ClassNotFoundException cnfe) { | |
65 logger.error(cnfe, cnfe); | |
66 } | |
67 | |
68 return transition; | |
69 } | |
70 } | |
71 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |