comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/transitions/TransitionFactory.java @ 106:5864c41219db

Initializes a TransitionEngine storing all transitions for each artifact at the application start. flys-artifacts/trunk@1288 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 03 Feb 2011 10:23:30 +0000
parents
children a228b39494a9
comparison
equal deleted inserted replaced
105:beb991dc4827 106:5864c41219db
1 package de.intevation.flys.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 de.intevation.artifacts.common.utils.XMLUtils;
10
11
12 /**
13 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
14 */
15 public class TransitionFactory {
16
17 /** The logger used in this class */
18 private static Logger logger = Logger.getLogger(TransitionFactory.class);
19
20 /** The XPath to the classname of the transition */
21 public static final String XPATH_TRANSITION = "@transition";
22
23 /** The XPath to the current state ID */
24 public static final String XPATH_CURRENT_STATE = "from/@state";
25
26 /** The XPath to the target state ID */
27 public static final String XPATH_TARGET_STATE = "to/@state";
28
29
30 /**
31 * Creates a new Transition based on the configured class provided by
32 * <code>transitionConf</code>.
33 *
34 * @param transitionConf The configuration of the transition.
35 *
36 * @return a Transition.
37 */
38 public static Transition createTransition(Node transitionConf) {
39 String clazz = (String) XMLUtils.xpath(
40 transitionConf, XPATH_TRANSITION, XPathConstants.STRING);
41
42 Transition transition = null;
43
44 try {
45 transition = (Transition) Class.forName(clazz).newInstance();
46
47 String from = (String) XMLUtils.xpath(
48 transitionConf, XPATH_CURRENT_STATE, XPathConstants.STRING);
49 String to = (String) XMLUtils.xpath(
50 transitionConf, XPATH_TARGET_STATE, XPathConstants.STRING);
51
52 transition.setFrom(from);
53 transition.setTo(to);
54 }
55 catch (InstantiationException ie) {
56 logger.error(ie, ie);
57 }
58 catch (IllegalAccessException iae) {
59 logger.error(iae, iae);
60 }
61 catch (ClassNotFoundException cnfe) {
62 logger.error(cnfe, cnfe);
63 }
64
65 return transition;
66 }
67 }
68 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org