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