001: // $HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/wcs/describecoverage/CoverageDescriptionDocument.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/deegree/
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: Aennchenstr. 19
030: 53115 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.wcs.describecoverage;
045:
046: import java.io.IOException;
047: import java.net.MalformedURLException;
048: import java.net.URI;
049: import java.net.URISyntaxException;
050: import java.net.URL;
051:
052: import org.deegree.datatypes.Code;
053: import org.deegree.datatypes.CodeList;
054: import org.deegree.datatypes.time.TimeSequence;
055: import org.deegree.datatypes.values.Values;
056: import org.deegree.framework.util.StringTools;
057: import org.deegree.framework.xml.ElementList;
058: import org.deegree.framework.xml.XMLParsingException;
059: import org.deegree.framework.xml.XMLTools;
060: import org.deegree.model.crs.UnknownCRSException;
061: import org.deegree.model.metadata.iso19115.Keywords;
062: import org.deegree.model.spatialschema.Envelope;
063: import org.deegree.ogcbase.CommonNamespaces;
064: import org.deegree.ogcbase.GMLDocument;
065: import org.deegree.ogcbase.InvalidGMLException;
066: import org.deegree.ogcbase.OGCDocument;
067: import org.deegree.ogcbase.OGCException;
068: import org.deegree.ogcwebservices.LonLatEnvelope;
069: import org.deegree.ogcwebservices.MetadataLink;
070: import org.deegree.ogcwebservices.MetadataType;
071: import org.deegree.ogcwebservices.OGCWebServiceException;
072: import org.deegree.ogcwebservices.SupportedFormats;
073: import org.deegree.ogcwebservices.SupportedSRSs;
074: import org.deegree.ogcwebservices.wcs.InterpolationMethod;
075: import org.deegree.ogcwebservices.wcs.SupportedInterpolations;
076: import org.deegree.ogcwebservices.wcs.WCSException;
077: import org.deegree.ogcwebservices.wcs.configuration.Extension;
078: import org.deegree.ogcwebservices.wcs.configuration.ExtensionDocument;
079: import org.w3c.dom.Element;
080: import org.xml.sax.SAXException;
081:
082: /**
083: * <ul>
084: * <li> usage of srsName from gml:Envelope is not supoorted yet. deegree Envelope doesn't uses CRSs
085: * <li> gml:Grid and gml:Polygon is not yet supported by the deegree WCS
086: * </ul>
087: *
088: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
089: * @author last edited by: $Author: apoth $
090: *
091: * @version $Revision: 9345 $, $Date: 2007-12-27 08:22:25 -0800 (Thu, 27 Dec 2007) $
092: */
093: public class CoverageDescriptionDocument extends OGCDocument {
094:
095: public static final String XML_TEMPLATE = "CoverageDescriptionTemplate.xml";
096:
097: private static URI WCSNS = CommonNamespaces.WCSNS;
098:
099: private static URI GMLNS = CommonNamespaces.GMLNS;
100:
101: private static URI DGRNS = CommonNamespaces.DEEGREEWCS;
102:
103: /**
104: * @throws IOException
105: * @throws SAXException
106: * @see "org.deegree.framework.xml.XMLFragment#createEmptyDocument()"
107: */
108: public void createEmptyDocument() throws IOException, SAXException {
109: URL url = CoverageDescriptionDocument.class
110: .getResource(XML_TEMPLATE);
111: if (url == null) {
112: throw new IOException("The resource '" + XML_TEMPLATE
113: + " could not be found.");
114: }
115: load(url);
116: }
117:
118: /**
119: * returns the version of the CoverageDescription
120: *
121: * @return the version of the CoverageDescription
122: * @throws InvalidCoverageDescriptionExcpetion
123: */
124: public String getVersion()
125: throws InvalidCoverageDescriptionExcpetion {
126: try {
127: return XMLTools.getRequiredAttrValue("version", null,
128: getRootElement());
129: } catch (XMLParsingException e) {
130: String s = e.getMessage() + "\n"
131: + StringTools.stackTraceToString(e);
132: throw new InvalidCoverageDescriptionExcpetion(s);
133: }
134: }
135:
136: /**
137: * creates a <tt>CoverageDescription</tt> instance from the DOM document encapsulated by this
138: * class
139: *
140: * @return created <tt>CoverageDescription</tt> instance
141: * @throws InvalidCoverageDescriptionExcpetion
142: * @throws UnknownCRSException
143: */
144: public CoverageOffering[] getCoverageOfferings()
145: throws InvalidCoverageDescriptionExcpetion,
146: UnknownCRSException {
147:
148: try {
149: ElementList el = XMLTools.getChildElements(
150: "CoverageOffering", WCSNS, getRootElement());
151: CoverageOffering[] co = getCoverageOfferings(el);
152: return co;
153: } catch (XMLParsingException e) {
154: String s = e.getMessage() + "\n"
155: + StringTools.stackTraceToString(e);
156: throw new InvalidCoverageDescriptionExcpetion(s);
157: } catch (WCSException e) {
158: String s = e.getMessage() + "\n"
159: + StringTools.stackTraceToString(e);
160: throw new InvalidCoverageDescriptionExcpetion(s);
161: } catch (OGCException e) {
162: String s = e.getMessage() + "\n"
163: + StringTools.stackTraceToString(e);
164: throw new InvalidCoverageDescriptionExcpetion(s);
165: }
166:
167: }
168:
169: /**
170: * creates an array of <tt>CoverageOffering</tt> objects contained in the enclosing
171: * CoverageDescrption element.
172: *
173: * @param el
174: * list of CoverageOffering elements
175: * @return array of <tt>CoverageOffering</tt> objects
176: * @throws XMLParsingException
177: * @throws UnknownCRSException
178: */
179: private CoverageOffering[] getCoverageOfferings(ElementList el)
180: throws XMLParsingException, WCSException, OGCException,
181: UnknownCRSException {
182: CoverageOffering[] co = new CoverageOffering[el.getLength()];
183:
184: for (int i = 0; i < co.length; i++) {
185: co[i] = getCoverageOffering(el.item(i));
186: }
187:
188: return co;
189: }
190:
191: /**
192: * @param element
193: * @return
194: * @throws XMLParsingException
195: * @throws UnknownCRSException
196: */
197: private CoverageOffering getCoverageOffering(Element element)
198: throws XMLParsingException, WCSException, OGCException,
199: UnknownCRSException {
200:
201: String name = XMLTools.getRequiredStringValue("name", WCSNS,
202: element);
203: String label = XMLTools.getStringValue("label", WCSNS, element,
204: name);
205: String desc = XMLTools.getStringValue("description", WCSNS,
206: element, null);
207: Element elem = XMLTools.getChildElement("metadataLink", WCSNS,
208: element);
209: MetadataLink mLink = parseMetadataLink(elem);
210: elem = XMLTools.getRequiredChildElement("lonLatEnvelope",
211: WCSNS, element);
212: LonLatEnvelope lonLatEnvelope = parseLonLatEnvelope(elem);
213: ElementList el = XMLTools.getChildElements("keywords", WCSNS,
214: element);
215: Keywords[] keywords = parseKeywords(el, WCSNS);
216: elem = XMLTools.getRequiredChildElement("domainSet", WCSNS,
217: element);
218: DomainSet domainSet = getDomainSet(elem);
219: RangeSet rangeSet = null;
220: elem = XMLTools.getRequiredChildElement("rangeSet", WCSNS,
221: element);
222: if (elem != null) {
223: elem = XMLTools.getRequiredChildElement("RangeSet", WCSNS,
224: elem);
225: rangeSet = getRangeSet(elem);
226: }
227: elem = XMLTools.getRequiredChildElement("supportedCRSs", WCSNS,
228: element);
229: SupportedSRSs supportedCRSs = getSupportedCRSs(elem);
230: elem = XMLTools.getRequiredChildElement("supportedFormats",
231: WCSNS, element);
232: SupportedFormats supportedFormats = getSupportedFomarts(elem);
233: elem = XMLTools.getRequiredChildElement(
234: "supportedInterpolations", WCSNS, element);
235: SupportedInterpolations supInterpol = getSupportedInterpolations(elem);
236: elem = XMLTools.getRequiredChildElement("Extension", DGRNS,
237: element);
238:
239: ExtensionDocument eb = new ExtensionDocument(elem,
240: getSystemId());
241: Extension extension = eb.getExtension();
242:
243: return new CoverageOffering(name, label, desc, mLink,
244: lonLatEnvelope, keywords, domainSet, rangeSet,
245: supportedCRSs, supportedFormats, supInterpol, extension);
246: }
247:
248: /**
249: * creates a <tt>MetadataLink</tt> object from the passed element.
250: *
251: * @param element
252: * @return created <tt>MetadataLink</tt>
253: * @throws XMLParsingException
254: */
255: private MetadataLink parseMetadataLink(Element element)
256: throws XMLParsingException {
257: if (element == null)
258: return null;
259:
260: try {
261: URL reference = new URL(XMLTools.getAttrValue(element,
262: "xlink:href"));
263: String title = XMLTools
264: .getAttrValue(element, "xlink:title");
265: URI about = new URI(XMLTools.getAttrValue(element, null,
266: "about", null));
267: String tmp = XMLTools.getAttrValue(element, null,
268: "metadataType", null);
269: MetadataType metadataType = new MetadataType(tmp);
270:
271: return new MetadataLink(reference, title, about,
272: metadataType);
273: } catch (MalformedURLException e) {
274: throw new XMLParsingException(
275: "Couldn't parse metadataLink reference\n"
276: + StringTools.stackTraceToString(e));
277: } catch (URISyntaxException e) {
278: throw new XMLParsingException(
279: "Couldn't parse metadataLink about\n"
280: + StringTools.stackTraceToString(e));
281: }
282: }
283:
284: /**
285: * creates a <tt>DomainSet</tt> from the passed element. Not all possible sub elements are
286: * supported at the moment by deegree (see class comment)
287: *
288: * @param element
289: * @return
290: * @throws XMLParsingException
291: * @throws InvalidCoverageDescriptionExcpetion
292: * @throws WCSException
293: * @throws UnknownCRSException
294: */
295: private DomainSet getDomainSet(Element element)
296: throws XMLParsingException,
297: InvalidCoverageDescriptionExcpetion, WCSException,
298: UnknownCRSException {
299: Element elem = XMLTools.getRequiredChildElement(
300: "spatialDomain", WCSNS, element);
301: SpatialDomain sd = getSpatialDomain(elem);
302: elem = XMLTools.getChildElement("temporalDomain", WCSNS,
303: element);
304: TimeSequence seq = null;
305: if (elem != null) {
306: try {
307: seq = parseTimeSequence(elem, WCSNS);
308: } catch (OGCWebServiceException e) {
309: String s = e.getMessage() + "\n"
310: + StringTools.stackTraceToString(e);
311: throw new InvalidCoverageDescriptionExcpetion(s);
312: }
313: }
314: return new DomainSet(sd, seq);
315: }
316:
317: /**
318: * creates a <tt>SpatialDomain</tt> object from the passe element. At the moment deegree
319: * doesn't support gml:Grid and gml:Polygon elements for defining a spatial domain of a
320: * coverage.
321: *
322: * @param element
323: * @return created <tt>SpatialDomain</tt>
324: * @throws XMLParsingException
325: * @throws InvalidCoverageDescriptionExcpetion
326: * @throws WCSException
327: * @throws UnknownCRSException
328: */
329: private SpatialDomain getSpatialDomain(Element element)
330: throws InvalidCoverageDescriptionExcpetion, WCSException,
331: UnknownCRSException {
332: if (XMLTools.getChildElement("Grid", GMLNS, element) != null) {
333: throw new InvalidCoverageDescriptionExcpetion(
334: "GML Grid for SpatialDomain is not "
335: + "supported by the deegree WCS yet.");
336: }
337: if (XMLTools.getChildElement("Polygon", GMLNS, element) != null) {
338: throw new InvalidCoverageDescriptionExcpetion(
339: "GML Polygon for SpatialDomain is not "
340: + "supported by the deegree WCS yet.");
341: }
342: ElementList el = XMLTools.getChildElements("Envelope", GMLNS,
343: element);
344: Envelope[] envelops = getEnvelopes(el);
345: return new SpatialDomain(envelops);
346: }
347:
348: /**
349: * creates an array of <tt>Envelope</tt>s from the passed element list
350: *
351: * @param el
352: * @return created array of <tt>Envelope</tt>s
353: * @throws XMLParsingException
354: * @throws InvalidCoverageDescriptionExcpetion
355: * @throws UnknownCRSException
356: */
357: private Envelope[] getEnvelopes(ElementList el)
358: throws InvalidCoverageDescriptionExcpetion,
359: UnknownCRSException {
360: if (el.getLength() == 0) {
361: throw new InvalidCoverageDescriptionExcpetion(
362: "at least one envelope must be"
363: + "defined in a spatialDomain");
364: }
365: Envelope[] envelopes = new Envelope[el.getLength()];
366: for (int i = 0; i < envelopes.length; i++) {
367: try {
368: envelopes[i] = GMLDocument.parseEnvelope(el.item(i));
369: } catch (InvalidGMLException e) {
370: String s = e.getMessage() + "\n"
371: + StringTools.stackTraceToString(e);
372: throw new InvalidCoverageDescriptionExcpetion(s);
373: }
374: }
375: return envelopes;
376: }
377:
378: /**
379: * creates a <tt>RangeSet</tt> object from the passed element
380: *
381: * @param element
382: * @return created <tt>RangeSet</tt>
383: * @throws XMLParsingException
384: * @throws WCSException
385: * @throws OGCException
386: */
387: private RangeSet getRangeSet(Element element)
388: throws XMLParsingException, WCSException, OGCException {
389: try {
390: String name = XMLTools.getRequiredStringValue("name",
391: WCSNS, element);
392: String label = XMLTools.getStringValue("label", WCSNS,
393: element, name);
394: String desc = XMLTools.getStringValue("description", WCSNS,
395: element, null);
396: Element elem = XMLTools.getChildElement("metadataLink",
397: WCSNS, element);
398: MetadataLink mLink = parseMetadataLink(elem);
399: String tmp = XMLTools.getAttrValue(element, null,
400: "semantic", null);
401: URI semantic = null;
402: if (tmp != null) {
403: semantic = new URI(tmp);
404: }
405:
406: tmp = XMLTools.getAttrValue(element, null, "refSys", null);
407: URI refSys = null;
408: if (tmp != null) {
409: refSys = new URI(tmp);
410: }
411:
412: String refSysLabel = XMLTools.getAttrValue(element, null,
413: "refSysLabel", null);
414:
415: AxisDescription[] axisDescription = null;
416: ElementList el = XMLTools.getChildElements(
417: "axisDescription", WCSNS, element);
418: if (elem != null) {
419: elem = XMLTools.getChildElement("AxisDescription",
420: WCSNS, element);
421: axisDescription = getAxisDescriptions(el);
422: }
423: elem = XMLTools.getChildElement("nullValues", WCSNS,
424: element);
425: Values nullValues = parseValues(elem, WCSNS);
426: return new RangeSet(name, label, desc, mLink, semantic,
427: refSys, refSysLabel, nullValues, axisDescription);
428: } catch (URISyntaxException e) {
429: throw new XMLParsingException(
430: "couldn't parse URI from typedLiteral\n"
431: + StringTools.stackTraceToString(e));
432: }
433:
434: }
435:
436: /**
437: * creates an array of <tt>AxisDescription</tt>s from the passed element list
438: *
439: * @param el
440: * @return created array of <tt>AxisDescription</tt>s
441: * @throws XMLParsingException
442: * @throws WCSException
443: * @throws OGCException
444: */
445: private AxisDescription[] getAxisDescriptions(ElementList el)
446: throws XMLParsingException, WCSException, OGCException {
447: AxisDescription[] ad = new AxisDescription[el.getLength()];
448: for (int i = 0; i < ad.length; i++) {
449: Element elem = XMLTools.getRequiredChildElement(
450: "AxisDescription", WCSNS, el.item(i));
451: ad[i] = getAxisDescription(elem);
452: }
453: return ad;
454: }
455:
456: /**
457: * creates an <tt>AxisDescription</tt> object from the passed element
458: *
459: * @param element
460: * @return created <tt>AxisDescription</tt>
461: * @throws XMLParsingException
462: * @throws WCSException
463: * @throws OGCException
464: */
465: private AxisDescription getAxisDescription(Element element)
466: throws XMLParsingException, WCSException, OGCException {
467: try {
468: String tmp = XMLTools.getAttrValue(element, null,
469: "semantic", null);
470: URI semantic = null;
471: if (tmp != null) {
472: semantic = new URI(tmp);
473: }
474:
475: tmp = XMLTools.getAttrValue(element, null, "refSys", null);
476: URI refSys = null;
477: if (tmp != null) {
478: refSys = new URI(tmp);
479: }
480:
481: String refSysLabel = XMLTools.getAttrValue(element, null,
482: "refSysLabel", null);
483:
484: String name = XMLTools.getRequiredStringValue("name",
485: WCSNS, element);
486: String label = XMLTools.getStringValue("label", WCSNS,
487: element, name);
488: String desc = XMLTools.getStringValue("description", WCSNS,
489: element, null);
490: Element elem = XMLTools.getChildElement("metadataLink",
491: WCSNS, element);
492: MetadataLink mLink = parseMetadataLink(elem);
493: elem = XMLTools.getRequiredChildElement("values", WCSNS,
494: element);
495: Values values = parseValues(elem, WCSNS);
496: return new AxisDescription(name, label, desc, mLink,
497: semantic, refSys, refSysLabel, values);
498: } catch (URISyntaxException e) {
499: throw new XMLParsingException(
500: "couldn't parse URI from AxisDescription\n"
501: + StringTools.stackTraceToString(e));
502: }
503: }
504:
505: /**
506: * creates a <tt>SupportedSRSs</tt> object from the passed element
507: *
508: * @param element
509: * @return created <tt>SupportedSRSs</tt>
510: * @throws XMLParsingException
511: */
512: private SupportedSRSs getSupportedCRSs(Element element)
513: throws XMLParsingException {
514: ElementList el = XMLTools.getChildElements(
515: "requestResponseCRSs", WCSNS, element);
516: CodeList[] requestResponseCRSs = parseCodeListArray(el);
517: el = XMLTools.getChildElements("requestCRSs", WCSNS, element);
518: CodeList[] requestCRSs = parseCodeListArray(el);
519: el = XMLTools.getChildElements("responseCRSs", WCSNS, element);
520: CodeList[] responseCRSs = parseCodeListArray(el);
521: el = XMLTools.getChildElements("nativeCRSs", WCSNS, element);
522: CodeList[] nativeCRSs = parseCodeListArray(el);
523: return new SupportedSRSs(requestResponseCRSs, requestCRSs,
524: responseCRSs, nativeCRSs);
525: }
526:
527: /**
528: * creates a <tt>SupportedFormats</tt> object from the passed element
529: *
530: * @param element
531: * @return
532: * @throws XMLParsingException
533: */
534: private SupportedFormats getSupportedFomarts(Element element)
535: throws XMLParsingException {
536: String nativeFormat = XMLTools.getAttrValue(element, null,
537: "nativeFormat", null);
538: ElementList el = XMLTools.getChildElements("formats", WCSNS,
539: element);
540: CodeList[] formats = parseCodeListArray(el);
541: Code nativeF = new Code(nativeFormat);
542: return new SupportedFormats(formats, nativeF);
543: }
544:
545: /**
546: * creates a <tt>SupportedInterpolations<tt> object from the passed element
547: * @param element
548: * @return created <tt>SupportedInterpolations<tt>
549: * @throws XMLParsingException
550: */
551: private SupportedInterpolations getSupportedInterpolations(
552: Element element) {
553: String tmp = XMLTools.getAttrValue(element, null, "default",
554: "nearest neighbor");
555: InterpolationMethod def = new InterpolationMethod(tmp);
556:
557: ElementList el = XMLTools.getChildElements(
558: "interpolationMethod", WCSNS, element);
559: InterpolationMethod[] ims = new InterpolationMethod[el
560: .getLength()];
561: for (int i = 0; i < ims.length; i++) {
562: tmp = XMLTools.getStringValue(el.item(i));
563: ims[i] = new InterpolationMethod(tmp);
564: }
565: return new SupportedInterpolations(ims, def);
566: }
567:
568: }
|