comparison gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/FISArtifact.java @ 171:7fb9441dd8af

Format Code to max 80 Chars per Row and Cleanup gnv-artifacts/trunk@208 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 09 Oct 2009 07:54:48 +0000
parents 5ebc059064a6
children 734ac082c8d1
comparison
equal deleted inserted replaced
170:7be22e76c270 171:7fb9441dd8af
34 import de.intevation.gnv.utils.ArtifactFactoryUtilities; 34 import de.intevation.gnv.utils.ArtifactFactoryUtilities;
35 import de.intevation.gnv.utils.ArtifactXMLUtilities; 35 import de.intevation.gnv.utils.ArtifactXMLUtilities;
36 36
37 /** 37 /**
38 * @author Tim Englich <tim.englich@intevation.de> 38 * @author Tim Englich <tim.englich@intevation.de>
39 * 39 *
40 */ 40 */
41 public class FISArtifact extends DefaultArtifact { 41 public class FISArtifact extends DefaultArtifact {
42 42
43 /** 43 /**
44 * the logger, used to log exceptions and additonaly information 44 * the logger, used to log exceptions and additonaly information
45 */ 45 */
46 private static Logger log = Logger.getLogger(GNVArtifactBase.class); 46 private static Logger log = Logger.getLogger(GNVArtifactBase.class);
47 /** 47 /**
48 * The UID of this Class 48 * The UID of this Class
49 */ 49 */
50 private static final long serialVersionUID = 2874044542701727083L; 50 private static final long serialVersionUID = 2874044542701727083L;
51 51
52 /** 52 /**
53 * The Identifier for the Replacement of the Artifactname 53 * The Identifier for the Replacement of the Artifactname
54 */ 54 */
55 public static final String XPATH_IDENTIFIER_REPLACE = "IDENTIFIER"; 55 public static final String XPATH_IDENTIFIER_REPLACE = "IDENTIFIER";
56 56
57 /** 57 /**
58 * The XPATH to the XML-Fragment that should be used for the Configuration 58 * The XPATH to the XML-Fragment that should be used for the Configuration
59 */ 59 */
60 public static final String XPATH_ARTIFACT_CONFIGURATION= "/artifact-database/artifacts/artifact[@name='"+XPATH_IDENTIFIER_REPLACE+"']"; 60 public static final String XPATH_ARTIFACT_CONFIGURATION = "/artifact-database/artifacts/artifact[@name='"
61 61 + XPATH_IDENTIFIER_REPLACE
62 + "']";
63
62 /** 64 /**
63 * The Name of the Artifact 65 * The Name of the Artifact
64 */ 66 */
65 private String name = null; 67 private String name = null;
66 68
67 private Map<String, Product> products = null; 69 private Map<String, Product> products = null;
68 70
69 private Artifact productArtifact = null; 71 private Artifact productArtifact = null;
70 72
71 private Product current = null; 73 private Product current = null;
72 74
73 private ArtifactXMLUtilities xmlUtilities = new ArtifactXMLUtilities(); 75 private ArtifactXMLUtilities xmlUtilities = new ArtifactXMLUtilities();
74 76
75 77 /**
76 /** 78 * @see de.intevation.artifactdatabase.DefaultArtifact#advance(org.w3c.dom.Document,
77 * @see de.intevation.artifactdatabase.DefaultArtifact#advance(org.w3c.dom.Document, de.intevation.artifacts.CallContext) 79 * de.intevation.artifacts.CallContext)
78 */ 80 */
79 @Override 81 @Override
80 public Document advance(Document target, CallContext context) { 82 public Document advance(Document target, CallContext context) {
81 83
82 Document result = null; 84 Document result = null;
83 if (this.productArtifact == null){ 85 if (this.productArtifact == null) {
84 if (this.current != null){ 86 if (this.current != null) {
85 87
86 String uuid = Config.getStringXPath(target, "action/uuid/@value"); 88 String uuid = Config.getStringXPath(target,
87 String hash = Config.getStringXPath(target, "action/hash/@value"); 89 "action/uuid/@value");
88 this.productArtifact = this.current.getArtifactFactory().createArtifact(uuid, context); 90 String hash = Config.getStringXPath(target,
89 Document feedDocument = xmlUtilities.reInitDocument(this.createFeedProductArtifactDocument(uuid, hash)); 91 "action/hash/@value");
90 log.debug("Feed ==> "+this.xmlUtilities.writeDocument2String(feedDocument)); 92 this.productArtifact = this.current.getArtifactFactory()
91 Document descibeDocument = xmlUtilities.reInitDocument(this.productArtifact.describe(context)); 93 .createArtifact(uuid, context);
92 log.debug("Descibe ==> "+this.xmlUtilities.writeDocument2String(descibeDocument)); 94 Document feedDocument = xmlUtilities.reInitDocument(this
93 this.productArtifact.feed(feedDocument, context); 95 .createFeedProductArtifactDocument(uuid, hash));
94 String targetName = Config.getStringXPath(descibeDocument, "result/reachable-states/state/@name"); 96 log.debug("Feed ==> "
95 Document advanceDocument = xmlUtilities.reInitDocument(this.createAdvanceProductArtifactDocument(uuid, hash, targetName)); 97 + this.xmlUtilities
96 log.debug("Advance ==> "+this.xmlUtilities.writeDocument2String(advanceDocument)); 98 .writeDocument2String(feedDocument));
97 result = this.productArtifact.advance(advanceDocument, context); 99 Document descibeDocument = xmlUtilities
98 }else{ 100 .reInitDocument(this.productArtifact.describe(context));
101 log.debug("Descibe ==> "
102 + this.xmlUtilities
103 .writeDocument2String(descibeDocument));
104 this.productArtifact.feed(feedDocument, context);
105 String targetName = Config.getStringXPath(descibeDocument,
106 "result/reachable-states/state/@name");
107 Document advanceDocument = xmlUtilities.reInitDocument(this
108 .createAdvanceProductArtifactDocument(uuid, hash,
109 targetName));
110 log.debug("Advance ==> "
111 + this.xmlUtilities
112 .writeDocument2String(advanceDocument));
113 result = this.productArtifact.advance(advanceDocument, context);
114 } else {
99 String msg = "Artifact is not configured properly. Call feed first."; 115 String msg = "Artifact is not configured properly. Call feed first.";
100 log.error(msg); 116 log.error(msg);
101 result = new ArtifactXMLUtilities().createExceptionReport(msg, XMLUtils.newDocument()); 117 result = new ArtifactXMLUtilities().createExceptionReport(msg,
102 } 118 XMLUtils.newDocument());
103 }else{ 119 }
120 } else {
104 result = this.productArtifact.advance(target, context); 121 result = this.productArtifact.advance(target, context);
105 } 122 }
106 return result; 123 return result;
107 } 124 }
108 private Document createAdvanceProductArtifactDocument(String uuid, String hash, String targetName){ 125
126 private Document createAdvanceProductArtifactDocument(String uuid,
127 String hash,
128 String targetName) {
109 Document document = XMLUtils.newDocument(); 129 Document document = XMLUtils.newDocument();
110 Element rootNode = xmlUtilities.createArtifactElement(document, "action"); 130 Element rootNode = xmlUtilities.createArtifactElement(document,
111 131 "action");
132
112 Element typeNode = xmlUtilities.createArtifactElement(document, "type"); 133 Element typeNode = xmlUtilities.createArtifactElement(document, "type");
113 typeNode.setAttribute("name", "advanve"); 134 typeNode.setAttribute("name", "advanve");
114 rootNode.appendChild(typeNode); 135 rootNode.appendChild(typeNode);
115 136
116 Element uuidNode = xmlUtilities.createArtifactElement(document, "uuid"); 137 Element uuidNode = xmlUtilities.createArtifactElement(document, "uuid");
117 uuidNode.setAttribute("value", uuid); 138 uuidNode.setAttribute("value", uuid);
118 rootNode.appendChild(uuidNode); 139 rootNode.appendChild(uuidNode);
119 140
120 Element hashNode = xmlUtilities.createArtifactElement(document, "hash"); 141 Element hashNode = xmlUtilities.createArtifactElement(document, "hash");
121 hashNode.setAttribute("value", hash); 142 hashNode.setAttribute("value", hash);
122 rootNode.appendChild(hashNode); 143 rootNode.appendChild(hashNode);
123 Element targetNode = xmlUtilities.createArtifactElement(document, "target"); 144 Element targetNode = xmlUtilities.createArtifactElement(document,
145 "target");
124 targetNode.setAttribute("name", targetName); 146 targetNode.setAttribute("name", targetName);
125 rootNode.appendChild(targetNode); 147 rootNode.appendChild(targetNode);
126 148
127 document.appendChild(rootNode); 149 document.appendChild(rootNode);
128 return document; 150 return document;
129 } 151 }
130 152
131 private Document createFeedProductArtifactDocument(String uuid, String hash){ 153 private Document createFeedProductArtifactDocument(String uuid, String hash) {
132 Document document = XMLUtils.newDocument(); 154 Document document = XMLUtils.newDocument();
133 Element rootNode = xmlUtilities.createArtifactElement(document, "action"); 155 Element rootNode = xmlUtilities.createArtifactElement(document,
134 156 "action");
157
135 Element typeNode = xmlUtilities.createArtifactElement(document, "type"); 158 Element typeNode = xmlUtilities.createArtifactElement(document, "type");
136 typeNode.setAttribute("name", "feed"); 159 typeNode.setAttribute("name", "feed");
137 rootNode.appendChild(typeNode); 160 rootNode.appendChild(typeNode);
138 161
139 Element uuidNode = xmlUtilities.createArtifactElement(document, "uuid"); 162 Element uuidNode = xmlUtilities.createArtifactElement(document, "uuid");
140 uuidNode.setAttribute("value", uuid); 163 uuidNode.setAttribute("value", uuid);
141 rootNode.appendChild(uuidNode); 164 rootNode.appendChild(uuidNode);
142 165
143 Element hashNode = xmlUtilities.createArtifactElement(document, "hash"); 166 Element hashNode = xmlUtilities.createArtifactElement(document, "hash");
144 hashNode.setAttribute("value", hash); 167 hashNode.setAttribute("value", hash);
145 rootNode.appendChild(hashNode); 168 rootNode.appendChild(hashNode);
146 169
147 Element dataNode = xmlUtilities.createArtifactElement(document, "data"); 170 Element dataNode = xmlUtilities.createArtifactElement(document, "data");
148 rootNode.appendChild(dataNode); 171 rootNode.appendChild(dataNode);
149 172
150
151 Collection<InputData> parameter = this.current.getParameter(); 173 Collection<InputData> parameter = this.current.getParameter();
152 if (parameter != null){ 174 if (parameter != null) {
153 Iterator<InputData> parameterIt = parameter.iterator(); 175 Iterator<InputData> parameterIt = parameter.iterator();
154 while(parameterIt.hasNext()){ 176 while (parameterIt.hasNext()) {
155 InputData inputData = parameterIt.next(); 177 InputData inputData = parameterIt.next();
156 Element inputNode = xmlUtilities.createArtifactElement(document, "input"); 178 Element inputNode = xmlUtilities.createArtifactElement(
179 document, "input");
157 inputNode.setAttribute("name", inputData.getName()); 180 inputNode.setAttribute("name", inputData.getName());
158 inputNode.setAttribute("value", inputData.getValue()); 181 inputNode.setAttribute("value", inputData.getValue());
159 dataNode.appendChild(inputNode); 182 dataNode.appendChild(inputNode);
160 } 183 }
161 } 184 }
162 document.appendChild(rootNode); 185 document.appendChild(rootNode);
163 return document; 186 return document;
164 187
165 } 188 }
166 189
167 /** 190 /**
168 * @see de.intevation.artifactdatabase.DefaultArtifact#describe(java.lang.Object) 191 * @see de.intevation.artifactdatabase.DefaultArtifact#describe(java.lang.Object)
169 */ 192 */
170 @Override 193 @Override
171 public Document describe(CallContext context) { 194 public Document describe(CallContext context) {
172 if (this.productArtifact == null){ 195 if (this.productArtifact == null) {
173 return this.createDescibeOutput(context.getMeta()); 196 return this.createDescibeOutput(context.getMeta());
174 }else{ 197 } else {
175 Document document = this.productArtifact.describe(context); 198 Document document = this.productArtifact.describe(context);
176 document = new ArtifactXMLUtilities().reInitDocument(document); 199 document = new ArtifactXMLUtilities().reInitDocument(document);
177 Node staticNode = Config.getNodeXPath(document, "/result/ui/static"); 200 Node staticNode = Config
178 if (staticNode != null){ 201 .getNodeXPath(document, "/result/ui/static");
179 Node staticUI = this.createSelectBox(document, context.getMeta()); 202 if (staticNode != null) {
203 Node staticUI = this.createSelectBox(document, context
204 .getMeta());
180 staticNode.insertBefore(staticUI, staticNode.getFirstChild()); 205 staticNode.insertBefore(staticUI, staticNode.getFirstChild());
181 } 206 }
182 return document; 207 return document;
183 } 208 }
184 } 209 }
185 210
186 /** 211 /**
187 * @see de.intevation.artifactdatabase.DefaultArtifact#feed(org.w3c.dom.Document, java.lang.Object) 212 * @see de.intevation.artifactdatabase.DefaultArtifact#feed(org.w3c.dom.Document,
213 * java.lang.Object)
188 */ 214 */
189 @Override 215 @Override
190 public Document feed(Document target, CallContext context) { 216 public Document feed(Document target, CallContext context) {
191 log.debug("FISArtifact.feed"); 217 log.debug("FISArtifact.feed");
192 Document result = null; 218 Document result = null;
193 if (this.productArtifact == null){ 219 if (this.productArtifact == null) {
194 String productName = Config.getStringXPath(target, "action/data/input[@name='product']/@value"); 220 String productName = Config.getStringXPath(target,
195 log.debug("Looking for ProductArtifact "+productName); 221 "action/data/input[@name='product']/@value");
222 log.debug("Looking for ProductArtifact " + productName);
196 if (this.products.containsKey(productName)) { 223 if (this.products.containsKey(productName)) {
197 this.current = this.products.get(productName); 224 this.current = this.products.get(productName);
198 result = new ArtifactXMLUtilities().createSuccessReport("Feed success New ProductArtifact created", XMLUtils.newDocument()); 225 result = new ArtifactXMLUtilities().createSuccessReport(
199 }else{ 226 "Feed success New ProductArtifact created", XMLUtils
200 String msg = "Product does not exists for "+productName; 227 .newDocument());
228 } else {
229 String msg = "Product does not exists for " + productName;
201 log.error(msg); 230 log.error(msg);
202 result = new ArtifactXMLUtilities().createExceptionReport(msg, XMLUtils.newDocument()); 231 result = new ArtifactXMLUtilities().createExceptionReport(msg,
203 } 232 XMLUtils.newDocument());
204 }else{ 233 }
234 } else {
205 log.debug("Feed a Productartifact"); 235 log.debug("Feed a Productartifact");
206 result = this.productArtifact.feed(target, context); 236 result = this.productArtifact.feed(target, context);
207 } 237 }
208 return result; 238 return result;
209 } 239 }
210 240
211 /** 241 /**
212 * @see de.intevation.artifactdatabase.DefaultArtifact#out(org.w3c.dom.Document, java.lang.Object) 242 * @see de.intevation.artifactdatabase.DefaultArtifact#out(org.w3c.dom.Document,
243 * java.lang.Object)
213 */ 244 */
214 @Override 245 @Override
215 public void out(Document format, OutputStream outputStream, CallContext context) throws IOException { 246 public void out(Document format, OutputStream outputStream,
216 if (this.productArtifact != null){ 247 CallContext context) throws IOException {
217 this.productArtifact.out(format,outputStream, context); 248 if (this.productArtifact != null) {
249 this.productArtifact.out(format, outputStream, context);
218 } 250 }
219 } 251 }
220 252
221 /** 253 /**
222 * Constructor 254 * Constructor
223 */ 255 */
224 public FISArtifact() { 256 public FISArtifact() {
225 super(); 257 super();
226 } 258 }
227 259
228 /** 260 /**
229 * @see de.intevation.artifactdatabase.DefaultArtifact#setup(java.lang.String, de.intevation.artifacts.ArtifactFactory, java.lang.Object) 261 * @see de.intevation.artifactdatabase.DefaultArtifact#setup(java.lang.String,
230 */ 262 * de.intevation.artifacts.ArtifactFactory, java.lang.Object)
263 */
231 @Override 264 @Override
232 public void setup(String identifier, ArtifactFactory factory, Object context) { 265 public void setup(String identifier, ArtifactFactory factory, Object context) {
233 log.debug("FISArtifact.setup"); 266 log.debug("FISArtifact.setup");
234 this.name = factory.getName(); 267 this.name = factory.getName();
235 super.setup(identifier,factory, context); 268 super.setup(identifier, factory, context);
236 if (context instanceof GNVArtifactContext){ 269 if (context instanceof GNVArtifactContext) {
237 GNVArtifactContext gnvContext = (GNVArtifactContext)context; 270 GNVArtifactContext gnvContext = (GNVArtifactContext) context;
238 Document doc = gnvContext.getConfig(); 271 Document doc = gnvContext.getConfig();
239 Node artifactNode = this.getConfigurationFragment(doc); 272 Node artifactNode = this.getConfigurationFragment(doc);
240 273
241 NodeList products = Config.getNodeSetXPath(artifactNode,"products/product"); 274 NodeList products = Config.getNodeSetXPath(artifactNode,
242 if (products != null){ 275 "products/product");
243 this.products = new HashMap<String, Product>(products.getLength()); 276 if (products != null) {
244 for (int i = 0; i < products.getLength(); i++){ 277 this.products = new HashMap<String, Product>(products
245 Node productNode = products.item(i); 278 .getLength());
246 String productName = Config.getStringXPath(productNode, "@name"); 279 for (int i = 0; i < products.getLength(); i++) {
247 NodeList parameterNodes = Config.getNodeSetXPath(productNode, "parameters/parameter"); 280 Node productNode = products.item(i);
248 Collection<InputData> parameter = null; 281 String productName = Config.getStringXPath(productNode,
249 if (parameterNodes != null){ 282 "@name");
250 parameter = new ArrayList<InputData>(parameterNodes.getLength()); 283 NodeList parameterNodes = Config.getNodeSetXPath(
251 for (int j = 0; j < parameterNodes.getLength(); j++){ 284 productNode, "parameters/parameter");
252 Node parameterNode = parameterNodes.item(j); 285 Collection<InputData> parameter = null;
253 String name = Config.getStringXPath(parameterNode, "@name"); 286 if (parameterNodes != null) {
254 String value = Config.getStringXPath(parameterNode, "@value"); 287 parameter = new ArrayList<InputData>(parameterNodes
255 parameter.add(new DefaultInputData(name, value)); 288 .getLength());
256 } 289 for (int j = 0; j < parameterNodes.getLength(); j++) {
257 } 290 Node parameterNode = parameterNodes.item(j);
258 Node artifactFactoryNode = Config.getNodeXPath(productNode, "artifact-factory"); 291 String name = Config.getStringXPath(parameterNode,
259 ArtifactFactory artifactFactory =new ArtifactFactoryUtilities().createArtitfactFactor(doc, artifactFactoryNode); 292 "@name");
260 this.products.put(productName, new DefaultProduct(productName, parameter,artifactFactory)); 293 String value = Config.getStringXPath(parameterNode,
261 } 294 "@value");
262 } 295 parameter.add(new DefaultInputData(name, value));
263 } 296 }
264 } 297 }
265 298 Node artifactFactoryNode = Config.getNodeXPath(productNode,
266 protected Node getConfigurationFragment(Document document){ 299 "artifact-factory");
300 ArtifactFactory artifactFactory = new ArtifactFactoryUtilities()
301 .createArtitfactFactor(doc, artifactFactoryNode);
302 this.products.put(productName, new DefaultProduct(
303 productName, parameter, artifactFactory));
304 }
305 }
306 }
307 }
308
309 protected Node getConfigurationFragment(Document document) {
267 log.debug("GNVArtifactBase.getConfigurationFragment"); 310 log.debug("GNVArtifactBase.getConfigurationFragment");
268 String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll(XPATH_IDENTIFIER_REPLACE, this.name); 311 String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll(
312 XPATH_IDENTIFIER_REPLACE, this.name);
269 log.debug(xpathQuery); 313 log.debug(xpathQuery);
270 return Config.getNodeXPath(document,xpathQuery); 314 return Config.getNodeXPath(document, xpathQuery);
271 } 315 }
272 316
273 protected Document createDescibeOutput(CallMeta callMeta){ 317 protected Document createDescibeOutput(CallMeta callMeta) {
274 log.debug("GNVArtifactBase.createDescibeOutput"); 318 log.debug("GNVArtifactBase.createDescibeOutput");
275 Document document = XMLUtils.newDocument(); 319 Document document = XMLUtils.newDocument();
276 Element rootNode = this.createRootNode(document); 320 Element rootNode = this.createRootNode(document);
277 this.createHeader(rootNode, document, "describe"); 321 this.createHeader(rootNode, document, "describe");
278 this.createOutputs(rootNode, document); 322 this.createOutputs(rootNode, document);
279 this.createCurrentState(rootNode, document); 323 this.createCurrentState(rootNode, document);
280 this.createReachableStates(rootNode, document); 324 this.createReachableStates(rootNode, document);
281 this.createModel(rootNode, document); 325 this.createModel(rootNode, document);
282 this.createUserInterface(rootNode, document, callMeta); 326 this.createUserInterface(rootNode, document, callMeta);
283 327
284 return document; 328 return document;
285 } 329 }
286 330
287 protected Element createRootNode(Document document){ 331 protected Element createRootNode(Document document) {
288 Element rootNode = xmlUtilities.createArtifactElement(document,"result"); 332 Element rootNode = xmlUtilities.createArtifactElement(document,
333 "result");
289 document.appendChild(rootNode); 334 document.appendChild(rootNode);
290 return rootNode; 335 return rootNode;
291 } 336 }
292 337
293 protected void createHeader(Element parent, Document document, String documentType){ 338 protected void createHeader(Element parent, Document document,
294 Element typeNode = xmlUtilities.createArtifactElement(document,"type"); 339 String documentType) {
340 Element typeNode = xmlUtilities.createArtifactElement(document, "type");
295 typeNode.setAttribute("name", documentType); 341 typeNode.setAttribute("name", documentType);
296 parent.appendChild(typeNode); 342 parent.appendChild(typeNode);
297 343
298 Element uuidNode = xmlUtilities.createArtifactElement(document,"uuid"); 344 Element uuidNode = xmlUtilities.createArtifactElement(document, "uuid");
299 uuidNode.setAttribute("value", super.identifier); 345 uuidNode.setAttribute("value", super.identifier);
300 parent.appendChild(uuidNode); 346 parent.appendChild(uuidNode);
301 347
302 Element hashNode = xmlUtilities.createArtifactElement(document,"hash"); 348 Element hashNode = xmlUtilities.createArtifactElement(document, "hash");
303 hashNode.setAttribute("value", this.hash()); 349 hashNode.setAttribute("value", this.hash());
304 parent.appendChild(hashNode); 350 parent.appendChild(hashNode);
305 351
306 352 }
307 } 353
308 protected void createReachableStates(Element parent,Document document){ 354 protected void createReachableStates(Element parent, Document document) {
309 Element stateNode = xmlUtilities.createArtifactElement(document,"reachable-states"); 355 Element stateNode = xmlUtilities.createArtifactElement(document,
310 if (this.products != null){ 356 "reachable-states");
357 if (this.products != null) {
311 Iterator<Product> products = this.products.values().iterator(); 358 Iterator<Product> products = this.products.values().iterator();
312 while(products.hasNext()){ 359 while (products.hasNext()) {
313 Product product = products.next(); 360 Product product = products.next();
314 Element currentNode = xmlUtilities.createArtifactElement(document,"state"); 361 Element currentNode = xmlUtilities.createArtifactElement(
362 document, "state");
315 currentNode.setAttribute("name", product.getName()); 363 currentNode.setAttribute("name", product.getName());
316 currentNode.setAttribute("description", product.getName()); 364 currentNode.setAttribute("description", product.getName());
317 stateNode.appendChild(currentNode); 365 stateNode.appendChild(currentNode);
318 } 366 }
319 } 367 }
320 parent.appendChild(stateNode); 368 parent.appendChild(stateNode);
321 } 369 }
322 370
323 protected void createCurrentState(Element parent, Document document){ 371 protected void createCurrentState(Element parent, Document document) {
324 Element stateNode = xmlUtilities.createArtifactElement(document,"state"); 372 Element stateNode = xmlUtilities.createArtifactElement(document,
373 "state");
325 stateNode.setAttribute("name", "choose-product"); 374 stateNode.setAttribute("name", "choose-product");
326 stateNode.setAttribute("description", "Initialer Stand Auswahl des products"); 375 stateNode.setAttribute("description",
376 "Initialer Stand Auswahl des products");
327 parent.appendChild(stateNode); 377 parent.appendChild(stateNode);
328 } 378 }
329 379
330 380 protected void createModel(Element parent, Document document) {
331 protected void createModel(Element parent, Document document){ 381 Element modelNode = xmlUtilities.createArtifactElement(document,
332 Element modelNode = xmlUtilities.createArtifactElement(document,"model"); 382 "model");
333 383
334 Element inputNode = xmlUtilities.createArtifactElement(document,"input"); 384 Element inputNode = xmlUtilities.createArtifactElement(document,
385 "input");
335 inputNode.setAttribute("name", "product"); 386 inputNode.setAttribute("name", "product");
336 inputNode.setAttribute("type", "String"); 387 inputNode.setAttribute("type", "String");
337 modelNode.appendChild(inputNode); 388 modelNode.appendChild(inputNode);
338 389
339 parent.appendChild(modelNode); 390 parent.appendChild(modelNode);
340 } 391 }
341 392
342 protected void createUserInterface(Element parent, Document document, CallMeta callMeta){ 393 protected void createUserInterface(Element parent, Document document,
343 Element uiNode = xmlUtilities.createArtifactElement(document,"ui"); 394 CallMeta callMeta) {
395 Element uiNode = xmlUtilities.createArtifactElement(document, "ui");
344 ArtifactXMLUtilities xmlUtilities = new ArtifactXMLUtilities(); 396 ArtifactXMLUtilities xmlUtilities = new ArtifactXMLUtilities();
345 Node dynamic = xmlUtilities.createArtifactElement(document, "dynamic"); 397 Node dynamic = xmlUtilities.createArtifactElement(document, "dynamic");
346 uiNode.appendChild(dynamic); 398 uiNode.appendChild(dynamic);
347 if (this.products != null && !this.products.isEmpty()){ 399 if (this.products != null && !this.products.isEmpty()) {
348 Element selectNode = createSelectBox(document,callMeta); 400 Element selectNode = createSelectBox(document, callMeta);
349 401
350 dynamic.appendChild(selectNode); 402 dynamic.appendChild(selectNode);
351 } 403 }
352 404
353 parent.appendChild(uiNode); 405 parent.appendChild(uiNode);
354 } 406 }
407
355 /** 408 /**
356 * @param document 409 * @param document
357 * @param xmlUtilities 410 * @param xmlUtilities
358 * @return 411 * @return
359 */ 412 */
360 private Element createSelectBox(Document document, CallMeta callMeta) { 413 private Element createSelectBox(Document document, CallMeta callMeta) {
361 414
362 ArtifactXMLUtilities xmlUtilities = new ArtifactXMLUtilities(); 415 ArtifactXMLUtilities xmlUtilities = new ArtifactXMLUtilities();
363 String selectboxName = "product"; 416 String selectboxName = "product";
364 Iterator<Product> it = this.products.values().iterator(); 417 Iterator<Product> it = this.products.values().iterator();
365 Element selectNode = xmlUtilities.createXFormElement(document,"select1"); 418 Element selectNode = xmlUtilities.createXFormElement(document,
419 "select1");
366 selectNode.setAttribute("ref", selectboxName); 420 selectNode.setAttribute("ref", selectboxName);
367 421
368
369 Element lableNode = xmlUtilities.createXFormElement(document, "label"); 422 Element lableNode = xmlUtilities.createXFormElement(document, "label");
370 lableNode.setTextContent(RessourceFactory.getInstance().getRessource(callMeta.getLanguages(), selectboxName, selectboxName)); 423 lableNode.setTextContent(RessourceFactory.getInstance().getRessource(
424 callMeta.getLanguages(), selectboxName, selectboxName));
371 selectNode.appendChild(lableNode); 425 selectNode.appendChild(lableNode);
372 Element choiceNode = xmlUtilities.createXFormElement(document, "choices"); 426 Element choiceNode = xmlUtilities.createXFormElement(document,
427 "choices");
373 selectNode.appendChild(choiceNode); 428 selectNode.appendChild(choiceNode);
374 while (it.hasNext()){ 429 while (it.hasNext()) {
375 Product p = it.next(); 430 Product p = it.next();
376 Element itemNode = xmlUtilities.createXFormElement(document, "item"); 431 Element itemNode = xmlUtilities
377 432 .createXFormElement(document, "item");
378 if (this.current != null && this.current.getName().equals(p.getName())){ 433
434 if (this.current != null
435 && this.current.getName().equals(p.getName())) {
379 itemNode.setAttribute("selected", "true"); 436 itemNode.setAttribute("selected", "true");
380 } 437 }
381 438
382 Element choiceLableNode = xmlUtilities.createXFormElement(document, "label"); 439 Element choiceLableNode = xmlUtilities.createXFormElement(document,
383 choiceLableNode.setTextContent(RessourceFactory.getInstance().getRessource(callMeta.getLanguages(), p.getName(), p.getName())); 440 "label");
441 choiceLableNode.setTextContent(RessourceFactory.getInstance()
442 .getRessource(callMeta.getLanguages(), p.getName(),
443 p.getName()));
384 itemNode.appendChild(choiceLableNode); 444 itemNode.appendChild(choiceLableNode);
385 445
386 Element choicValueNode = xmlUtilities.createXFormElement(document, "value"); 446 Element choicValueNode = xmlUtilities.createXFormElement(document,
447 "value");
387 choicValueNode.setTextContent(p.getName()); 448 choicValueNode.setTextContent(p.getName());
388 itemNode.appendChild(choicValueNode); 449 itemNode.appendChild(choicValueNode);
389 450
390 choiceNode.appendChild(itemNode); 451 choiceNode.appendChild(itemNode);
391 452
392 } 453 }
393 return selectNode; 454 return selectNode;
394 } 455 }
395 456
396 protected void createOutputs(Element parent, Document document){ 457 protected void createOutputs(Element parent, Document document) {
397 log.debug("GNVArtifactBase.createOutputs"); 458 log.debug("GNVArtifactBase.createOutputs");
398 Element outputsNode = xmlUtilities.createArtifactElement(document,"outputs"); 459 Element outputsNode = xmlUtilities.createArtifactElement(document,
460 "outputs");
399 parent.appendChild(outputsNode); 461 parent.appendChild(outputsNode);
400 } 462 }
401 463
402 } 464 }

http://dive4elements.wald.intevation.org