001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/wps/capabilities/WPSCapabilitiesDocument.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:
045: package org.deegree.ogcwebservices.wps.capabilities;
046:
047: import static org.deegree.ogcwebservices.wps.capabilities.WPSOperationsMetadata.DESCRIBEPROCESS;
048: import static org.deegree.ogcwebservices.wps.capabilities.WPSOperationsMetadata.EXECUTE;
049:
050: import java.io.IOException;
051: import java.net.URL;
052: import java.util.HashMap;
053: import java.util.List;
054: import java.util.Map;
055:
056: import org.deegree.framework.log.ILogger;
057: import org.deegree.framework.log.LoggerFactory;
058: import org.deegree.framework.xml.XMLParsingException;
059: import org.deegree.framework.xml.XMLTools;
060: import org.deegree.ogcwebservices.getcapabilities.InvalidCapabilitiesException;
061: import org.deegree.ogcwebservices.getcapabilities.OGCCapabilities;
062: import org.deegree.ogcwebservices.getcapabilities.Operation;
063: import org.deegree.ogcwebservices.getcapabilities.OperationsMetadata;
064: import org.deegree.owscommon.OWSCommonCapabilitiesDocument;
065: import org.deegree.owscommon.OWSDomainType;
066: import org.w3c.dom.Element;
067: import org.w3c.dom.Node;
068: import org.xml.sax.SAXException;
069:
070: /**
071: * WPSCapabilitiesDocument.java
072: *
073: * Creates an object representation of the sample_wps_capabilities.xml document
074: *
075: * Created on 08.03.2006. 18:57:37h
076: *
077: * @author <a href="mailto:christian@kiehle.org">Christian Kiehle</a>
078: * @author <a href="mailto:christian.heier@gmx.de">Christian Heier</a>
079: *
080: * @version 1.0.
081: *
082: * @since 2.0
083: */
084: public class WPSCapabilitiesDocument extends
085: OWSCommonCapabilitiesDocument {
086:
087: /**
088: *
089: */
090: private static final long serialVersionUID = -4004369952171016830L;
091:
092: private static final ILogger LOG = LoggerFactory
093: .getLogger(WPSCapabilitiesDocument.class);
094:
095: private static final String XML_TEMPLATE = "WPSCapabilitiesTemplate.xml";
096:
097: /**
098: * @throws IOException
099: * @throws SAXException
100: */
101: public void createEmptyDocument() throws IOException, SAXException {
102: URL url = WPSCapabilitiesDocument.class
103: .getResource(XML_TEMPLATE);
104: if (null == url) {
105: throw new IOException("The resource '" + XML_TEMPLATE
106: + " ' could not be found");
107: }
108: load(url);
109: }
110:
111: /*
112: * (non-Javadoc)
113: *
114: * @see org.deegree.ogcwebservices.getcapabilities.OGCCapabilitiesDocument#parseCapabilities()
115: */
116: @Override
117: public OGCCapabilities parseCapabilities()
118: throws InvalidCapabilitiesException {
119: try {
120:
121: return new WPSCapabilities(parseVersion(),
122: parseUpdateSequence(), getServiceIdentification(),
123: getServiceProvider(), getOperationsMetadata(), null);
124: } catch (Exception e) {
125: LOG.logError(e.getMessage(), e);
126: throw new InvalidCapabilitiesException(e.getMessage());
127: }
128: }
129:
130: /**
131: * Creates an object representation of the <code>ows:OperationsMetadata</code> section.
132: *
133: * @return object representation of the <code>ows:OperationsMetadata</code> section
134: * @throws XMLParsingException
135: */
136: @SuppressWarnings("unchecked")
137: public OperationsMetadata getOperationsMetadata()
138: throws XMLParsingException {
139:
140: List operationElementList = XMLTools.getNodes(getRootElement(),
141: "ows:OperationsMetadata/ows:Operation", nsContext);
142:
143: // build HashMap of 'ows:Operation'-elements for easier access
144: Map operations = new HashMap();
145: for (int i = 0; i < operationElementList.size(); i++) {
146: operations.put(XMLTools.getRequiredNodeAsString(
147: (Node) operationElementList.get(i), "@name",
148: nsContext), operationElementList.get(i));
149: }
150:
151: Operation getCapabilities = getOperation(
152: OperationsMetadata.GET_CAPABILITIES_NAME, true,
153: operations);
154: Operation describeProcess = getOperation(DESCRIBEPROCESS, true,
155: operations);
156: Operation execute = getOperation(EXECUTE, true, operations);
157:
158: List parameterElementList = XMLTools.getNodes(getRootElement(),
159: "ows:OperationsMetadata/ows:Parameter", nsContext);
160: OWSDomainType[] parameters = new OWSDomainType[parameterElementList
161: .size()];
162: for (int i = 0; i < parameters.length; i++) {
163: parameters[i] = getOWSDomainType(null,
164: (Element) parameterElementList.get(i));
165: }
166:
167: List constraintElementList = XMLTools.getNodes(
168: getRootElement(),
169: "ows:OperationsMetadata/ows:Constraint", nsContext);
170: OWSDomainType[] constraints = new OWSDomainType[constraintElementList
171: .size()];
172: for (int i = 0; i < constraints.length; i++) {
173: constraints[i] = getOWSDomainType(null,
174: (Element) constraintElementList.get(i));
175: }
176: WPSOperationsMetadata metadata = new WPSOperationsMetadata(
177: getCapabilities, describeProcess, execute, parameters,
178: constraints);
179:
180: return metadata;
181: }
182:
183: }
|