001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/wps/describeprocess/DescribeProcessRequestHandler.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.describeprocess;
044    
045    import java.util.ArrayList;
046    import java.util.List;
047    import java.util.Map;
048    
049    import org.deegree.datatypes.Code;
050    import org.deegree.framework.log.ILogger;
051    import org.deegree.framework.log.LoggerFactory;
052    import org.deegree.ogcwebservices.InvalidParameterValueException;
053    import org.deegree.ogcwebservices.OGCWebServiceException;
054    import org.deegree.ogcwebservices.wps.WPService;
055    import org.deegree.ogcwebservices.wps.configuration.WPSConfiguration;
056    import org.deegree.ogcwebservices.wps.execute.Process;
057    
058    /**
059     * DescribeProcessRequestHandler.java
060     * 
061     * Created on 10.03.2006. 12:06:58h
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    
071    public class DescribeProcessRequestHandler {
072    
073            private static ILogger LOG = LoggerFactory.getLogger( DescribeProcessRequestHandler.class );
074    
075            private WPService wpService = null;
076    
077            /**
078             * 
079             * @param wpService
080             */
081            public DescribeProcessRequestHandler( WPService wpService ) {
082                    this.wpService = wpService;
083            }
084    
085            /**
086             * 
087             * @param describeProcessRequest
088             * @return
089             * @throws OGCWebServiceException
090             */
091            public ProcessDescriptions handleRequest( DescribeProcessRequest describeProcessRequest )
092                            throws OGCWebServiceException {
093    
094                    // Get configuration from current wps instance
095                    WPSConfiguration wpsConfiguration = wpService.getConfiguration();
096    
097                    // Get the map of registered Processes from wps configuration
098                    Map<String, Process> processesMap = wpsConfiguration.getRegisteredProcesses();
099    
100                    // Get list of requested process descriptions from
101                    // wpsDescribeProcessRequest
102                    List<Code> requestedProcessesList = describeProcessRequest.getIdentifier();
103    
104                    // Prepare list of process description to return
105                    List<ProcessDescription> processDescriptionList = new ArrayList<ProcessDescription>();
106    
107                    // If the requested process is registered in current wps instance add it
108                    // to
109                    // processDescriptions, otherwise throw exception
110                    int requestedProcessesSize = requestedProcessesList.size();
111                    for ( int i = 0; i < requestedProcessesSize; i++ ) {
112    
113                            Code requestedProcess = requestedProcessesList.get( i );
114    
115                            String identifier = requestedProcess.getCode().toUpperCase();
116    
117                            if ( processesMap.containsKey( identifier ) ) {
118    
119                                    Process process = processesMap.get( identifier );
120    
121                                    ProcessDescription processDescription = process.getProcessDescription();
122                                    processDescriptionList.add( i, processDescription );
123    
124                            } else {
125                                    String msg = "Process '" + identifier + "' is not supported by this WPS.";
126                                    LOG.logError( msg );
127                                    throw new InvalidParameterValueException( "Identifier", msg );
128                            }
129                    }
130                    return new ProcessDescriptions( processDescriptionList );
131            }
132    
133    }
134    /* ********************************************************************
135    Changes to this class. What the people have been up to:
136    $Log$
137    Revision 1.3  2006/08/24 06:42:16  poth
138    File header corrected
139    
140    Revision 1.2  2006/07/12 14:46:15  poth
141    comment footer added
142    
143    ********************************************************************** */