Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java @ 127:f6f0e4ce4a35
merged gnv-artifacts/0.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:41 +0200 |
parents | ef157bd2fa92 |
children | 7fb9441dd8af |
comparison
equal
deleted
inserted
replaced
49:94a07d1d9316 | 127:f6f0e4ce4a35 |
---|---|
1 /** | |
2 * | |
3 */ | |
4 package de.intevation.gnv.transition; | |
5 | |
6 import java.io.OutputStream; | |
7 import java.util.ArrayList; | |
8 import java.util.Collection; | |
9 | |
10 import net.sf.ehcache.Element; | |
11 | |
12 import org.apache.log4j.Logger; | |
13 import org.w3c.dom.Node; | |
14 import org.w3c.dom.NodeList; | |
15 | |
16 import de.intevation.artifactdatabase.Config; | |
17 import de.intevation.artifacts.CallMeta; | |
18 import de.intevation.gnv.artifacts.cache.CacheFactory; | |
19 import de.intevation.gnv.geobackend.base.Result; | |
20 import de.intevation.gnv.transition.exception.TransitionException; | |
21 | |
22 /** | |
23 * @author Tim Englich <tim.englich@intevation.de> | |
24 * | |
25 */ | |
26 public abstract class OutputTransitionBase extends TransitionBase implements | |
27 OutputTransition { | |
28 | |
29 | |
30 /** | |
31 * The UID of this Class | |
32 */ | |
33 private static final long serialVersionUID = -1718732895737303823L; | |
34 | |
35 /** | |
36 * the logger, used to log exceptions and additonaly information | |
37 */ | |
38 private static Logger log = Logger.getLogger(OutputTransitionBase.class); | |
39 | |
40 | |
41 /** | |
42 * The different Outputmodes which are provided by an OutputTransition | |
43 */ | |
44 protected Collection<OutputMode> outputModes = null; | |
45 | |
46 /** | |
47 * Constructor | |
48 */ | |
49 public OutputTransitionBase() { | |
50 super(); | |
51 } | |
52 | |
53 /** | |
54 * @see de.intevation.gnv.transition.OutputTransition#getOutputModes() | |
55 */ | |
56 public Collection<OutputMode> getOutputModes() { | |
57 log.debug("OutputTransitionBase.getOutputModes"); | |
58 return this.outputModes; | |
59 } | |
60 /** | |
61 * @see de.intevation.gnv.transition.Transition#validate() | |
62 */ | |
63 public boolean validate() { | |
64 log.debug("OutputTransitionBase.validate"); | |
65 return true; | |
66 } | |
67 | |
68 /** | |
69 * @see de.intevation.gnv.transition.TransitionBase#setup(org.w3c.dom.Node) | |
70 */ | |
71 @Override | |
72 public void setup(Node configuration) { | |
73 log.debug("OutputTransitionBase.setup"); | |
74 super.setup(configuration); | |
75 NodeList outputModeList = Config.getNodeSetXPath(configuration, "outputsModes/outputsMode"); | |
76 if (outputModeList != null){ | |
77 log.debug(outputModeList.getLength()+ " were found."); | |
78 this.outputModes = new ArrayList<OutputMode>(outputModeList.getLength()); | |
79 for (int i = 0; i < outputModeList.getLength(); i++){ | |
80 Node currentNode = outputModeList.item(i); | |
81 String name = Config.getStringXPath(currentNode, "@name"); | |
82 String description = Config.getStringXPath(currentNode, "@description"); | |
83 String mimeType = Config.getStringXPath(currentNode, "@mime-type"); | |
84 | |
85 NodeList inputValuesList = Config.getNodeSetXPath(currentNode, "parameters/inputvalue"); | |
86 Collection<InputValue> inputParameters = null; | |
87 if (inputValuesList != null){ | |
88 inputParameters = new ArrayList<InputValue>(inputValuesList.getLength()); | |
89 for (int j = 0 ; j < inputValuesList.getLength(); j++){ | |
90 Node currentInputValuesNode = inputValuesList.item(j); | |
91 String inputValueName = Config.getStringXPath(currentInputValuesNode, "@name"); | |
92 String inputValueType = Config.getStringXPath(currentInputValuesNode, "@type"); | |
93 String defaultValue = Config.getStringXPath(currentInputValuesNode, "@value"); | |
94 boolean isMultiselect = false; | |
95 InputValue inputValue = new DefaultInputValue(inputValueName, inputValueType, defaultValue, isMultiselect); | |
96 inputParameters.add(inputValue); | |
97 } | |
98 } | |
99 | |
100 OutputMode outputMode = new DefaultOutputMode(name, description, mimeType,inputParameters); | |
101 log.debug(outputMode.toString()); | |
102 this.outputModes.add(outputMode); | |
103 | |
104 } | |
105 } | |
106 } | |
107 | |
108 /** | |
109 * @see de.intevation.gnv.transition.TransitionBase#advance() | |
110 */ | |
111 @Override | |
112 public void advance(String uuid, CallMeta callMeta) throws TransitionException { | |
113 log.debug("OutputTransitionBase.advance"); | |
114 if (this.getChartResult(uuid) == null){ | |
115 super.advance(uuid, callMeta); | |
116 } | |
117 } | |
118 | |
119 /** | |
120 * @see de.intevation.gnv.transition.OutputTransition#out(java.lang.String, java.util.Collection, java.io.OutputStream) | |
121 */ | |
122 public void out(String outputMode, Collection<InputData> inputData, | |
123 OutputStream outputStream) throws TransitionException { | |
124 } | |
125 | |
126 /** | |
127 * @return | |
128 */ | |
129 protected Collection<Result> getChartResult(String uuid) { | |
130 log.debug("OutputTransitionBase.getChartResult"); | |
131 if (CacheFactory.getInstance().isInitialized()){ | |
132 String key = uuid+super.getID(); | |
133 log.debug("Hash for Queryelements: "+key); | |
134 Element value = CacheFactory.getInstance().getCache().get(key); | |
135 if (value != null){ | |
136 return (Collection<Result>)(value.getObjectValue()); | |
137 } | |
138 } | |
139 return null; | |
140 } | |
141 | |
142 /** | |
143 * @see de.intevation.gnv.transition.TransitionBase#purifyResult(java.util.Collection, java.lang.String) | |
144 */ | |
145 @Override | |
146 protected void purifyResult(Collection<Result> result, String uuid) { | |
147 log.debug("OutputTransitionBase.purifyResult"); | |
148 if (CacheFactory.getInstance().isInitialized()){ | |
149 String key = uuid+super.getID(); | |
150 log.debug("Hash for Queryelements: "+key); | |
151 CacheFactory.getInstance().getCache().put(new Element(key, result)); | |
152 } | |
153 } | |
154 | |
155 } |