001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/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 OWSCommonCapabilitiesDocument {
085
086 private static final ILogger LOG = LoggerFactory.getLogger( WPSCapabilitiesDocument.class );
087
088 private static final String XML_TEMPLATE = "WPSCapabilitiesTemplate.xml";
089
090 /**
091 * @throws IOException
092 * @throws SAXException
093 */
094 public void createEmptyDocument()
095 throws IOException, SAXException {
096 URL url = WPSCapabilitiesDocument.class.getResource( XML_TEMPLATE );
097 if ( null == url ) {
098 throw new IOException( "The resource '" + XML_TEMPLATE + " ' could not be found" );
099 }
100 load( url );
101 }
102
103 /*
104 * (non-Javadoc)
105 *
106 * @see org.deegree.ogcwebservices.getcapabilities.OGCCapabilitiesDocument#parseCapabilities()
107 */
108 @Override
109 public OGCCapabilities parseCapabilities()
110 throws InvalidCapabilitiesException {
111 try {
112
113 return new WPSCapabilities( parseVersion(), parseUpdateSequence(), getServiceIdentification(),
114 getServiceProvider(), getOperationsMetadata(), null );
115 } catch ( Exception e ) {
116 LOG.logError( e.getMessage(), e );
117 throw new InvalidCapabilitiesException( e.getMessage() );
118 }
119 }
120
121 /**
122 * Creates an object representation of the <code>ows:OperationsMetadata</code> section.
123 *
124 * @return object representation of the <code>ows:OperationsMetadata</code> section
125 * @throws XMLParsingException
126 */
127 @SuppressWarnings("unchecked")
128 public OperationsMetadata getOperationsMetadata()
129 throws XMLParsingException {
130
131 List operationElementList = XMLTools.getNodes( getRootElement(), "ows:OperationsMetadata/ows:Operation",
132 nsContext );
133
134 // build HashMap of 'ows:Operation'-elements for easier access
135 Map operations = new HashMap();
136 for ( int i = 0; i < operationElementList.size(); i++ ) {
137 operations.put(
138 XMLTools.getRequiredNodeAsString( (Node) operationElementList.get( i ), "@name", nsContext ),
139 operationElementList.get( i ) );
140 }
141
142 Operation getCapabilities = getOperation( OperationsMetadata.GET_CAPABILITIES_NAME, true, operations );
143 Operation describeProcess = getOperation( DESCRIBEPROCESS, true, operations );
144 Operation execute = getOperation( EXECUTE, true, operations );
145
146 List parameterElementList = XMLTools.getNodes( getRootElement(), "ows:OperationsMetadata/ows:Parameter",
147 nsContext );
148 OWSDomainType[] parameters = new OWSDomainType[parameterElementList.size()];
149 for ( int i = 0; i < parameters.length; i++ ) {
150 parameters[i] = getOWSDomainType( null, (Element) parameterElementList.get( i ) );
151 }
152
153 List constraintElementList = XMLTools.getNodes( getRootElement(), "ows:OperationsMetadata/ows:Constraint",
154 nsContext );
155 OWSDomainType[] constraints = new OWSDomainType[constraintElementList.size()];
156 for ( int i = 0; i < constraints.length; i++ ) {
157 constraints[i] = getOWSDomainType( null, (Element) constraintElementList.get( i ) );
158 }
159 WPSOperationsMetadata metadata = new WPSOperationsMetadata( getCapabilities, describeProcess, execute,
160 parameters, constraints );
161
162 return metadata;
163 }
164
165 }