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