Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/StateFactory.java @ 2792:fe987587ebc9
Merged revisions 4539-4540,4543,4545-4546 via svnmerge from
file:///home/clients/bsh/bsh-generischer-viewer/Material/SVN/flys-artifacts/trunk
........
r4539 | teichmann | 2012-05-27 20:02:13 +0200 (So, 27 Mai 2012) | 1 line
FixA: Added forgotten csv/report facets/generators to conf.
........
r4540 | teichmann | 2012-05-27 20:11:31 +0200 (So, 27 Mai 2012) | 1 line
FixA: Fixed class cast bug in report facet.
........
r4543 | teichmann | 2012-05-28 20:35:01 +0200 (Mo, 28 Mai 2012) | 1 line
FixA: Added facet to return delta w/t as CSV
........
r4545 | teichmann | 2012-05-28 22:59:27 +0200 (Mo, 28 Mai 2012) | 1 line
FixA: Made Delta W/t calculation finally work
........
r4546 | teichmann | 2012-05-28 23:34:24 +0200 (Mo, 28 Mai 2012) | 1 line
FixA: corrected fitting (Q->W instead W->Q).
........
flys-artifacts/tags/2.7@4547 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 29 May 2012 04:58:29 +0000 |
parents | 45f7762767e2 |
children | e74e707ff650 |
line wrap: on
line source
package de.intevation.flys.artifacts.states; import javax.xml.xpath.XPathConstants; import org.apache.log4j.Logger; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import de.intevation.artifactdatabase.data.DefaultStateData; import de.intevation.artifactdatabase.state.State; import de.intevation.artifacts.common.utils.XMLUtils; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class StateFactory { /** The logger used in this class */ private static Logger logger = Logger.getLogger(StateFactory.class); /** The XPath to the classname of the state */ public static final String XPATH_STATE = "@state"; /** The XPath to the data items of the state relative to the state node. */ public static final String XPATH_DATA = "data"; /** The XPath to the data name relative to the data node.*/ public static final String XPATH_DATA_NAME = "@name"; /** The XPath to the data type relative to the data node.*/ public static final String XPATH_DATA_TYPE = "@type"; /** The XPath to the data description relative to the data node.*/ public static final String XPATH_DATA_DESCRIPTION = "@description"; /** * Creates a new State based on the configured class provided by * <code>stateConf</code>. * * @param stateConf The configuration of the state. * * @return a State. */ public static State createState(Node stateConf) { String clazz = (String) XMLUtils.xpath( stateConf, XPATH_STATE, XPathConstants.STRING); State state = null; try { logger.debug("Create a new State for class: " + clazz); state = (State) Class.forName(clazz).newInstance(); state.setup(stateConf); initializeStateData(state, stateConf); } catch (InstantiationException ie) { logger.error(ie, ie); } catch (IllegalAccessException iae) { logger.error(iae, iae); } catch (ClassNotFoundException cnfe) { logger.error(cnfe, cnfe); } return state; } /** * This method extracts the configured input data of a state and adds new * StateData objects to the State. * * @param state The state. * @param stateConf The state configuration node. */ protected static void initializeStateData(State state, Node stateConf) { NodeList dataList = (NodeList) XMLUtils.xpath( stateConf, XPATH_DATA, XPathConstants.NODESET); if (dataList == null || dataList.getLength() == 0) { logger.debug("The state has no input data configured."); return; } int items = dataList.getLength(); logger.debug("The state has " + items + " data items configured."); for (int i = 0; i < items; i++) { Node data = dataList.item(i); String name = (String) XMLUtils.xpath( data, XPATH_DATA_NAME, XPathConstants.STRING); String type = (String) XMLUtils.xpath( data, XPATH_DATA_TYPE, XPathConstants.STRING); String desc = (String) XMLUtils.xpath( data, XPATH_DATA_DESCRIPTION, XPathConstants.STRING); if (name == null || name.equals("")) { logger.warn("No name for data item at pos " + i + " found."); continue; } if (type == null || type.equals("")) { logger.warn("No type for data item at pos " + i + " found."); logger.warn("Default type 'string' used."); type = "string"; } logger.debug("add StateData '" + name + "' (type '" + type + "')"); state.addData(name, new DefaultStateData(name, desc, type)); } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :