001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wps/configuration/WPSConfigurationDocument.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.wps.configuration; 045 046 import java.net.MalformedURLException; 047 048 import org.deegree.framework.log.ILogger; 049 import org.deegree.framework.log.LoggerFactory; 050 import org.deegree.framework.util.StringTools; 051 import org.deegree.framework.xml.InvalidConfigurationException; 052 import org.deegree.framework.xml.XMLParsingException; 053 import org.deegree.framework.xml.XMLTools; 054 import org.deegree.model.metadata.iso19115.OnlineResource; 055 import org.deegree.ogcwebservices.wps.capabilities.WPSCapabilitiesDocument; 056 import org.deegree.ogcwebservices.wps.execute.RequestQueueManager; 057 import org.w3c.dom.Element; 058 059 /** 060 * WPSConfigurationDocument.java 061 * 062 * Created on 08.03.2006. 20:38:30h 063 * 064 * @author <a href="mailto:christian@kiehle.org">Christian Kiehle</a> 065 * @author <a href="mailto:christian.heier@gmx.de">Christian Heier</a> 066 * 067 * @version 1.0. 068 * 069 * @since 2.0 070 */ 071 public class WPSConfigurationDocument extends WPSCapabilitiesDocument { 072 073 protected static final ILogger LOG = LoggerFactory.getLogger( WPSConfigurationDocument.class ); 074 075 /** 076 * Creates a class representation of the document. 077 * 078 * @return class representation of the configuration document 079 */ 080 public WPSConfiguration getConfiguration() 081 throws InvalidConfigurationException { 082 WPSConfiguration WPSConfiguration = null; 083 084 try { 085 // last Parameter <code>ProcessOfferings</code> set to null, because 086 // <code>WPSConfiguration</code> 087 // constructor is responsible for instantiating ProcessOfferings 088 WPSConfiguration = new WPSConfiguration( parseVersion(), parseUpdateSequence(), getServiceIdentification(), 089 getServiceProvider(), getOperationsMetadata(), null, 090 getDeegreeParams() ); 091 } catch ( XMLParsingException e ) { 092 LOG.logError( e.getMessage() ); 093 throw new InvalidConfigurationException( e.getMessage() + "\n" + StringTools.stackTraceToString( e ) ); 094 } 095 return WPSConfiguration; 096 } 097 098 /** 099 * Creates a class representation of the <code>deegreeParams</code>- section. 100 * 101 * @return 102 * @throws InvalidConfigurationException 103 */ 104 public WPSDeegreeParams getDeegreeParams() 105 throws InvalidConfigurationException { 106 LOG.logInfo( nsContext.toString() ); 107 WPSDeegreeParams deegreeParams = null; 108 109 try { 110 Element element = (Element) XMLTools.getRequiredNode( getRootElement(), "./deegreewps:deegreeParams", 111 nsContext ); 112 OnlineResource defaultOnlineResource = parseOnLineResource( (Element) XMLTools.getRequiredNode( 113 element, 114 "./deegreewps:DefaultOnlineResource", 115 nsContext ) ); 116 int cacheSize = XMLTools.getNodeAsInt( element, "./deegreewps:CacheSize/text()", nsContext, 100 ); 117 int requestTimeLimit = XMLTools.getNodeAsInt( element, "./deegreewps:RequestTimeLimit/text()", nsContext, 2 ); 118 119 String[] processDirectories = XMLTools.getNodesAsStrings( 120 element, 121 "./deegreewps:ProcessDirectoryList/deegreewps:ProcessDirectory/text()", 122 nsContext ); 123 int lengthOfProcessDirectoryList = processDirectories.length; 124 if ( 0 == lengthOfProcessDirectoryList ) { 125 LOG.logInfo( "No process directory specified. Using configuration document directory." ); 126 processDirectories = new String[] { "." }; 127 } 128 129 for ( int i = 0; i < lengthOfProcessDirectoryList; i++ ) { 130 try { 131 processDirectories[i] = resolve( processDirectories[i] ).toURI().getPath(); 132 } catch ( Exception e ) { 133 LOG.logError( "Process directory '" + processDirectories[i] 134 + "' cannot be resolved as a directory: " + e.getMessage(), e ); 135 throw new InvalidConfigurationException( 136 "Process directory '" 137 + processDirectories[i] 138 + "' cannot be resolved as a directory: " 139 + e.getMessage(), e ); 140 141 } 142 } 143 RequestQueueManager requestQueueManagerClass = getRequestQueueManagerClass( element ); 144 145 deegreeParams = new WPSDeegreeParams( defaultOnlineResource, cacheSize, requestTimeLimit, 146 processDirectories, requestQueueManagerClass ); 147 148 } catch ( XMLParsingException e ) { 149 LOG.logError( e.getMessage() ); 150 throw new InvalidConfigurationException( "Error parsing the deegreeParams " 151 + "section of the WPS configuration: \n" + e.getMessage() 152 + StringTools.stackTraceToString( e ) ); 153 } 154 return deegreeParams; 155 } 156 157 private RequestQueueManager getRequestQueueManagerClass( Element deegreeParamsNode ) 158 throws XMLParsingException { 159 160 // Get resonsible class for requestqueuemanager from deegreeParams 161 // section 162 RequestQueueManager requestQueueManager = null; 163 164 String requestQueueManagerClass = XMLTools.getRequiredNodeAsString( 165 deegreeParamsNode, 166 "./deegreewps:RequestQueueManager/deegreewps:ResponsibleClass/text()", 167 nsContext ); 168 169 Object tmp = null; 170 try { 171 tmp = Class.forName( requestQueueManagerClass ).newInstance(); 172 } catch ( ClassNotFoundException clnfe ) { 173 174 String msg = "Responsible class for queue management: '" + requestQueueManagerClass + "' not found."; 175 LOG.logError( msg, clnfe ); 176 throw new XMLParsingException( msg, clnfe ); 177 } catch ( InstantiationException ia ) { 178 179 String msg = "Responsible class for queue management: '" + requestQueueManagerClass 180 + "' can not be instantiated."; 181 LOG.logError( msg, ia ); 182 throw new XMLParsingException( msg, ia ); 183 } catch ( IllegalAccessException iae ) { 184 185 String msg = "Responsible class for queue management: '" + requestQueueManagerClass 186 + "' can not be accessed."; 187 188 LOG.logError( msg, iae ); 189 throw new XMLParsingException( msg, iae ); 190 } 191 192 if ( tmp instanceof RequestQueueManager ) { 193 requestQueueManager = (RequestQueueManager) tmp; 194 } else { 195 String msg = "Responsible class for queue management: '" 196 + requestQueueManagerClass 197 + "' does not implement required Interface 'org.deegree.ogcwebservices.wps.execute.RequestQueueManager'."; 198 ; 199 LOG.logError( msg ); 200 throw new XMLParsingException( msg ); 201 } 202 LOG.logInfo( "requestQueueManager: " + requestQueueManagerClass ); 203 return requestQueueManager; 204 } 205 206 }