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