001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wps/WPServiceFactory.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/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    
044    package org.deegree.ogcwebservices.wps;
045    
046    import java.io.IOException;
047    import java.net.URL;
048    
049    import org.deegree.framework.log.ILogger;
050    import org.deegree.framework.log.LoggerFactory;
051    import org.deegree.framework.xml.InvalidConfigurationException;
052    import org.deegree.ogcwebservices.OGCWebServiceException;
053    import org.deegree.ogcwebservices.wps.configuration.WPSConfiguration;
054    import org.deegree.ogcwebservices.wps.configuration.WPSConfigurationDocument;
055    import org.xml.sax.SAXException;
056    
057    /**
058     * WPServiceFactory.java
059     * 
060     * Created on 08.03.2006. 17:47:52h
061     * 
062     * @author <a href="mailto:christian@kiehle.org">Christian Kiehle</a>
063     * @author <a href="mailto:christian.heier@gmx.de">Christian Heier</a>
064     * @author last edited by: $Author: apoth $
065     * 
066     * @version $Revision: 9348 $, $Date: 2007-12-27 17:59:14 +0100 (Do, 27 Dez 2007) $
067     */
068    public final class WPServiceFactory {
069    
070        private static WPSConfiguration CONFIG = null;
071    
072        private static final ILogger LOG = LoggerFactory.getLogger( WPSConfiguration.class );
073    
074        private WPServiceFactory() {
075    
076        }
077    
078        /**
079         * 
080         * @param config
081         * @return WPService
082         */
083        public static WPService getInstance( WPSConfiguration config ) {
084            return new WPService( config );
085        }
086    
087        /**
088         * 
089         * @return WPService
090         * @throws OGCWebServiceException
091         */
092        public static WPService getInstance()
093                                throws OGCWebServiceException {
094            if ( null == CONFIG ) {
095                throw new OGCWebServiceException( WPServiceFactory.class.getName(),
096                                                  "Configuration has not been initialized" );
097            }
098            return new WPService( CONFIG );
099        }
100    
101        /**
102         * 
103         * @param wpsConfiguration
104         */
105        public static void setConfiguration( WPSConfiguration wpsConfiguration ) {
106            CONFIG = wpsConfiguration;
107        }
108    
109        /**
110         * 
111         * @param serviceConfigurationUrl
112         * @throws InvalidConfigurationException
113         * @throws IOException
114         */
115        public static void setConfiguration( URL serviceConfigurationUrl )
116                                throws InvalidConfigurationException, IOException {
117            
118            WPSConfigurationDocument wpsConfDoc = new WPSConfigurationDocument();
119            try {
120                wpsConfDoc.load( serviceConfigurationUrl );
121            } catch ( SAXException e ) {
122                LOG.logError( "SAXException: " + e.getMessage() );
123                throw new InvalidConfigurationException( "WPServiceFactory", e.getMessage() );
124            }
125            WPServiceFactory.setConfiguration( wpsConfDoc.getConfiguration() );
126    
127            
128        }
129    
130        /**
131         * 
132         * @return WPService
133         * @throws OGCWebServiceException
134         * @todo
135         */
136        public static WPService getService() {
137            return WPServiceFactory.getInstance( CONFIG );
138        }
139    
140    }