[Dive4elements-commits] [PATCH 3 of 5] FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory)
Wald Commits
scm-commit at wald.intevation.org
Sun Apr 28 15:29:51 CEST 2013
# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1367154870 -7200
# Node ID 9a6741ccf6d4a00d22ceb0b585d7a5d384a46473
# Parent 73da40528cf2f03b56b70ab0552f9d743e784431
FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/doc/conf/conf.xml
--- a/artifacts/doc/conf/conf.xml Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/doc/conf/conf.xml Sun Apr 28 15:14:30 2013 +0200
@@ -11,7 +11,7 @@
<artifact-database>
<export-secret>YOUR_SECRET</export-secret>
<factories>
- <context-factory>org.dive4elements.river.artifacts.context.FLYSContextFactory</context-factory>
+ <context-factory>org.dive4elements.river.artifacts.context.RiverContextFactory</context-factory>
<collection-factory
name="DefaultArtifactCollectionFactory"
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/artifacts/AnnotationArtifact.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/AnnotationArtifact.java Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/AnnotationArtifact.java Sun Apr 28 15:14:30 2013 +0200
@@ -34,7 +34,7 @@
import org.dive4elements.artifacts.common.utils.XMLUtils;
import org.dive4elements.river.artifacts.states.DefaultState;
-import org.dive4elements.river.artifacts.context.FLYSContext;
+import org.dive4elements.river.artifacts.context.RiverContext;
import org.dive4elements.river.utils.RiverUtils;
@@ -207,9 +207,9 @@
{
List<String> stateIds = getPreviousStateIds();
- FLYSContext flysContext = RiverUtils.getFlysContext(context);
+ RiverContext flysContext = RiverUtils.getFlysContext(context);
StateEngine engine = (StateEngine) flysContext.get(
- FLYSContext.STATE_ENGINE_KEY);
+ RiverContext.STATE_ENGINE_KEY);
for (String stateId: stateIds) {
logger.debug("Append output modes for state: " + stateId);
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/artifacts/ChartArtifact.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/ChartArtifact.java Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/ChartArtifact.java Sun Apr 28 15:14:30 2013 +0200
@@ -33,7 +33,7 @@
import org.dive4elements.river.utils.RiverUtils;
import org.dive4elements.river.artifacts.states.DefaultState;
-import org.dive4elements.river.artifacts.context.FLYSContext;
+import org.dive4elements.river.artifacts.context.RiverContext;
import org.dive4elements.river.artifacts.resources.Resources;
@@ -89,9 +89,9 @@
{
List<String> stateIds = getPreviousStateIds();
- FLYSContext flysContext = RiverUtils.getFlysContext(context);
+ RiverContext flysContext = RiverUtils.getFlysContext(context);
StateEngine engine = (StateEngine) flysContext.get(
- FLYSContext.STATE_ENGINE_KEY);
+ RiverContext.STATE_ENGINE_KEY);
for (String stateId: stateIds) {
logger.debug("Append output modes for state: " + stateId);
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/artifacts/FLYSArtifact.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/FLYSArtifact.java Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/FLYSArtifact.java Sun Apr 28 15:14:30 2013 +0200
@@ -51,7 +51,7 @@
import org.dive4elements.artifacts.common.utils.XMLUtils;
import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
import org.dive4elements.river.artifacts.cache.CacheFactory;
-import org.dive4elements.river.artifacts.context.FLYSContext;
+import org.dive4elements.river.artifacts.context.RiverContext;
import org.dive4elements.river.artifacts.model.CalculationMessage;
import org.dive4elements.river.artifacts.states.DefaultState;
import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
@@ -139,9 +139,9 @@
{
List<String> stateIds = getPreviousStateIds();
- FLYSContext flysContext = RiverUtils.getFlysContext(context);
+ RiverContext flysContext = RiverUtils.getFlysContext(context);
StateEngine engine = (StateEngine) flysContext.get(
- FLYSContext.STATE_ENGINE_KEY);
+ RiverContext.STATE_ENGINE_KEY);
boolean debug = log.isDebugEnabled();
@@ -191,7 +191,7 @@
super.setup(identifier, factory, context, callMeta, data);
- FLYSContext flysContext = RiverUtils.getFlysContext(context);
+ RiverContext flysContext = RiverUtils.getFlysContext(context);
List<State> states = getStates(context);
@@ -447,13 +447,13 @@
dumpArtifact();
}
- FLYSContext flysContext = RiverUtils.getFlysContext(context);
+ RiverContext flysContext = RiverUtils.getFlysContext(context);
StateEngine stateEngine = (StateEngine) flysContext.get(
- FLYSContext.STATE_ENGINE_KEY);
+ RiverContext.STATE_ENGINE_KEY);
TransitionEngine transitionEngine = (TransitionEngine) flysContext.get(
- FLYSContext.TRANSITION_ENGINE_KEY);
+ RiverContext.TRANSITION_ENGINE_KEY);
List<State> reachable = transitionEngine.getReachableStates(
this, getCurrentState(context), stateEngine);
@@ -704,9 +704,9 @@
* @return list of states.
*/
protected List<State> getStates(Object context) {
- FLYSContext flysContext = RiverUtils.getFlysContext(context);
+ RiverContext flysContext = RiverUtils.getFlysContext(context);
StateEngine engine = (StateEngine) flysContext.get(
- FLYSContext.STATE_ENGINE_KEY);
+ RiverContext.STATE_ENGINE_KEY);
return engine.getStates(getName());
}
@@ -718,9 +718,9 @@
* @return state with given ID.
*/
protected State getState(Object context, String stateID) {
- FLYSContext flysContext = RiverUtils.getFlysContext(context);
+ RiverContext flysContext = RiverUtils.getFlysContext(context);
StateEngine engine = (StateEngine) flysContext.get(
- FLYSContext.STATE_ENGINE_KEY);
+ RiverContext.STATE_ENGINE_KEY);
return engine.getState(stateID);
}
@@ -979,9 +979,9 @@
DefaultState current = (DefaultState) getCurrentState(context);
- FLYSContext flysContext = RiverUtils.getFlysContext(context);
+ RiverContext flysContext = RiverUtils.getFlysContext(context);
StateEngine engine = (StateEngine) flysContext.get(
- FLYSContext.STATE_ENGINE_KEY);
+ RiverContext.STATE_ENGINE_KEY);
for (int i = 0; i < count; i++) {
Element node = (Element)nodes.item(i);
@@ -1031,14 +1031,14 @@
log.debug("Determine if the state '" + stateId + "' is reachable.");
}
- FLYSContext flysContext = RiverUtils.getFlysContext(context);
+ RiverContext flysContext = RiverUtils.getFlysContext(context);
State currentState = getCurrentState(context);
StateEngine sEngine = (StateEngine) flysContext.get(
- FLYSContext.STATE_ENGINE_KEY);
+ RiverContext.STATE_ENGINE_KEY);
TransitionEngine tEngine = (TransitionEngine) flysContext.get(
- FLYSContext.TRANSITION_ENGINE_KEY);
+ RiverContext.TRANSITION_ENGINE_KEY);
return tEngine.isStateReachable(this, stateId, currentState, sEngine);
}
@@ -1534,7 +1534,7 @@
* Calls endOfLife() for each state in the list <i>ids</i>.
*
* @param ids The State IDs that should be destroyed.
- * @param context The FLYSContext.
+ * @param context The RiverContext.
*/
protected void destroyStates(List<String> ids, Object context) {
for (int i = 0, num = ids.size(); i < num; i++) {
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/artifacts/MapArtifact.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/MapArtifact.java Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/MapArtifact.java Sun Apr 28 15:14:30 2013 +0200
@@ -18,7 +18,7 @@
import org.dive4elements.artifacts.CallMeta;
import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
import org.dive4elements.river.artifacts.RiverAxisArtifact.RiverAxisState;
-import org.dive4elements.river.artifacts.context.FLYSContext;
+import org.dive4elements.river.artifacts.context.RiverContext;
import org.dive4elements.river.artifacts.model.map.WMSDBLayerFacet;
import org.dive4elements.river.artifacts.states.DefaultState;
import org.dive4elements.river.model.River;
@@ -84,9 +84,9 @@
{
List<String> stateIds = getPreviousStateIds();
- FLYSContext flysContext = RiverUtils.getFlysContext(context);
+ RiverContext flysContext = RiverUtils.getFlysContext(context);
StateEngine engine = (StateEngine) flysContext.get(
- FLYSContext.STATE_ENGINE_KEY);
+ RiverContext.STATE_ENGINE_KEY);
for (String stateId: stateIds) {
logger.debug("Append output modes for state: " + stateId);
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/artifacts/context/FLYSContext.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/context/FLYSContext.java Sun Apr 28 15:09:31 2013 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,124 +0,0 @@
-/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
- * Software engineering by Intevation GmbH
- *
- * This file is Free Software under the GNU AGPL (>=v3)
- * and comes with ABSOLUTELY NO WARRANTY! Check out the
- * documentation coming with Dive4Elements River for details.
- */
-
-package org.dive4elements.river.artifacts.context;
-
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-
-import org.w3c.dom.Document;
-
-import org.dive4elements.artifactdatabase.DefaultArtifactContext;
-import org.dive4elements.artifacts.CallContext;
-import org.dive4elements.river.exports.OutGenerator;
-
-
-/**
- * This class is used to store application wide information in a global context.
- *
- * @author <a href="mailto:ingo.weinzierl at intevation.de">Ingo Weinzierl</a>
- */
-public class FLYSContext extends DefaultArtifactContext {
-
- /** The logger used in this class. */
- private static Logger logger = Logger.getLogger(FLYSContext.class);
-
- /** The key that is used to store the StateEngine in the context. */
- public static final String ARTIFACT_KEY =
- "artifact";
-
- /** The key that is used to store the TransitionEngine in the context. */
- public static final String TRANSITION_ENGINE_KEY =
- "artifact.transition.engine";
-
- /** The key that is used to store the StateEngine in the context. */
- public static final String STATE_ENGINE_KEY =
- "artifact.state.engine";
-
- /** The key that is used to store the Map of OutGenerator classes in the
- * context. */
- public static final String OUTGENERATORS_KEY =
- "flys.export.outgenerators";
-
- /** The key that is used to store the map of themes in the context. */
- public static final String THEMES =
- "flys.themes.map";
-
- /** The key that is used to store a map of theme mappings in the context. */
- public static final String THEME_MAPPING =
- "flys.themes.mapping.map";
-
- /** The key that is used to store a map of WMS urls for each river. */
- public static final String RIVER_WMS =
- "flys.floodmap.river.wms";
-
- /** The key that is used to store an instance of Scheduler in the context.*/
- public static final String SCHEDULER =
- "flys.wsplgen.scheduler";
-
- /** Key to store the configured modules in the context. */
- public static final String MODULES = "flys.modules";
-
-
- /**
- * The default constructor.
- */
- public FLYSContext() {
- super();
- }
-
-
- /**
- * A constructor with a config document.
- */
- public FLYSContext(Document config) {
- super(config);
- }
-
- /**
- * Returns the OutGenerator for a specified <i>type</i>.
- *
- * @param name The name of the output type.
- * @param type Defines the type of the desired OutGenerator.
- *
- * @return Instance of an OutGenerator for specified <i>type</i>.
- */
- public static OutGenerator getOutGenerator(
- CallContext context,
- String name,
- String type)
- {
-
- FLYSContext flysContext = context instanceof FLYSContext
- ? (FLYSContext) context
- : (FLYSContext) context.globalContext();
-
- Map<String, Class> generators = (Map<String, Class>)
- flysContext.get(FLYSContext.OUTGENERATORS_KEY);
-
- if (generators == null) {
- return null;
- }
-
- Class clazz = generators.get(name);
-
- try {
- return clazz != null ? (OutGenerator) clazz.newInstance() : null;
- }
- catch (InstantiationException ie) {
- logger.error(ie, ie);
- }
- catch (IllegalAccessException iae) {
- logger.error(iae, iae);
- }
-
- return null;
- }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/artifacts/context/FLYSContextFactory.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/context/FLYSContextFactory.java Sun Apr 28 15:09:31 2013 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,529 +0,0 @@
-/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
- * Software engineering by Intevation GmbH
- *
- * This file is Free Software under the GNU AGPL (>=v3)
- * and comes with ABSOLUTELY NO WARRANTY! Check out the
- * documentation coming with Dive4Elements River for details.
- */
-
-package org.dive4elements.river.artifacts.context;
-
-import org.dive4elements.artifactdatabase.state.State;
-import org.dive4elements.artifactdatabase.state.StateEngine;
-import org.dive4elements.artifactdatabase.transition.Transition;
-import org.dive4elements.artifactdatabase.transition.TransitionEngine;
-import org.dive4elements.artifacts.ArtifactContextFactory;
-import org.dive4elements.artifacts.GlobalContext;
-import org.dive4elements.artifacts.common.utils.Config;
-import org.dive4elements.artifacts.common.utils.XMLUtils;
-import org.dive4elements.river.artifacts.model.Module;
-import org.dive4elements.river.artifacts.model.ZoomScale;
-import org.dive4elements.river.artifacts.states.StateFactory;
-import org.dive4elements.river.artifacts.transitions.TransitionFactory;
-import org.dive4elements.river.themes.Theme;
-import org.dive4elements.river.themes.ThemeFactory;
-import org.dive4elements.river.themes.ThemeGroup;
-import org.dive4elements.river.themes.ThemeMapping;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.xpath.XPathConstants;
-
-import org.apache.log4j.Logger;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-
-/**
- * The ArtifactContextFactory is used to initialize basic components and put
- * them into the global context of the application.
- *
- * @author <a href="mailto:ingo.weinzierl at intevation.de">Ingo Weinzierl</a>
- */
-public class FLYSContextFactory implements ArtifactContextFactory {
-
- /** The logger that is used in this class. */
- private static Logger logger = Logger.getLogger(FLYSContextFactory.class);
-
- /** The XPath to the artifacts configured in the configuration. */
- public static final String XPATH_ARTIFACTS =
- "/artifact-database/artifacts/artifact";
-
- /** The XPath to the name of the artifact. */
- public static final String XPATH_ARTIFACT_NAME = "/artifact/@name";
-
- /** The XPath to the xlink ref in an artifact configuration. */
- public static final String XPATH_XLINK = "xlink:href";
-
- /** The XPath to the transitions configured in the artifact config. */
- public static final String XPATH_TRANSITIONS =
- "/artifact/states/transition";
-
- /** The XPath to the states configured in the artifact config. */
- public static final String XPATH_STATES =
- "/artifact/states/state";
-
- public static final String XPATH_OUTPUT_GENERATORS =
- "/artifact-database/output-generators/output-generator";
-
- public static final String XPATH_THEME_CONFIG =
- "/artifact-database/flys/themes/configuration/text()";
-
- public static final String XPATH_THEMES =
- "theme";
-
- public static final String XPATH_THEME_GROUPS =
- "/themes/themegroup";
-
- public static final String XPATH_THEME_MAPPINGS =
- "/themes/mappings/mapping";
-
- public static final String XPATH_RIVER_WMS =
- "/artifact-database/floodmap/river";
-
- public static final String XPATH_MODULES = "/artifact-database/modules/module";
-
- private static final String XPATH_ZOOM_SCALES = "/artifact-database/options/zoom-scales/zoom-scale";
-
- private static final String XPATH_DGM_PATH = "/artifact-database/options/dgm-path/text()";
-
-
- /**
- * Creates a new FLYSArtifactContext object and initialize all
- * components required by the application.
- *
- * @param config The artifact server configuration.
- * @return a FLYSArtifactContext.
- */
- @Override
- public GlobalContext createArtifactContext(Document config) {
- FLYSContext context = new FLYSContext(config);
-
- configureTransitions(config, context);
- configureStates(config, context);
- configureOutGenerators(config, context);
- configureThemes(config, context);
- configureThemesMappings(config, context);
- configureFloodmapWMS(config, context);
- configureModules(config, context);
- configureZoomScales(config, context);
- configureDGMPath(config, context);
-
- return context;
- }
-
-
- private void configureDGMPath(Document config, FLYSContext context) {
- String dgmPath = (String) XMLUtils.xpath(
- config,
- XPATH_DGM_PATH,
- XPathConstants.STRING);
-
- context.put("dgm-path", dgmPath);
- }
-
-
- protected void configureZoomScales(Document config, FLYSContext context) {
- NodeList list = (NodeList)XMLUtils.xpath(
- config,
- XPATH_ZOOM_SCALES,
- XPathConstants.NODESET);
- ZoomScale scale = new ZoomScale();
- for (int i = 0; i < list.getLength(); i++) {
- Element element = (Element)list.item(i);
- String river = "default";
- double range = 0d;
- double radius = 10d;
- if (element.hasAttribute("river")) {
- river = element.getAttribute("river");
- }
- if (!element.hasAttribute("range")) {
- continue;
- }
- else {
- String r = element.getAttribute("range");
- try {
- range = Double.parseDouble(r);
- }
- catch (NumberFormatException nfe) {
- continue;
- }
- }
- if (!element.hasAttribute("radius")) {
- continue;
- }
- else {
- String r = element.getAttribute("radius");
- try {
- radius = Double.parseDouble(r);
- }
- catch (NumberFormatException nfe) {
- continue;
- }
- }
- scale.addRange(river, range, radius);
- }
- context.put("zoomscale", scale);
- }
-
-
- /**
- * This method initializes the transition configuration.
- *
- * @param config the config document.
- * @param context the FLYSContext.
- */
- protected void configureTransitions(Document config, FLYSContext context) {
- TransitionEngine engine = new TransitionEngine();
-
- Document[] artifacts = getArtifactConfigurations(config);
- logger.info("Found " + artifacts.length + " artifacts in the config.");
-
- for (Document doc: artifacts) {
-
- String artName = (String) XMLUtils.xpath(
- doc, XPATH_ARTIFACT_NAME, XPathConstants.STRING);
-
- NodeList list = (NodeList) XMLUtils.xpath(
- doc, XPATH_TRANSITIONS, XPathConstants.NODESET);
-
- if (list == null) {
- logger.warn("The artifact " + artName +
- " has no transitions configured.");
- continue;
- }
-
- int trans = list.getLength();
-
- logger.info(
- "Artifact '" + artName + "' has " + trans + " transitions.");
-
- for (int i = 0; i < trans; i++) {
- Transition t = TransitionFactory.createTransition(list.item(i));
- String s = t.getFrom();
- engine.addTransition(s, t);
- }
- }
-
- context.put(FLYSContext.TRANSITION_ENGINE_KEY, engine);
- }
-
-
- /**
- * This method returns all artifact documents defined in
- * <code>config</code>. <br>NOTE: The artifact configurations need to be
- * stored in own files referenced by an xlink.
- *
- * @param config The global configuration.
- *
- * @return an array of Artifact configurations.
- */
- protected Document[] getArtifactConfigurations(Document config) {
- NodeList artifacts = (NodeList) XMLUtils.xpath(
- config, XPATH_ARTIFACTS, XPathConstants.NODESET);
-
- int count = artifacts.getLength();
-
- Document[] artifactDocs = new Document[count];
-
- for (int i = 0; i < count; i++) {
- Element tmp = (Element) artifacts.item(i);
-
- String xlink = tmp.getAttribute(XPATH_XLINK);
- xlink = Config.replaceConfigDir(xlink);
-
- File artifactFile = new File(xlink);
- artifactDocs[i] = XMLUtils.parseDocument(artifactFile);
- }
-
- return artifactDocs;
- }
-
-
- /**
- * This method initializes the transition configuration.
- *
- * @param config the config document.
- * @param context the FLYSContext.
- */
- protected void configureStates(Document config, FLYSContext context) {
- StateEngine engine = new StateEngine();
-
- Document[] artifacts = getArtifactConfigurations(config);
- logger.info("Found " + artifacts.length + " artifacts in the config.");
-
- for (Document doc: artifacts) {
- List<State> states = new ArrayList<State>();
-
- String artName = (String) XMLUtils.xpath(
- doc, XPATH_ARTIFACT_NAME, XPathConstants.STRING);
-
- NodeList stateList = (NodeList) XMLUtils.xpath(
- doc, XPATH_STATES, XPathConstants.NODESET);
-
- if (stateList == null) {
- logger.warn("The artifact " + artName +
- " has no states configured.");
- continue;
- }
-
- int count = stateList.getLength();
-
- logger.info(
- "Artifact '" + artName + "' has " + count + " states.");
-
- for (int i = 0; i < count; i++) {
- states.add(StateFactory.createState(
- stateList.item(i)));
- }
-
- engine.addStates(artName, states);
- }
-
- context.put(FLYSContext.STATE_ENGINE_KEY, engine);
- }
-
-
- /**
- * This method intializes the provided output generators.
- *
- * @param config the config document.
- * @param context the FLYSContext.
- */
- protected void configureOutGenerators(Document config, FLYSContext context){
- Map<String, Class<?>> generators = new HashMap<String, Class<?>>();
-
- NodeList outGenerators = (NodeList) XMLUtils.xpath(
- config,
- XPATH_OUTPUT_GENERATORS,
- XPathConstants.NODESET);
-
- int num = outGenerators == null ? 0 : outGenerators.getLength();
-
- if (num == 0) {
- logger.warn("No output generators configured in this application.");
- return;
- }
-
- logger.info("Found " + num + " configured output generators.");
-
- int idx = 0;
-
- for (int i = 0; i < num; i++) {
- Node item = outGenerators.item(i);
-
- String name = (String) XMLUtils.xpath(
- item, "@name", XPathConstants.STRING);
-
- String clazz = (String) XMLUtils.xpath(
- item, "text()", XPathConstants.STRING);
-
- if (name == null || clazz == null) {
- continue;
- }
-
- try {
- generators.put(name, Class.forName(clazz));
-
- idx++;
- }
- catch (ClassNotFoundException cnfe) {
- logger.warn(cnfe, cnfe);
- }
- }
-
- logger.info("Successfully loaded " + idx + " output generators.");
- context.put(FLYSContext.OUTGENERATORS_KEY, generators);
- }
-
-
- /**
- * This methods reads the configured themes and puts them into the
- * FLYSContext.
- *
- * @param config The global configuration.
- * @param context The FLYSContext.
- */
- protected void configureThemes(Document config, FLYSContext context) {
- logger.debug("FLYSContextFactory.configureThemes");
-
- Document cfg = getThemeConfig(config);
-
- NodeList themeGroups = (NodeList) XMLUtils.xpath(
- cfg, XPATH_THEME_GROUPS, XPathConstants.NODESET);
-
- int groupNum = themeGroups != null ? themeGroups.getLength() : 0;
-
- if (groupNum == 0) {
- logger.warn("There are no theme groups configured!");
- }
-
- logger.info("Found " + groupNum + " theme groups in configuration");
-
- List<ThemeGroup> groups = new ArrayList<ThemeGroup>();
-
- for (int g = 0; g < groupNum; g++) {
- Element themeGroup = (Element) themeGroups.item(g);
- NodeList themes = (NodeList) XMLUtils.xpath(
- themeGroup, XPATH_THEMES, XPathConstants.NODESET);
-
- int num = themes != null ? themes.getLength() : 0;
-
- if (num == 0) {
- logger.warn("There are no themes configured!");
- return;
- }
-
- logger.info("Theme group has " + num + " themes.");
-
- Map<String, Theme> theThemes = new HashMap<String, Theme>();
-
- for (int i = 0; i < num; i++) {
- Node theme = themes.item(i);
-
- Theme theTheme = ThemeFactory.createTheme(cfg, theme);
-
- if (theme != null) {
- theThemes.put(theTheme.getName(), theTheme);
- }
- }
- String gName = themeGroup.getAttribute("name");
- groups.add(new ThemeGroup(gName, theThemes));
-
- logger.info(
- "Initialized " + theThemes.size() + "/" + num + " themes " +
- "of theme-group '" + gName + "'");
- }
- context.put(FLYSContext.THEMES, groups);
- }
-
- /**
- * This method is used to retrieve the theme configuration document.
- *
- * @param config The global configuration.
- *
- * @return the theme configuration.
- */
- protected Document getThemeConfig(Document config) {
- String themeConfig = (String) XMLUtils.xpath(
- config,
- XPATH_THEME_CONFIG,
- XPathConstants.STRING);
-
- themeConfig = Config.replaceConfigDir(themeConfig);
-
- logger.debug("Parse theme cfg: " + themeConfig);
-
- return XMLUtils.parseDocument(new File(themeConfig));
- }
-
-
- protected void configureThemesMappings(Document cfg, FLYSContext context) {
- logger.debug("FLYSContextFactory.configureThemesMappings");
-
- Document config = getThemeConfig(cfg);
-
- NodeList mappings = (NodeList) XMLUtils.xpath(
- config, XPATH_THEME_MAPPINGS, XPathConstants.NODESET);
-
- int num = mappings != null ? mappings.getLength() : 0;
-
- if (num == 0) {
- logger.warn("No theme <--> facet mappins found!");
- return;
- }
-
- Map<String, List<ThemeMapping>> mapping =
- new HashMap<String, List<ThemeMapping>>();
-
- for (int i = 0; i < num; i++) {
- Element node = (Element)mappings.item(i);
-
- String from = node.getAttribute("from");
- String to = node.getAttribute("to");
- String pattern = node.getAttribute("pattern");
- String masterAttrPattern = node.getAttribute("masterAttr");
- String outputPattern = node.getAttribute("output");
-
- if (from.length() > 0 && to.length() > 0) {
- List<ThemeMapping> tm = mapping.get(from);
-
- if (tm == null) {
- tm = new ArrayList<ThemeMapping>();
- mapping.put(from, tm);
- }
-
- tm.add(new ThemeMapping(
- from, to, pattern, masterAttrPattern, outputPattern));
- }
- }
-
- logger.debug("Found " + mapping.size() + " theme mappings.");
-
- context.put(FLYSContext.THEME_MAPPING, mapping);
- }
-
-
- /**
- * Reads configured floodmap river WMSs from floodmap.xml and
- * loads them into the given FLYSContext.
- * @param cfg
- * @param context
- */
- protected void configureFloodmapWMS(Document cfg, FLYSContext context) {
- Map<String, String> riverWMS = new HashMap<String, String>();
-
- NodeList rivers = (NodeList) XMLUtils.xpath(
- cfg, XPATH_RIVER_WMS, XPathConstants.NODESET);
-
- int num = rivers != null ? rivers.getLength() : 0;
-
- for (int i = 0; i < num; i++) {
- Element e = (Element) rivers.item(i);
-
- String river = e.getAttribute("name");
- String url = XMLUtils.xpathString(e, "river-wms/@url", null);
-
- if (river != null && url != null) {
- riverWMS.put(river, url);
- }
- }
-
- logger.debug("Found " + riverWMS.size() + " river WMS.");
-
- context.put(FLYSContext.RIVER_WMS, riverWMS);
- }
-
-
- /**
- * This method initializes the modules configuration.
- *
- * @param config the config document.
- * @param context the FLYSContext.
- */
- protected void configureModules(Document cfg, FLYSContext context) {
- NodeList modulenodes = (NodeList) XMLUtils.xpath(
- cfg, XPATH_MODULES, XPathConstants.NODESET);
-
- int num = modulenodes != null ? modulenodes.getLength() : 0;
- ArrayList<Module> modules = new ArrayList<Module>(num);
-
- for (int i = 0; i < num; i++) {
- Element e = (Element) modulenodes.item(i);
- String modulename = e.getAttribute("name");
- String attrselected = e.getAttribute("selected");
- boolean selected = attrselected == null ? false :
- attrselected.equalsIgnoreCase("true");
- logger.debug("Loaded module " + modulename);
- modules.add(new Module(modulename, selected));
- }
- context.put(FLYSContext.MODULES, modules);
- }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContext.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContext.java Sun Apr 28 15:14:30 2013 +0200
@@ -0,0 +1,124 @@
+/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.artifacts.context;
+
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Document;
+
+import org.dive4elements.artifactdatabase.DefaultArtifactContext;
+import org.dive4elements.artifacts.CallContext;
+import org.dive4elements.river.exports.OutGenerator;
+
+
+/**
+ * This class is used to store application wide information in a global context.
+ *
+ * @author <a href="mailto:ingo.weinzierl at intevation.de">Ingo Weinzierl</a>
+ */
+public class RiverContext extends DefaultArtifactContext {
+
+ /** The logger used in this class. */
+ private static Logger logger = Logger.getLogger(RiverContext.class);
+
+ /** The key that is used to store the StateEngine in the context. */
+ public static final String ARTIFACT_KEY =
+ "artifact";
+
+ /** The key that is used to store the TransitionEngine in the context. */
+ public static final String TRANSITION_ENGINE_KEY =
+ "artifact.transition.engine";
+
+ /** The key that is used to store the StateEngine in the context. */
+ public static final String STATE_ENGINE_KEY =
+ "artifact.state.engine";
+
+ /** The key that is used to store the Map of OutGenerator classes in the
+ * context. */
+ public static final String OUTGENERATORS_KEY =
+ "flys.export.outgenerators";
+
+ /** The key that is used to store the map of themes in the context. */
+ public static final String THEMES =
+ "flys.themes.map";
+
+ /** The key that is used to store a map of theme mappings in the context. */
+ public static final String THEME_MAPPING =
+ "flys.themes.mapping.map";
+
+ /** The key that is used to store a map of WMS urls for each river. */
+ public static final String RIVER_WMS =
+ "flys.floodmap.river.wms";
+
+ /** The key that is used to store an instance of Scheduler in the context.*/
+ public static final String SCHEDULER =
+ "flys.wsplgen.scheduler";
+
+ /** Key to store the configured modules in the context. */
+ public static final String MODULES = "flys.modules";
+
+
+ /**
+ * The default constructor.
+ */
+ public RiverContext() {
+ super();
+ }
+
+
+ /**
+ * A constructor with a config document.
+ */
+ public RiverContext(Document config) {
+ super(config);
+ }
+
+ /**
+ * Returns the OutGenerator for a specified <i>type</i>.
+ *
+ * @param name The name of the output type.
+ * @param type Defines the type of the desired OutGenerator.
+ *
+ * @return Instance of an OutGenerator for specified <i>type</i>.
+ */
+ public static OutGenerator getOutGenerator(
+ CallContext context,
+ String name,
+ String type)
+ {
+
+ RiverContext flysContext = context instanceof RiverContext
+ ? (RiverContext) context
+ : (RiverContext) context.globalContext();
+
+ Map<String, Class> generators = (Map<String, Class>)
+ flysContext.get(RiverContext.OUTGENERATORS_KEY);
+
+ if (generators == null) {
+ return null;
+ }
+
+ Class clazz = generators.get(name);
+
+ try {
+ return clazz != null ? (OutGenerator) clazz.newInstance() : null;
+ }
+ catch (InstantiationException ie) {
+ logger.error(ie, ie);
+ }
+ catch (IllegalAccessException iae) {
+ logger.error(iae, iae);
+ }
+
+ return null;
+ }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/context/RiverContextFactory.java Sun Apr 28 15:14:30 2013 +0200
@@ -0,0 +1,529 @@
+/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.artifacts.context;
+
+import org.dive4elements.artifactdatabase.state.State;
+import org.dive4elements.artifactdatabase.state.StateEngine;
+import org.dive4elements.artifactdatabase.transition.Transition;
+import org.dive4elements.artifactdatabase.transition.TransitionEngine;
+import org.dive4elements.artifacts.ArtifactContextFactory;
+import org.dive4elements.artifacts.GlobalContext;
+import org.dive4elements.artifacts.common.utils.Config;
+import org.dive4elements.artifacts.common.utils.XMLUtils;
+import org.dive4elements.river.artifacts.model.Module;
+import org.dive4elements.river.artifacts.model.ZoomScale;
+import org.dive4elements.river.artifacts.states.StateFactory;
+import org.dive4elements.river.artifacts.transitions.TransitionFactory;
+import org.dive4elements.river.themes.Theme;
+import org.dive4elements.river.themes.ThemeFactory;
+import org.dive4elements.river.themes.ThemeGroup;
+import org.dive4elements.river.themes.ThemeMapping;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.xpath.XPathConstants;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+
+/**
+ * The ArtifactContextFactory is used to initialize basic components and put
+ * them into the global context of the application.
+ *
+ * @author <a href="mailto:ingo.weinzierl at intevation.de">Ingo Weinzierl</a>
+ */
+public class RiverContextFactory implements ArtifactContextFactory {
+
+ /** The logger that is used in this class. */
+ private static Logger logger = Logger.getLogger(RiverContextFactory.class);
+
+ /** The XPath to the artifacts configured in the configuration. */
+ public static final String XPATH_ARTIFACTS =
+ "/artifact-database/artifacts/artifact";
+
+ /** The XPath to the name of the artifact. */
+ public static final String XPATH_ARTIFACT_NAME = "/artifact/@name";
+
+ /** The XPath to the xlink ref in an artifact configuration. */
+ public static final String XPATH_XLINK = "xlink:href";
+
+ /** The XPath to the transitions configured in the artifact config. */
+ public static final String XPATH_TRANSITIONS =
+ "/artifact/states/transition";
+
+ /** The XPath to the states configured in the artifact config. */
+ public static final String XPATH_STATES =
+ "/artifact/states/state";
+
+ public static final String XPATH_OUTPUT_GENERATORS =
+ "/artifact-database/output-generators/output-generator";
+
+ public static final String XPATH_THEME_CONFIG =
+ "/artifact-database/flys/themes/configuration/text()";
+
+ public static final String XPATH_THEMES =
+ "theme";
+
+ public static final String XPATH_THEME_GROUPS =
+ "/themes/themegroup";
+
+ public static final String XPATH_THEME_MAPPINGS =
+ "/themes/mappings/mapping";
+
+ public static final String XPATH_RIVER_WMS =
+ "/artifact-database/floodmap/river";
+
+ public static final String XPATH_MODULES = "/artifact-database/modules/module";
+
+ private static final String XPATH_ZOOM_SCALES = "/artifact-database/options/zoom-scales/zoom-scale";
+
+ private static final String XPATH_DGM_PATH = "/artifact-database/options/dgm-path/text()";
+
+
+ /**
+ * Creates a new FLYSArtifactContext object and initialize all
+ * components required by the application.
+ *
+ * @param config The artifact server configuration.
+ * @return a FLYSArtifactContext.
+ */
+ @Override
+ public GlobalContext createArtifactContext(Document config) {
+ RiverContext context = new RiverContext(config);
+
+ configureTransitions(config, context);
+ configureStates(config, context);
+ configureOutGenerators(config, context);
+ configureThemes(config, context);
+ configureThemesMappings(config, context);
+ configureFloodmapWMS(config, context);
+ configureModules(config, context);
+ configureZoomScales(config, context);
+ configureDGMPath(config, context);
+
+ return context;
+ }
+
+
+ private void configureDGMPath(Document config, RiverContext context) {
+ String dgmPath = (String) XMLUtils.xpath(
+ config,
+ XPATH_DGM_PATH,
+ XPathConstants.STRING);
+
+ context.put("dgm-path", dgmPath);
+ }
+
+
+ protected void configureZoomScales(Document config, RiverContext context) {
+ NodeList list = (NodeList)XMLUtils.xpath(
+ config,
+ XPATH_ZOOM_SCALES,
+ XPathConstants.NODESET);
+ ZoomScale scale = new ZoomScale();
+ for (int i = 0; i < list.getLength(); i++) {
+ Element element = (Element)list.item(i);
+ String river = "default";
+ double range = 0d;
+ double radius = 10d;
+ if (element.hasAttribute("river")) {
+ river = element.getAttribute("river");
+ }
+ if (!element.hasAttribute("range")) {
+ continue;
+ }
+ else {
+ String r = element.getAttribute("range");
+ try {
+ range = Double.parseDouble(r);
+ }
+ catch (NumberFormatException nfe) {
+ continue;
+ }
+ }
+ if (!element.hasAttribute("radius")) {
+ continue;
+ }
+ else {
+ String r = element.getAttribute("radius");
+ try {
+ radius = Double.parseDouble(r);
+ }
+ catch (NumberFormatException nfe) {
+ continue;
+ }
+ }
+ scale.addRange(river, range, radius);
+ }
+ context.put("zoomscale", scale);
+ }
+
+
+ /**
+ * This method initializes the transition configuration.
+ *
+ * @param config the config document.
+ * @param context the RiverContext.
+ */
+ protected void configureTransitions(Document config, RiverContext context) {
+ TransitionEngine engine = new TransitionEngine();
+
+ Document[] artifacts = getArtifactConfigurations(config);
+ logger.info("Found " + artifacts.length + " artifacts in the config.");
+
+ for (Document doc: artifacts) {
+
+ String artName = (String) XMLUtils.xpath(
+ doc, XPATH_ARTIFACT_NAME, XPathConstants.STRING);
+
+ NodeList list = (NodeList) XMLUtils.xpath(
+ doc, XPATH_TRANSITIONS, XPathConstants.NODESET);
+
+ if (list == null) {
+ logger.warn("The artifact " + artName +
+ " has no transitions configured.");
+ continue;
+ }
+
+ int trans = list.getLength();
+
+ logger.info(
+ "Artifact '" + artName + "' has " + trans + " transitions.");
+
+ for (int i = 0; i < trans; i++) {
+ Transition t = TransitionFactory.createTransition(list.item(i));
+ String s = t.getFrom();
+ engine.addTransition(s, t);
+ }
+ }
+
+ context.put(RiverContext.TRANSITION_ENGINE_KEY, engine);
+ }
+
+
+ /**
+ * This method returns all artifact documents defined in
+ * <code>config</code>. <br>NOTE: The artifact configurations need to be
+ * stored in own files referenced by an xlink.
+ *
+ * @param config The global configuration.
+ *
+ * @return an array of Artifact configurations.
+ */
+ protected Document[] getArtifactConfigurations(Document config) {
+ NodeList artifacts = (NodeList) XMLUtils.xpath(
+ config, XPATH_ARTIFACTS, XPathConstants.NODESET);
+
+ int count = artifacts.getLength();
+
+ Document[] artifactDocs = new Document[count];
+
+ for (int i = 0; i < count; i++) {
+ Element tmp = (Element) artifacts.item(i);
+
+ String xlink = tmp.getAttribute(XPATH_XLINK);
+ xlink = Config.replaceConfigDir(xlink);
+
+ File artifactFile = new File(xlink);
+ artifactDocs[i] = XMLUtils.parseDocument(artifactFile);
+ }
+
+ return artifactDocs;
+ }
+
+
+ /**
+ * This method initializes the transition configuration.
+ *
+ * @param config the config document.
+ * @param context the RiverContext.
+ */
+ protected void configureStates(Document config, RiverContext context) {
+ StateEngine engine = new StateEngine();
+
+ Document[] artifacts = getArtifactConfigurations(config);
+ logger.info("Found " + artifacts.length + " artifacts in the config.");
+
+ for (Document doc: artifacts) {
+ List<State> states = new ArrayList<State>();
+
+ String artName = (String) XMLUtils.xpath(
+ doc, XPATH_ARTIFACT_NAME, XPathConstants.STRING);
+
+ NodeList stateList = (NodeList) XMLUtils.xpath(
+ doc, XPATH_STATES, XPathConstants.NODESET);
+
+ if (stateList == null) {
+ logger.warn("The artifact " + artName +
+ " has no states configured.");
+ continue;
+ }
+
+ int count = stateList.getLength();
+
+ logger.info(
+ "Artifact '" + artName + "' has " + count + " states.");
+
+ for (int i = 0; i < count; i++) {
+ states.add(StateFactory.createState(
+ stateList.item(i)));
+ }
+
+ engine.addStates(artName, states);
+ }
+
+ context.put(RiverContext.STATE_ENGINE_KEY, engine);
+ }
+
+
+ /**
+ * This method intializes the provided output generators.
+ *
+ * @param config the config document.
+ * @param context the RiverContext.
+ */
+ protected void configureOutGenerators(Document config, RiverContext context){
+ Map<String, Class<?>> generators = new HashMap<String, Class<?>>();
+
+ NodeList outGenerators = (NodeList) XMLUtils.xpath(
+ config,
+ XPATH_OUTPUT_GENERATORS,
+ XPathConstants.NODESET);
+
+ int num = outGenerators == null ? 0 : outGenerators.getLength();
+
+ if (num == 0) {
+ logger.warn("No output generators configured in this application.");
+ return;
+ }
+
+ logger.info("Found " + num + " configured output generators.");
+
+ int idx = 0;
+
+ for (int i = 0; i < num; i++) {
+ Node item = outGenerators.item(i);
+
+ String name = (String) XMLUtils.xpath(
+ item, "@name", XPathConstants.STRING);
+
+ String clazz = (String) XMLUtils.xpath(
+ item, "text()", XPathConstants.STRING);
+
+ if (name == null || clazz == null) {
+ continue;
+ }
+
+ try {
+ generators.put(name, Class.forName(clazz));
+
+ idx++;
+ }
+ catch (ClassNotFoundException cnfe) {
+ logger.warn(cnfe, cnfe);
+ }
+ }
+
+ logger.info("Successfully loaded " + idx + " output generators.");
+ context.put(RiverContext.OUTGENERATORS_KEY, generators);
+ }
+
+
+ /**
+ * This methods reads the configured themes and puts them into the
+ * RiverContext.
+ *
+ * @param config The global configuration.
+ * @param context The RiverContext.
+ */
+ protected void configureThemes(Document config, RiverContext context) {
+ logger.debug("RiverContextFactory.configureThemes");
+
+ Document cfg = getThemeConfig(config);
+
+ NodeList themeGroups = (NodeList) XMLUtils.xpath(
+ cfg, XPATH_THEME_GROUPS, XPathConstants.NODESET);
+
+ int groupNum = themeGroups != null ? themeGroups.getLength() : 0;
+
+ if (groupNum == 0) {
+ logger.warn("There are no theme groups configured!");
+ }
+
+ logger.info("Found " + groupNum + " theme groups in configuration");
+
+ List<ThemeGroup> groups = new ArrayList<ThemeGroup>();
+
+ for (int g = 0; g < groupNum; g++) {
+ Element themeGroup = (Element) themeGroups.item(g);
+ NodeList themes = (NodeList) XMLUtils.xpath(
+ themeGroup, XPATH_THEMES, XPathConstants.NODESET);
+
+ int num = themes != null ? themes.getLength() : 0;
+
+ if (num == 0) {
+ logger.warn("There are no themes configured!");
+ return;
+ }
+
+ logger.info("Theme group has " + num + " themes.");
+
+ Map<String, Theme> theThemes = new HashMap<String, Theme>();
+
+ for (int i = 0; i < num; i++) {
+ Node theme = themes.item(i);
+
+ Theme theTheme = ThemeFactory.createTheme(cfg, theme);
+
+ if (theme != null) {
+ theThemes.put(theTheme.getName(), theTheme);
+ }
+ }
+ String gName = themeGroup.getAttribute("name");
+ groups.add(new ThemeGroup(gName, theThemes));
+
+ logger.info(
+ "Initialized " + theThemes.size() + "/" + num + " themes " +
+ "of theme-group '" + gName + "'");
+ }
+ context.put(RiverContext.THEMES, groups);
+ }
+
+ /**
+ * This method is used to retrieve the theme configuration document.
+ *
+ * @param config The global configuration.
+ *
+ * @return the theme configuration.
+ */
+ protected Document getThemeConfig(Document config) {
+ String themeConfig = (String) XMLUtils.xpath(
+ config,
+ XPATH_THEME_CONFIG,
+ XPathConstants.STRING);
+
+ themeConfig = Config.replaceConfigDir(themeConfig);
+
+ logger.debug("Parse theme cfg: " + themeConfig);
+
+ return XMLUtils.parseDocument(new File(themeConfig));
+ }
+
+
+ protected void configureThemesMappings(Document cfg, RiverContext context) {
+ logger.debug("RiverContextFactory.configureThemesMappings");
+
+ Document config = getThemeConfig(cfg);
+
+ NodeList mappings = (NodeList) XMLUtils.xpath(
+ config, XPATH_THEME_MAPPINGS, XPathConstants.NODESET);
+
+ int num = mappings != null ? mappings.getLength() : 0;
+
+ if (num == 0) {
+ logger.warn("No theme <--> facet mappins found!");
+ return;
+ }
+
+ Map<String, List<ThemeMapping>> mapping =
+ new HashMap<String, List<ThemeMapping>>();
+
+ for (int i = 0; i < num; i++) {
+ Element node = (Element)mappings.item(i);
+
+ String from = node.getAttribute("from");
+ String to = node.getAttribute("to");
+ String pattern = node.getAttribute("pattern");
+ String masterAttrPattern = node.getAttribute("masterAttr");
+ String outputPattern = node.getAttribute("output");
+
+ if (from.length() > 0 && to.length() > 0) {
+ List<ThemeMapping> tm = mapping.get(from);
+
+ if (tm == null) {
+ tm = new ArrayList<ThemeMapping>();
+ mapping.put(from, tm);
+ }
+
+ tm.add(new ThemeMapping(
+ from, to, pattern, masterAttrPattern, outputPattern));
+ }
+ }
+
+ logger.debug("Found " + mapping.size() + " theme mappings.");
+
+ context.put(RiverContext.THEME_MAPPING, mapping);
+ }
+
+
+ /**
+ * Reads configured floodmap river WMSs from floodmap.xml and
+ * loads them into the given RiverContext.
+ * @param cfg
+ * @param context
+ */
+ protected void configureFloodmapWMS(Document cfg, RiverContext context) {
+ Map<String, String> riverWMS = new HashMap<String, String>();
+
+ NodeList rivers = (NodeList) XMLUtils.xpath(
+ cfg, XPATH_RIVER_WMS, XPathConstants.NODESET);
+
+ int num = rivers != null ? rivers.getLength() : 0;
+
+ for (int i = 0; i < num; i++) {
+ Element e = (Element) rivers.item(i);
+
+ String river = e.getAttribute("name");
+ String url = XMLUtils.xpathString(e, "river-wms/@url", null);
+
+ if (river != null && url != null) {
+ riverWMS.put(river, url);
+ }
+ }
+
+ logger.debug("Found " + riverWMS.size() + " river WMS.");
+
+ context.put(RiverContext.RIVER_WMS, riverWMS);
+ }
+
+
+ /**
+ * This method initializes the modules configuration.
+ *
+ * @param config the config document.
+ * @param context the RiverContext.
+ */
+ protected void configureModules(Document cfg, RiverContext context) {
+ NodeList modulenodes = (NodeList) XMLUtils.xpath(
+ cfg, XPATH_MODULES, XPathConstants.NODESET);
+
+ int num = modulenodes != null ? modulenodes.getLength() : 0;
+ ArrayList<Module> modules = new ArrayList<Module>(num);
+
+ for (int i = 0; i < num; i++) {
+ Element e = (Element) modulenodes.item(i);
+ String modulename = e.getAttribute("name");
+ String attrselected = e.getAttribute("selected");
+ boolean selected = attrselected == null ? false :
+ attrselected.equalsIgnoreCase("true");
+ logger.debug("Loaded module " + modulename);
+ modules.add(new Module(modulename, selected));
+ }
+ context.put(RiverContext.MODULES, modules);
+ }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/artifacts/model/FlowVelocityFilterFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/FlowVelocityFilterFacet.java Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/FlowVelocityFilterFacet.java Sun Apr 28 15:14:30 2013 +0200
@@ -16,7 +16,7 @@
import org.dive4elements.river.artifacts.FLYSArtifact;
import org.dive4elements.river.artifacts.access.RiverAccess;
-import org.dive4elements.river.artifacts.context.FLYSContext;
+import org.dive4elements.river.artifacts.context.RiverContext;
import org.dive4elements.river.artifacts.math.MovingAverage;
import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
@@ -59,7 +59,7 @@
FlowVelocityData[] data = (FlowVelocityData[]) res.getData();
if(start != null && end != null) {
- FLYSContext fc = (FLYSContext)context.globalContext();
+ RiverContext fc = (RiverContext)context.globalContext();
ZoomScale scales = (ZoomScale)fc.get("zoomscale");
RiverAccess access = new RiverAccess((FLYSArtifact)artifact);
String river = access.getRiver();
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffEpochFilterFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffEpochFilterFacet.java Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffEpochFilterFacet.java Sun Apr 28 15:14:30 2013 +0200
@@ -15,7 +15,7 @@
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.FLYSArtifact;
import org.dive4elements.river.artifacts.access.RiverAccess;
-import org.dive4elements.river.artifacts.context.FLYSContext;
+import org.dive4elements.river.artifacts.context.RiverContext;
import org.dive4elements.river.artifacts.model.CalculationResult;
import org.dive4elements.river.artifacts.model.DataFacet;
import org.dive4elements.river.artifacts.math.MovingAverage;
@@ -50,7 +50,7 @@
Double end = (Double)context.getContextValue("endkm");
if(start != null && end != null) {
- FLYSContext fc = (FLYSContext)context.globalContext();
+ RiverContext fc = (RiverContext)context.globalContext();
ZoomScale scales = (ZoomScale)fc.get("zoomscale");
RiverAccess access = new RiverAccess((FLYSArtifact)artifact);
String river = access.getRiver();
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffYearFilterFacet.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffYearFilterFacet.java Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/BedDiffYearFilterFacet.java Sun Apr 28 15:14:30 2013 +0200
@@ -15,7 +15,7 @@
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.river.artifacts.FLYSArtifact;
import org.dive4elements.river.artifacts.access.RiverAccess;
-import org.dive4elements.river.artifacts.context.FLYSContext;
+import org.dive4elements.river.artifacts.context.RiverContext;
import org.dive4elements.river.artifacts.model.CalculationResult;
import org.dive4elements.river.artifacts.model.DataFacet;
import org.dive4elements.river.artifacts.math.MovingAverage;
@@ -49,7 +49,7 @@
Double start = (Double)context.getContextValue("startkm");
Double end = (Double)context.getContextValue("endkm");
if(start != null && end != null) {
- FLYSContext fc = (FLYSContext)context.globalContext();
+ RiverContext fc = (RiverContext)context.globalContext();
ZoomScale scales = (ZoomScale)fc.get("zoomscale");
RiverAccess access = new RiverAccess((FLYSArtifact)artifact);
String river = access.getRiver();
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/artifacts/services/ModuleService.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/ModuleService.java Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/ModuleService.java Sun Apr 28 15:14:30 2013 +0200
@@ -21,7 +21,7 @@
import org.dive4elements.artifacts.GlobalContext;
import org.dive4elements.artifacts.ArtifactNamespaceContext;
import org.dive4elements.river.artifacts.model.Module;
-import org.dive4elements.river.artifacts.context.FLYSContext;
+import org.dive4elements.river.artifacts.context.RiverContext;
import org.dive4elements.river.artifacts.resources.Resources;
public class ModuleService extends FLYSService {
@@ -45,7 +45,7 @@
ArtifactNamespaceContext.NAMESPACE_PREFIX);
Element em = ec.create("modules");
- List<Module> modules = (List<Module>)globalContext.get(FLYSContext.MODULES);
+ List<Module> modules = (List<Module>)globalContext.get(RiverContext.MODULES);
for (Module module : modules) {
Element m = ec.create("module");
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/artifacts/services/ThemeListingService.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/ThemeListingService.java Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/ThemeListingService.java Sun Apr 28 15:14:30 2013 +0200
@@ -25,7 +25,7 @@
import org.dive4elements.river.themes.ThemeGroup;
import org.dive4elements.river.themes.ThemeFactory;
-import org.dive4elements.river.artifacts.context.FLYSContext;
+import org.dive4elements.river.artifacts.context.RiverContext;
/**
* This service provides a list of themes filtered by the theme name.
@@ -58,7 +58,7 @@
null);
List<ThemeGroup> tgs =
- ThemeFactory.getThemeGroups((FLYSContext) context);
+ ThemeFactory.getThemeGroups((RiverContext) context);
Element te = ec.create("themes");
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/FloodMapState.java Sun Apr 28 15:14:30 2013 +0200
@@ -49,7 +49,7 @@
import org.dive4elements.river.artifacts.access.RangeAccess;
-import org.dive4elements.river.artifacts.context.FLYSContext;
+import org.dive4elements.river.artifacts.context.RiverContext;
import org.dive4elements.river.artifacts.model.CalculationMessage;
import org.dive4elements.river.artifacts.model.CalculationResult;
@@ -259,7 +259,7 @@
));
GlobalContext gc = (GlobalContext) context.globalContext();
- Scheduler scheduler = (Scheduler) gc.get(FLYSContext.SCHEDULER);
+ Scheduler scheduler = (Scheduler) gc.get(RiverContext.SCHEDULER);
scheduler.addJob(job);
return null;
@@ -879,7 +879,7 @@
job.setDgm(dgm.getPath());
}
else {
- FLYSContext fc = (FLYSContext)context.globalContext();
+ RiverContext fc = (RiverContext)context.globalContext();
String prefix = (String) fc.get("dgm-path");
job.setDgm(prefix.trim() + dgm.getPath().trim());
}
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/collections/FLYSArtifactCollection.java
--- a/artifacts/src/main/java/org/dive4elements/river/collections/FLYSArtifactCollection.java Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/collections/FLYSArtifactCollection.java Sun Apr 28 15:14:30 2013 +0200
@@ -38,7 +38,7 @@
import org.dive4elements.artifacts.CallMeta;
import org.dive4elements.artifacts.common.utils.XMLUtils;
import org.dive4elements.river.artifacts.FLYSArtifact;
-import org.dive4elements.river.artifacts.context.FLYSContext;
+import org.dive4elements.river.artifacts.context.RiverContext;
import org.dive4elements.river.exports.OutGenerator;
import org.dive4elements.river.exports.OutputHelper;
import org.dive4elements.river.utils.RiverUtils;
@@ -306,7 +306,7 @@
CollectionAttribute attr,
String out
) {
- OutGenerator outGen = FLYSContext.getOutGenerator(cc, out, null);
+ OutGenerator outGen = RiverContext.getOutGenerator(cc, out, null);
if (outGen == null) {
return null;
@@ -367,10 +367,10 @@
&& type.length() > 0
&& type.indexOf("chartinfo") > 0)
{
- generator = FLYSContext.getOutGenerator(context, type, subtype);
+ generator = RiverContext.getOutGenerator(context, type, subtype);
}
else {
- generator = FLYSContext.getOutGenerator(context, name, subtype);
+ generator = RiverContext.getOutGenerator(context, name, subtype);
}
if (generator == null) {
@@ -476,9 +476,9 @@
AttributeParser aParser,
String[] uuids)
{
- FLYSContext flysContext = RiverUtils.getFlysContext(context);
+ RiverContext flysContext = RiverUtils.getFlysContext(context);
StateEngine engine = (StateEngine) flysContext.get(
- FLYSContext.STATE_ENGINE_KEY);
+ RiverContext.STATE_ENGINE_KEY);
if (engine == null) {
log.error("buildOutAttributes: engine == null");
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/exports/OutputHelper.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/OutputHelper.java Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/OutputHelper.java Sun Apr 28 15:14:30 2013 +0200
@@ -35,7 +35,7 @@
import org.dive4elements.artifacts.common.utils.ClientProtocolUtils;
import org.dive4elements.artifacts.common.utils.XMLUtils;
import org.dive4elements.river.artifacts.FLYSArtifact;
-import org.dive4elements.river.artifacts.context.FLYSContext;
+import org.dive4elements.river.artifacts.context.RiverContext;
import org.dive4elements.river.artifacts.model.ManagedDomFacet;
import org.dive4elements.river.artifacts.model.ManagedFacet;
import org.dive4elements.river.themes.Theme;
@@ -440,16 +440,16 @@
{
log.info("FLYSArtifactCollection.getThemeForFacet: " + facet);
- FLYSContext flysContext = context instanceof FLYSContext
- ? (FLYSContext) context
- : (FLYSContext) context.globalContext();
+ RiverContext flysContext = context instanceof RiverContext
+ ? (RiverContext) context
+ : (RiverContext) context.globalContext();
// Push artifact in flysContext.
ArtifactDatabase db = context.getDatabase();
try {
FLYSArtifact artifact = (FLYSArtifact) db.getRawArtifact(uuid);
log.debug("Got raw artifact");
- flysContext.put(FLYSContext.ARTIFACT_KEY, artifact);
+ flysContext.put(RiverContext.ARTIFACT_KEY, artifact);
}
catch (ArtifactDatabaseException dbe) {
log.error("Exception caught when trying to get art.", dbe);
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/exports/sq/SQOverviewGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/sq/SQOverviewGenerator.java Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/sq/SQOverviewGenerator.java Sun Apr 28 15:14:30 2013 +0200
@@ -33,7 +33,7 @@
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.artifacts.common.ArtifactNamespaceContext;
import org.dive4elements.artifacts.common.utils.XMLUtils;
-import org.dive4elements.river.artifacts.context.FLYSContext;
+import org.dive4elements.river.artifacts.context.RiverContext;
import org.dive4elements.river.collections.FLYSArtifactCollection;
import org.dive4elements.river.exports.ChartGenerator;
import org.dive4elements.river.exports.OutGenerator;
@@ -78,7 +78,7 @@
if(name != null) {
logger.debug("name: " + name);
ChartGenerator g =
- (ChartGenerator)FLYSContext.getOutGenerator(
+ (ChartGenerator)RiverContext.getOutGenerator(
context,
name,
null);
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/themes/ThemeFactory.java
--- a/artifacts/src/main/java/org/dive4elements/river/themes/ThemeFactory.java Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/themes/ThemeFactory.java Sun Apr 28 15:14:30 2013 +0200
@@ -10,7 +10,7 @@
import org.dive4elements.artifacts.common.utils.XMLUtils;
import org.dive4elements.river.artifacts.FLYSArtifact;
-import org.dive4elements.river.artifacts.context.FLYSContext;
+import org.dive4elements.river.artifacts.context.RiverContext;
import java.util.ArrayList;
import java.util.HashMap;
@@ -76,7 +76,7 @@
* @return First matching theme.
*/
public static Theme getTheme(
- FLYSContext c,
+ RiverContext c,
String name,
String pattern,
String output,
@@ -95,11 +95,11 @@
// Fetch mapping and themes.
@SuppressWarnings("unchecked")
Map<String, List<ThemeMapping>> map = (Map<String, List<ThemeMapping>>)
- c.get(FLYSContext.THEME_MAPPING);
+ c.get(RiverContext.THEME_MAPPING);
@SuppressWarnings("unchecked")
List<ThemeGroup> tgs = (List<ThemeGroup>)
- c.get(FLYSContext.THEMES);
+ c.get(RiverContext.THEMES);
ThemeGroup group = null;
for (ThemeGroup tg: tgs) {
@@ -116,7 +116,7 @@
Map<String, Theme> t = group.getThemes();
- FLYSArtifact artifact = (FLYSArtifact) c.get(FLYSContext.ARTIFACT_KEY);
+ FLYSArtifact artifact = (FLYSArtifact) c.get(RiverContext.ARTIFACT_KEY);
if (map == null || map.isEmpty() || t == null || t.isEmpty()) {
logger.warn("No mappings or themes found. Cannot retrieve theme!");
@@ -155,17 +155,17 @@
@SuppressWarnings("unchecked")
- public static List<ThemeGroup> getThemeGroups(FLYSContext c) {
+ public static List<ThemeGroup> getThemeGroups(RiverContext c) {
List<ThemeGroup> tgs = (List<ThemeGroup>)
- c.get(FLYSContext.THEMES);
+ c.get(RiverContext.THEMES);
return tgs;
}
@SuppressWarnings("unchecked")
- public static List<Theme> getThemes (FLYSContext c, String name) {
+ public static List<Theme> getThemes (RiverContext c, String name) {
List<ThemeGroup> tgs = (List<ThemeGroup>)
- c.get(FLYSContext.THEMES);
+ c.get(RiverContext.THEMES);
if (tgs == null) {
return null;
}
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java
--- a/artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java Sun Apr 28 15:14:30 2013 +0200
@@ -17,7 +17,7 @@
import org.dive4elements.river.artifacts.StaticWKmsArtifact;
import org.dive4elements.river.artifacts.WINFOArtifact;
import org.dive4elements.river.artifacts.access.RangeAccess;
-import org.dive4elements.river.artifacts.context.FLYSContext;
+import org.dive4elements.river.artifacts.context.RiverContext;
import org.dive4elements.river.artifacts.model.LocationProvider;
import org.dive4elements.river.artifacts.model.RiverFactory;
import org.dive4elements.river.artifacts.model.WKms;
@@ -139,16 +139,16 @@
/**
- * Returns the FLYSContext from context object.
+ * Returns the RiverContext from context object.
*
- * @param context The CallContext or the FLYSContext.
+ * @param context The CallContext or the RiverContext.
*
- * @return the FLYSContext.
+ * @return the RiverContext.
*/
- public static FLYSContext getFlysContext(Object context) {
- return context instanceof FLYSContext
- ? (FLYSContext) context
- : (FLYSContext) ((CallContext) context).globalContext();
+ public static RiverContext getFlysContext(Object context) {
+ return context instanceof RiverContext
+ ? (RiverContext) context
+ : (RiverContext) ((CallContext) context).globalContext();
}
diff -r 73da40528cf2 -r 9a6741ccf6d4 artifacts/src/main/java/org/dive4elements/river/wsplgen/SchedulerSetup.java
--- a/artifacts/src/main/java/org/dive4elements/river/wsplgen/SchedulerSetup.java Sun Apr 28 15:09:31 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/wsplgen/SchedulerSetup.java Sun Apr 28 15:14:30 2013 +0200
@@ -14,12 +14,12 @@
import org.dive4elements.artifactdatabase.LifetimeListener;
-import org.dive4elements.river.artifacts.context.FLYSContext;
+import org.dive4elements.river.artifacts.context.RiverContext;
/**
* A LifetimeListener that is used to create an instance of Scheduler. This
- * instance is put into the GlobalContext using FLYSContext.SCHEDULER.
+ * instance is put into the GlobalContext using RiverContext.SCHEDULER.
*
* @author <a href="mailto:ingo.weinzierl at intevation.de">Ingo Weinzierl</a>
*/
@@ -33,7 +33,7 @@
@Override
public void systemUp(GlobalContext globalContext) {
Scheduler scheduler = Scheduler.getInstance();
- globalContext.put(FLYSContext.SCHEDULER, scheduler);
+ globalContext.put(RiverContext.SCHEDULER, scheduler);
}
More information about the Dive4elements-commits
mailing list