001 //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/wps/capabilities/WPSCapabilitiesDocument.java $ 002 /*---------------------------------------------------------------------------- 003 This file is part of deegree, http://deegree.org/ 004 Copyright (C) 2001-2009 by: 005 Department of Geography, University of Bonn 006 and 007 lat/lon GmbH 008 009 This library is free software; you can redistribute it and/or modify it under 010 the terms of the GNU Lesser General Public License as published by the Free 011 Software Foundation; either version 2.1 of the License, or (at your option) 012 any later version. 013 This library is distributed in the hope that it will be useful, but WITHOUT 014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 016 details. 017 You should have received a copy of the GNU Lesser General Public License 018 along with this library; if not, write to the Free Software Foundation, Inc., 019 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 020 021 Contact information: 022 023 lat/lon GmbH 024 Aennchenstr. 19, 53177 Bonn 025 Germany 026 http://lat-lon.de/ 027 028 Department of Geography, University of Bonn 029 Prof. Dr. Klaus Greve 030 Postfach 1147, 53001 Bonn 031 Germany 032 http://www.geographie.uni-bonn.de/deegree/ 033 034 e-mail: info@deegree.org 035 ----------------------------------------------------------------------------*/ 036 037 package org.deegree.ogcwebservices.wps.capabilities; 038 039 import static org.deegree.ogcwebservices.wps.capabilities.WPSOperationsMetadata.DESCRIBEPROCESS; 040 import static org.deegree.ogcwebservices.wps.capabilities.WPSOperationsMetadata.EXECUTE; 041 042 import java.io.IOException; 043 import java.net.URL; 044 import java.util.HashMap; 045 import java.util.List; 046 import java.util.Map; 047 048 import org.deegree.framework.log.ILogger; 049 import org.deegree.framework.log.LoggerFactory; 050 import org.deegree.framework.xml.XMLParsingException; 051 import org.deegree.framework.xml.XMLTools; 052 import org.deegree.ogcwebservices.getcapabilities.InvalidCapabilitiesException; 053 import org.deegree.ogcwebservices.getcapabilities.OGCCapabilities; 054 import org.deegree.ogcwebservices.getcapabilities.Operation; 055 import org.deegree.ogcwebservices.getcapabilities.OperationsMetadata; 056 import org.deegree.owscommon.OWSCommonCapabilitiesDocument; 057 import org.deegree.owscommon.OWSDomainType; 058 import org.w3c.dom.Element; 059 import org.w3c.dom.Node; 060 import org.xml.sax.SAXException; 061 062 /** 063 * WPSCapabilitiesDocument.java 064 * 065 * Creates an object representation of the sample_wps_capabilities.xml document 066 * 067 * Created on 08.03.2006. 18:57:37h 068 * 069 * @author <a href="mailto:christian@kiehle.org">Christian Kiehle</a> 070 * @author <a href="mailto:christian.heier@gmx.de">Christian Heier</a> 071 * 072 * @version 1.0. 073 * 074 * @since 2.0 075 */ 076 public class WPSCapabilitiesDocument extends OWSCommonCapabilitiesDocument { 077 078 /** 079 * 080 */ 081 private static final long serialVersionUID = -4004369952171016830L; 082 083 private static final ILogger LOG = LoggerFactory.getLogger( WPSCapabilitiesDocument.class ); 084 085 private static final String XML_TEMPLATE = "WPSCapabilitiesTemplate.xml"; 086 087 /** 088 * @throws IOException 089 * @throws SAXException 090 */ 091 public void createEmptyDocument() 092 throws IOException, SAXException { 093 URL url = WPSCapabilitiesDocument.class.getResource( XML_TEMPLATE ); 094 if ( null == url ) { 095 throw new IOException( "The resource '" + XML_TEMPLATE + " ' could not be found" ); 096 } 097 load( url ); 098 } 099 100 /* 101 * (non-Javadoc) 102 * 103 * @see org.deegree.ogcwebservices.getcapabilities.OGCCapabilitiesDocument#parseCapabilities() 104 */ 105 @Override 106 public OGCCapabilities parseCapabilities() 107 throws InvalidCapabilitiesException { 108 try { 109 110 return new WPSCapabilities( parseVersion(), parseUpdateSequence(), getServiceIdentification(), 111 getServiceProvider(), getOperationsMetadata(), null ); 112 } catch ( Exception e ) { 113 LOG.logError( e.getMessage(), e ); 114 throw new InvalidCapabilitiesException( e.getMessage() ); 115 } 116 } 117 118 /** 119 * Creates an object representation of the <code>ows:OperationsMetadata</code> section. 120 * 121 * @return object representation of the <code>ows:OperationsMetadata</code> section 122 * @throws XMLParsingException 123 */ 124 @SuppressWarnings("unchecked") 125 public OperationsMetadata getOperationsMetadata() 126 throws XMLParsingException { 127 128 List operationElementList = XMLTools.getNodes( getRootElement(), "ows:OperationsMetadata/ows:Operation", 129 nsContext ); 130 131 // build HashMap of 'ows:Operation'-elements for easier access 132 Map operations = new HashMap(); 133 for ( int i = 0; i < operationElementList.size(); i++ ) { 134 operations.put( 135 XMLTools.getRequiredNodeAsString( (Node) operationElementList.get( i ), "@name", nsContext ), 136 operationElementList.get( i ) ); 137 } 138 139 Operation getCapabilities = getOperation( OperationsMetadata.GET_CAPABILITIES_NAME, true, operations ); 140 Operation describeProcess = getOperation( DESCRIBEPROCESS, true, operations ); 141 Operation execute = getOperation( EXECUTE, true, operations ); 142 143 List parameterElementList = XMLTools.getNodes( getRootElement(), "ows:OperationsMetadata/ows:Parameter", 144 nsContext ); 145 OWSDomainType[] parameters = new OWSDomainType[parameterElementList.size()]; 146 for ( int i = 0; i < parameters.length; i++ ) { 147 parameters[i] = getOWSDomainType( null, (Element) parameterElementList.get( i ) ); 148 } 149 150 List constraintElementList = XMLTools.getNodes( getRootElement(), "ows:OperationsMetadata/ows:Constraint", 151 nsContext ); 152 OWSDomainType[] constraints = new OWSDomainType[constraintElementList.size()]; 153 for ( int i = 0; i < constraints.length; i++ ) { 154 constraints[i] = getOWSDomainType( null, (Element) constraintElementList.get( i ) ); 155 } 156 WPSOperationsMetadata metadata = new WPSOperationsMetadata( getCapabilities, describeProcess, execute, 157 parameters, constraints ); 158 159 return metadata; 160 } 161 162 }