001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/wps/execute/ExecuteRequest.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/exse/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstraße 19
030: 53177 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042: ---------------------------------------------------------------------------*/
043:
044: package org.deegree.ogcwebservices.wps.execute;
045:
046: import static org.deegree.ogcbase.CommonNamespaces.OWSNS;
047:
048: import java.net.MalformedURLException;
049: import java.net.URI;
050: import java.net.URISyntaxException;
051: import java.net.URL;
052: import java.util.ArrayList;
053: import java.util.HashMap;
054: import java.util.List;
055: import java.util.Map;
056:
057: import org.deegree.datatypes.Code;
058: import org.deegree.datatypes.values.TypedLiteral;
059: import org.deegree.framework.log.ILogger;
060: import org.deegree.framework.log.LoggerFactory;
061: import org.deegree.framework.xml.NamespaceContext;
062: import org.deegree.framework.xml.XMLParsingException;
063: import org.deegree.framework.xml.XMLTools;
064: import org.deegree.model.crs.CRSFactory;
065: import org.deegree.model.crs.CoordinateSystem;
066: import org.deegree.model.crs.UnknownCRSException;
067: import org.deegree.model.feature.GMLFeatureCollectionDocument;
068: import org.deegree.model.spatialschema.Envelope;
069: import org.deegree.model.spatialschema.GeometryFactory;
070: import org.deegree.ogcbase.CommonNamespaces;
071: import org.deegree.ogcwebservices.InvalidParameterValueException;
072: import org.deegree.ogcwebservices.MissingParameterValueException;
073: import org.deegree.ogcwebservices.OGCWebServiceException;
074: import org.deegree.ogcwebservices.OperationNotSupportedException;
075: import org.deegree.ogcwebservices.wps.WPSRequestBaseType;
076: import org.deegree.ogcwebservices.wps.execute.IOValue.ComplexValueReference;
077: import org.w3c.dom.Element;
078:
079: /**
080: * ExecuteRequest.java
081: *
082: * Created on 09.03.2006. 23:16:00h
083: *
084: * WPS Execute operation request, to execute one identified Process. If a process is to be run
085: * multiple times, each run shall be submitted as a separate Execute request.
086: *
087: *
088: * @author <a href="mailto:christian@kiehle.org">Christian Kiehle</a>
089: * @author <a href="mailto:christian.heier@gmx.de">Christian Heier</a>
090: * @author last edited by: $Author: ckiehle $
091: *
092: * @version $Revision: 10197 $, $Date: 2008-02-20 03:41:29 -0800 (Wed, 20 Feb 2008) $
093: */
094: public class ExecuteRequest extends WPSRequestBaseType {
095:
096: /**
097: *
098: */
099: private static final long serialVersionUID = -2943128923230930885L;
100:
101: private static ILogger LOG = LoggerFactory
102: .getLogger(ExecuteRequest.class);
103:
104: private static NamespaceContext nsContext = CommonNamespaces
105: .getNamespaceContext();
106:
107: /**
108: * @param version
109: * @param id
110: * @param vendorSpecificParameter
111: * @param inputs
112: * @param identifier
113: * @param definitions
114: * @param status
115: * @param store
116: */
117: public ExecuteRequest(String version, String id,
118: Map<String, String> vendorSpecificParameter,
119: ExecuteDataInputs inputs, Code identifier,
120: OutputDefinitions definitions, boolean status, boolean store) {
121: super (version, id, vendorSpecificParameter);
122:
123: dataInputs = inputs;
124: this .identifier = identifier;
125: outputDefinitions = definitions;
126: this .status = status;
127: this .store = store;
128: }
129:
130: /**
131: * Identifier of the Process to be executed. This Process identifier shall be as listed in the
132: * ProcessOfferings section of the WPS Capabilities document.
133: */
134: protected Code identifier;
135:
136: /**
137: * List of input (or parameter) values provided to the process, including each of the Inputs
138: * needed to execute the process. It is possible to have no inputs provided only when all the
139: * inputs are predetermined fixed resources. In all other cases, at least one input is required.
140: */
141: protected ExecuteDataInputs dataInputs;
142:
143: /**
144: * List of definitions of the outputs (or parameters) requested from the process. These outputs
145: * are not normally identified, unless the client is specifically requesting a limited subset of
146: * outputs, and/or is requesting output formats and/or schemas and/or encodings different from
147: * the defaults and selected from the alternatives identified in the process description, or
148: * wishes to customize the descriptive information about the output.
149: */
150: protected OutputDefinitions outputDefinitions;
151:
152: /**
153: * Specifies if the Execute operation response shall be returned quickly with status
154: * information, or not returned until process execution is complete. This parameter shall not be
155: * included unless the corresponding "statusSupported" parameter is included and is "true" in
156: * the ProcessDescription for this process.
157: */
158: protected boolean status;
159:
160: /**
161: * Specifies if the complex valued output(s) of this process should be stored by the process as
162: * web-accessible resources. If store is "true", the server shall store all the complex valued
163: * output(s) of the process so that the client can retrieve them as required. If store is
164: * "false", all the complex valued output(s) shall be encoded in the Execute operation response.
165: * This parameter shall not be included unless the corresponding "storeSupported" parameter is
166: * included and is "true" in the ProcessDescription for this process.
167: */
168: protected boolean store;
169:
170: /**
171: * @return Returns the identifier.
172: */
173: public Code getIdentifier() {
174: return identifier;
175: }
176:
177: /**
178: * @return Returns the dataInputs.
179: */
180: public ExecuteDataInputs getDataInputs() {
181: return dataInputs;
182: }
183:
184: /**
185: * @return Returns the outputDefinitions.
186: */
187: public OutputDefinitions getOutputDefinitions() {
188: return outputDefinitions;
189: }
190:
191: /**
192: * @return
193: */
194: public boolean isStatus() {
195: return status;
196: }
197:
198: /**
199: * @return
200: */
201: public boolean isStore() {
202: return store;
203: }
204:
205: /**
206: *
207: * KVP-encoded transfer of the execute operation request is not supported.
208: *
209: * @see "OGC 05-007r4 Subclause 10.2.2"
210: * @param map
211: * @return
212: * @throws OGCWebServiceException
213: *
214: */
215: public static ExecuteRequest create(Map map)
216: throws OGCWebServiceException {
217: String msg = "KVP-encoded transfer of the execute operation request is not supported.";
218: LOG.logError(msg);
219: throw new OperationNotSupportedException(msg);
220: }
221:
222: /**
223: *
224: * @param id
225: * @param executeNode
226: * @return
227: * @throws OGCWebServiceException
228: * @throws MissingParameterValueException
229: * @throws InvalidParameterValueException
230: */
231: public static ExecuteRequest create(String id, Element executeNode)
232: throws OGCWebServiceException,
233: MissingParameterValueException,
234: InvalidParameterValueException {
235:
236: // get attribute version from <wps:Execute> Node
237: String version = getVersion(executeNode);
238:
239: // get attribute status from <wps:Execute> Node
240: boolean status = getStatus(executeNode);
241:
242: // get attribute store from <wps:Execute> Node
243: boolean store = getStore(executeNode);
244:
245: Map<String, String> vendorSpecificParameters = null;
246:
247: // get <ows:Identifier> from <wps:Execute> Node
248: Code identifier = getIdentifier(executeNode);
249:
250: // get <wps:DataInputs> from <wps:Execute> Node
251: ExecuteDataInputs dataInputs = getDataInputs(executeNode);
252:
253: // get <wps:OutputDefinitions> from <wps:Execute> Node
254: OutputDefinitions outputDefinitions = getOutputDefinitions(executeNode);
255:
256: return new ExecuteRequest(version, id,
257: vendorSpecificParameters, dataInputs, identifier,
258: outputDefinitions, status, store);
259: }
260:
261: /**
262: *
263: * @param executeNode
264: * @return version
265: * @throws InvalidParameterValueException
266: * @throws MissingParameterValueException
267: */
268: private static final String getVersion(Element executeNode)
269: throws InvalidParameterValueException,
270: MissingParameterValueException {
271: String version = null;
272: try {
273: version = XMLTools.getRequiredAttrValue("version", null,
274: executeNode);
275: } catch (XMLParsingException xmlex) {
276: String msg = "Operation Request does not include parameter value and this server did not declare a default value for that parameter.";
277: LOG.logDebug(msg);
278: throw new MissingParameterValueException("Version", msg);
279: }
280: if ("".equals(version)) {
281: String msg = "Operation Request contains an invalid parameter value";
282: LOG.logDebug(msg);
283: throw new InvalidParameterValueException("Version", msg);
284: }
285: if (!supportedVersion.equals(version)) {
286: String msg = "Operation Request contains an invalid parameter value";
287: LOG.logDebug(msg);
288: throw new InvalidParameterValueException("Version", msg);
289: }
290: return version;
291: }
292:
293: /**
294: *
295: * @param executeNode
296: * @return status
297: * @throws InvalidParameterValueException
298: */
299: private static final boolean getStatus(Element executeNode)
300: throws InvalidParameterValueException {
301: boolean status = false;
302: String statusString = XMLTools.getAttrValue(executeNode, null,
303: "status", null);
304: if (null != statusString) {
305: if ("true".equalsIgnoreCase(statusString)
306: || "false".equalsIgnoreCase(statusString)) {
307: status = new Boolean(statusString);
308: } else {
309: String msg = "Operation Request contains an invalid parameter value";
310: LOG.logDebug(msg);
311: throw new InvalidParameterValueException("status", msg);
312: }
313: }
314: return status;
315: }
316:
317: /**
318: *
319: * @param executeNode
320: * @return store
321: * @throws InvalidParameterValueException
322: */
323: private static final boolean getStore(Element executeNode)
324: throws InvalidParameterValueException {
325: boolean store = false;
326: String storeString = XMLTools.getAttrValue(executeNode, null,
327: "store", null);
328: if (null != storeString) {
329: if ("true".equalsIgnoreCase(storeString)
330: || "false".equalsIgnoreCase(storeString)) {
331: store = new Boolean(storeString);
332: } else {
333: String msg = "Operation Request contains an invalid parameter value";
334: LOG.logDebug(msg);
335: throw new InvalidParameterValueException("store", msg);
336: }
337: }
338: return store;
339: }
340:
341: /**
342: *
343: * @param e
344: * @return identifier
345: * @throws InvalidParameterValueException
346: * @throws MissingParameterValueException
347: */
348: private static Code getIdentifier(Element e)
349: throws InvalidParameterValueException,
350: MissingParameterValueException {
351: // Get required node <ows:Identifier>
352: String identifierAsString = null;
353:
354: try {
355: identifierAsString = XMLTools.getRequiredNodeAsString(e,
356: "ows:Identifier/text()", nsContext);
357: } catch (XMLParsingException ex) {
358: String msg = "Operation Request does not include parameter value and this server did not declare a default value for that parameter.";
359: LOG.logDebug(msg);
360: throw new MissingParameterValueException("Identifier", msg);
361: }
362:
363: if ("".equals(identifierAsString)) {
364: String msg = "Operation Request contains an invalid parameter value";
365: LOG.logDebug(msg);
366: throw new InvalidParameterValueException("Identifier", msg);
367: }
368: return new Code(identifierAsString, null);
369: }
370:
371: /**
372: *
373: * @param executeNode
374: * @return dataInputs
375: * @throws MissingParameterValueException
376: * @throws InvalidParameterValueException
377: */
378: @SuppressWarnings("unchecked")
379: private static ExecuteDataInputs getDataInputs(Element executeNode)
380: throws MissingParameterValueException,
381: InvalidParameterValueException {
382: // Get optional node <DataInputs>
383: ExecuteDataInputs dataInputs = null;
384: try {
385: Element dataInputsNode = (Element) XMLTools.getNode(
386: executeNode, "wps:DataInputs", nsContext);
387:
388: // dataInputsNode may be null, if not null, at least one <Input> has
389: // to be defined
390: if (null != dataInputsNode) {
391: LOG.logInfo("DataInputs: " + dataInputsNode);
392: List dataInputNodeList = XMLTools.getNodes(
393: dataInputsNode, "wps:Input", nsContext);
394:
395: if (null != dataInputNodeList
396: && 0 != dataInputNodeList.size()) {
397: dataInputs = new ExecuteDataInputs();
398: int size = dataInputNodeList.size();
399: HashMap inputs = new HashMap<String, IOValue>(size);
400: for (int i = 0; i < size; i++) {
401: IOValue ioValue = getIOValue((Element) dataInputNodeList
402: .get(i));
403:
404: inputs.put(ioValue.getIdentifier().getCode(),
405: ioValue);
406: }
407: dataInputs.setInputs(inputs);
408: } else {
409: throw new MissingParameterValueException("Input",
410: "If DataInputs node provided, at least one input node has to be defined.");
411: }
412: }
413: } catch (XMLParsingException ex) {
414: String msg = "Optional node DataInputs not declared";
415: LOG.logDebug(msg);
416: }
417:
418: return dataInputs;
419: }
420:
421: /**
422: *
423: * @param inputNode
424: * @return IOValue
425: * @throws InvalidParameterValueException
426: * @throws MissingParameterValueException
427: */
428: private static IOValue getIOValue(Element inputNode)
429: throws InvalidParameterValueException,
430: MissingParameterValueException {
431: Code identifier = getIdentifier(inputNode);
432: String title = getTitle(inputNode);
433: String _abstract = getAbstract(inputNode);
434: Envelope boundingBox = getBoundingBox(inputNode);
435: ComplexValue complexValue = getComplexValue(inputNode);
436: ComplexValueReference complexValueReference = getValueReference(inputNode);
437: TypedLiteral literalValue = getLiteralValue(inputNode);
438:
439: return new IOValue(identifier, title, _abstract, boundingBox,
440: complexValue, complexValueReference, literalValue);
441: }
442:
443: /**
444: *
445: * @param e
446: * @return title
447: * @throws MissingParameterValueException
448: * @throws InvalidParameterValueException
449: */
450: private static String getTitle(Element e)
451: throws MissingParameterValueException,
452: InvalidParameterValueException {
453: String title;
454: try {
455: title = XMLTools.getRequiredNodeAsString(e,
456: "ows:Title/text()", nsContext);
457: } catch (XMLParsingException ex) {
458: String msg = "Operation Request does not include parameter value and this server did not declare a default value for that parameter.";
459: throw new MissingParameterValueException("Title", msg);
460: }
461:
462: if ("".equals(title)) {
463: throw new InvalidParameterValueException("Title",
464: "Operation Request contains an invalid parameter Value");
465: }
466: return title;
467: }
468:
469: /**
470: *
471: * @param e
472: * @return abstact
473: */
474: private static String getAbstract(Element e) {
475: String _abstract = null;
476: try {
477: _abstract = XMLTools.getNodeAsString(e,
478: "ows:Abstract/text()", nsContext, null);
479: } catch (XMLParsingException ex) {
480: // optional Node
481: }
482: return _abstract;
483: }
484:
485: /**
486: *
487: * @param e
488: * @return boundingBox
489: * @throws MissingParameterValueException
490: * @throws InvalidParameterValueException
491: */
492: private static Envelope getBoundingBox(Element e)
493: throws MissingParameterValueException,
494: InvalidParameterValueException {
495: Envelope boundingBox = null;
496:
497: try {
498: Element boundingBoxValueNode = (Element) XMLTools.getNode(
499: e, "wps:BoundingBoxValue", nsContext);
500:
501: if (null != boundingBoxValueNode) {
502: double minX = 0;
503: double minY = 0;
504: double maxX = 0;
505: double maxY = 0;
506: String crsName = null;
507: String crs = null;
508: try {
509: crs = XMLTools.getRequiredNodeAsString(
510: boundingBoxValueNode, "@crs", nsContext);
511: String lowerCornerValue = XMLTools
512: .getRequiredNodeAsString(
513: boundingBoxValueNode,
514: "ows:LowerCorner/text()", nsContext);
515: String[] lowerCornerValues = lowerCornerValue
516: .split(" ");
517: if (lowerCornerValues.length != 2) {
518: throw new InvalidParameterValueException(
519: "lowerCornerNode",
520: "Two parameters are mandatory.");
521: }
522: minX = Double.parseDouble(lowerCornerValues[0]);
523: minY = Double.parseDouble(lowerCornerValues[1]);
524: } catch (XMLParsingException ex) {
525: throw new MissingParameterValueException(
526: "LowerCornerNode",
527: "Operation Request does not include "
528: + "parameter value and this server did "
529: + "not declare a default value for that "
530: + "parameter.");
531: }
532: try {
533: String upperCornerValue = XMLTools
534: .getRequiredNodeAsString(
535: boundingBoxValueNode,
536: "ows:UpperCorner/text()", nsContext);
537: String[] upperCornerValues = upperCornerValue
538: .split(" ");
539: if (upperCornerValues.length != 2) {
540: throw new InvalidParameterValueException(
541: "upperCornerNode",
542: "Two parameters are mandatory.");
543: }
544: maxX = Double.parseDouble(upperCornerValues[0]);
545: maxY = Double.parseDouble(upperCornerValues[1]);
546: } catch (XMLParsingException ex) {
547: throw new MissingParameterValueException(
548: "LowerCornerNode",
549: "Operation Request does not include parameter value and this server did not declare a default value for that parameter.");
550: }
551:
552: crsName = crs.substring(16);
553:
554: CoordinateSystem cs;
555: try {
556: cs = CRSFactory.create(crsName);
557: } catch (UnknownCRSException e1) {
558: throw new InvalidParameterValueException(
559: ExecuteRequest.class.getName(), e1
560: .getMessage());
561: }
562:
563: boundingBox = GeometryFactory.createEnvelope(minX,
564: minY, maxX, maxY, cs);
565: }
566: } catch (XMLParsingException ex) {
567: // optionalNode
568: }
569: return boundingBox;
570: }
571:
572: /**
573: *
574: * @param e
575: * @return complexValue
576: * @throws MissingParameterValueException
577: * @throws InvalidParameterValueException
578: */
579: private static ComplexValue getComplexValue(Element e)
580: throws InvalidParameterValueException {
581: ComplexValue complexValue = null;
582:
583: try {
584: Element complexValueNode = (Element) XMLTools.getNode(e,
585: "wps:ComplexValue", nsContext);
586: if (null != complexValueNode) {
587: String format = null;
588: URI encoding = null;
589: URL schema = null;
590: Object value = null;
591: try {
592:
593: format = complexValueNode.getAttribute("format");
594: if (null != format) {
595: if ("".equals(format)) {
596: throw new InvalidParameterValueException(
597: "ComplexValue",
598: "Attribute format must not be empty if provided.");
599:
600: }
601: }
602: String enc = complexValueNode
603: .getAttribute("encoding");
604: if (null != enc) {
605: if ("".equals(enc)) {
606: throw new InvalidParameterValueException(
607: "ComplexValue",
608: "Attribute encoding must not be empty if provided.");
609: }
610: encoding = new URI(enc);
611: }
612:
613: String scheme = complexValueNode
614: .getAttribute("schema");
615: if (null != scheme) {
616: if ("".equals(scheme)) {
617: throw new InvalidParameterValueException(
618: "ComplexValue",
619: "Attribute schema must not be empty if provided.");
620: }
621: schema = new URL(scheme);
622: }
623:
624: /**
625: * FIXME complexValue may contain any type of data specified by the attributes
626: * format, encoding and schema dynamically extract the content of this node
627: * according to specified format, encoding , schema
628: *
629: * @see OGC05-007r4 Table 35. At the moment only a GML FeatureCollection is
630: * supported.
631: *
632: * does using xmlfragment make more sense??
633: */
634: Element complexValueContent = XMLTools
635: .getFirstChildElement(complexValueNode);
636: if (null != complexValueContent) {
637: try {
638:
639: GMLFeatureCollectionDocument gmlFeatureCollectionDoc = new GMLFeatureCollectionDocument();
640: gmlFeatureCollectionDoc
641: .setRootElement(complexValueContent);
642: value = gmlFeatureCollectionDoc.parse();
643:
644: } catch (XMLParsingException ex1) {
645: LOG
646: .logInfo("Provided content cannot be parsed as featurecollection");
647: }
648: }
649:
650: } catch (URISyntaxException uriEx) {
651: throw new InvalidParameterValueException(
652: "ComplexValue",
653: "Operation Request contains an invalid parameter Value");
654: } catch (MalformedURLException mue) {
655: throw new InvalidParameterValueException(
656: "ComplexValue",
657: "Operation Request contains an invalid parameter Value");
658: }
659:
660: complexValue = new ComplexValue(format, encoding,
661: schema, value);
662: }
663:
664: } catch (XMLParsingException ex) {
665: // optionalNode
666: }
667:
668: return complexValue;
669:
670: }
671:
672: /**
673: *
674: * @param e
675: * @return complexValueReference
676: * @throws InvalidParameterValueException
677: * @throws MissingParameterValueException
678: */
679: private static ComplexValueReference getValueReference(Element e)
680: throws InvalidParameterValueException {
681: ComplexValueReference complexValueReference = null;
682:
683: Element complexValueReferenceNode;
684: try {
685: complexValueReferenceNode = (Element) XMLTools.getNode(e,
686: "wps:ComplexValueReference", nsContext);
687:
688: if (null != complexValueReferenceNode) {
689: String format = null;
690: URI encoding = null;
691: URL schema = null;
692: URL reference = null;
693:
694: format = complexValueReferenceNode
695: .getAttribute("format");
696: if (null != format) {
697: if ("".equals(format)) {
698: throw new InvalidParameterValueException(
699: "ComplexValueReference",
700: "Attribute format must not be empty if provided.");
701: }
702: }
703:
704: String enc = complexValueReferenceNode
705: .getAttribute("encoding");
706: if (null != enc) {
707: if ("".equals(enc)) {
708: throw new InvalidParameterValueException(
709: "ComplexValueReference",
710: "Attribute encoding must not be empty if provided.");
711: }
712: try {
713: encoding = new URI(enc);
714: } catch (URISyntaxException e1) {
715: throw new InvalidParameterValueException(
716: "ComplexValueReference",
717: "Provided content of attribute encoding could not be parsed as URI.");
718: }
719: }
720:
721: String scheme = complexValueReferenceNode
722: .getAttribute("schema");
723: if (null != scheme) {
724: if ("".equals(scheme)) {
725: throw new InvalidParameterValueException(
726: "ComplexValueReference",
727: "Attribute schema must not be empty if provided.");
728: }
729: try {
730: schema = new URL(scheme);
731: } catch (MalformedURLException e1) {
732: throw new InvalidParameterValueException(
733: "ComplexValueReference",
734: "Provided content of attribute schema could not be parsed as URL.");
735: }
736: }
737:
738: String referenceString = complexValueReferenceNode
739: .getAttributeNS(OWSNS.toString(), "reference");
740: if ("".equals(referenceString)) {
741: throw new InvalidParameterValueException(
742: "ComplexValueReference",
743: "Mandatory attibute reference must not be empty.");
744: }
745: try {
746: reference = new URL(referenceString);
747: } catch (MalformedURLException e1) {
748: throw new InvalidParameterValueException(
749: "ComplexValueReference",
750: "Provided content of attribute reference could not be parsed as URL.");
751:
752: }
753:
754: complexValueReference = new IOValue.ComplexValueReference(
755: format, encoding, schema, reference);
756: }
757: } catch (XMLParsingException e1) {
758: // optional element
759: }
760:
761: return complexValueReference;
762: }
763:
764: /**
765: *
766: * @param e
767: * @return literalValue
768: * @throws InvalidParameterValueException
769: */
770: private static TypedLiteral getLiteralValue(Element e)
771: throws InvalidParameterValueException {
772: TypedLiteral literalValue = null;
773:
774: Element literalValueNode;
775: try {
776: literalValueNode = (Element) XMLTools.getNode(e,
777: "wps:LiteralValue", nsContext);
778: if (null != literalValueNode) {
779: String value = null;
780: URI dataType = null;
781: URI uom = null;
782: String dataTypeString = literalValueNode
783: .getAttribute("dataType");
784: if (null != dataTypeString) {
785: if ("".equals(dataTypeString)) {
786: throw new InvalidParameterValueException(
787: "LiteralValue",
788: "Attribute data type must not be empty if provided.");
789: }
790: try {
791: dataType = new URI(dataTypeString);
792: } catch (URISyntaxException e1) {
793: throw new InvalidParameterValueException(
794: "LiteralValue",
795: "Provided content of attribute data type could not be parsed as URI.");
796: }
797: }
798:
799: String uomString = literalValueNode.getAttribute("uom");
800: if (null != uomString) {
801: if ("".equals(uomString)) {
802: throw new InvalidParameterValueException(
803: "LiteralValue",
804: "Attribute uom must not be empty if provided.");
805: }
806: }
807: try {
808: uom = new URI(uomString);
809: } catch (URISyntaxException e1) {
810: throw new InvalidParameterValueException(
811: "LiteralValue",
812: "Provided content of attribute uom could not be parsed as URI.");
813: }
814: value = XMLTools.getNodeAsString(literalValueNode,
815: "/text()", nsContext, null);
816:
817: literalValue = new TypedLiteral(value, dataType, uom);
818: }
819:
820: } catch (XMLParsingException e1) {
821: // optional Element
822: }
823:
824: return literalValue;
825: }
826:
827: /**
828: *
829: * @param executeNode
830: * @return outputDefinitions
831: * @throws MissingParameterValueException
832: * @throws InvalidParameterValueException
833: */
834: @SuppressWarnings("unchecked")
835: private static OutputDefinitions getOutputDefinitions(
836: Element executeNode) throws MissingParameterValueException,
837: InvalidParameterValueException {
838: OutputDefinitions outputDefinitions = null;
839:
840: try {
841: Element outputDefinitionsNode = (Element) XMLTools.getNode(
842: executeNode, "wps:OutputDefinitions", nsContext);
843:
844: if (null != outputDefinitionsNode) {
845:
846: // outputDefinitionsNode may be null, if not null, at least one
847: // <Input> has
848: // to be defined
849: if (null != outputDefinitionsNode) {
850: LOG.logInfo("outputDefinitionsNode: "
851: + outputDefinitionsNode);
852: List outputNodeList = XMLTools.getNodes(
853: outputDefinitionsNode, "wps:Output",
854: nsContext);
855:
856: if (null != outputNodeList
857: && 0 != outputNodeList.size()) {
858: outputDefinitions = new OutputDefinitions();
859: int size = outputNodeList.size();
860: List outputs = new ArrayList<OutputDefinition>(
861: size);
862: for (int i = 0; i < size; i++) {
863: outputs
864: .add(
865: i,
866: getOutputDefinition((Element) outputNodeList
867: .get(i)));
868: }
869:
870: outputDefinitions.setOutputDefinitions(outputs);
871: } else {
872: throw new MissingParameterValueException(
873: "Output",
874: "If OutputDefinitions node provided, at least one output node has to be defined.");
875: }
876: }
877: }
878:
879: } catch (XMLParsingException ex) {
880: // Optional element
881: }
882:
883: return outputDefinitions;
884: }
885:
886: /**
887: *
888: * @param outputNode
889: * @return outputDefinitions
890: * @throws InvalidParameterValueException
891: * @throws MissingParameterValueException
892: */
893: private static OutputDefinition getOutputDefinition(
894: Element outputNode) throws InvalidParameterValueException,
895: MissingParameterValueException {
896:
897: Code identifier = getIdentifier(outputNode);
898: String title = getTitle(outputNode);
899: String _abstract = getAbstract(outputNode);
900: String format = null;
901: URI encoding = null;
902: URL schema = null;
903: URI uom = null;
904:
905: format = outputNode.getAttribute("format");
906: if (null != format) {
907: if ("".equals(format)) {
908: throw new InvalidParameterValueException("Output",
909: "Attribute format must not be empty if provided.");
910: }
911: }
912:
913: String enc = outputNode.getAttribute("encoding");
914: if (null != enc) {
915: if ("".equals(enc)) {
916: throw new InvalidParameterValueException("Output",
917: "Attribute encoding must not be empty if provided.");
918: }
919: try {
920: encoding = new URI(enc);
921: } catch (URISyntaxException e1) {
922: throw new InvalidParameterValueException("Output",
923: "Provided content of attribute encoding could not be parsed as URI.");
924: }
925: }
926:
927: String scheme = outputNode.getAttribute("schema");
928: if (null != scheme) {
929: if ("".equals(scheme)) {
930: throw new InvalidParameterValueException("Output",
931: "Attribute schema must not be empty if provided.");
932: }
933: try {
934: schema = new URL(scheme);
935: } catch (MalformedURLException e1) {
936: throw new InvalidParameterValueException("Output",
937: "Provided content of attribute schema could not be parsed as URL.");
938: }
939: }
940:
941: String uomString = outputNode.getAttribute("uom");
942: if (null != uomString) {
943: if ("".equals(uomString)) {
944: throw new InvalidParameterValueException("Output",
945: "Attribute uom must not be empty if provided.");
946: }
947: }
948: try {
949: uom = new URI(uomString);
950: } catch (URISyntaxException e1) {
951: throw new InvalidParameterValueException("Output",
952: "Provided content of attribute uom could not be parsed as URI.");
953: }
954:
955: return new OutputDefinition(identifier, title, _abstract,
956: encoding, format, schema, uom);
957: }
958:
959: }
|