001    //$HeadURL: $
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.wcts;
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.ogcbase.ExceptionCode;
045    import org.deegree.ogcwebservices.OGCWebServiceException;
046    import org.deegree.ogcwebservices.getcapabilities.InvalidCapabilitiesException;
047    import org.deegree.ogcwebservices.wcts.configuration.WCTSConfiguration;
048    import org.deegree.ogcwebservices.wcts.configuration.WCTSConfigurationDocument;
049    import org.xml.sax.SAXException;
050    
051    /**
052     * <code>WCTServiceFactory</code> a convenience class to create and receive a
053     * {@link WCTSConfiguration} instance.
054     *
055     * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
056     *
057     * @author last edited by: $Author:$
058     *
059     * @version $Revision:$, $Date:$
060     *
061     */
062    public class WCTServiceFactory {
063        private static ILogger LOG = LoggerFactory.getLogger( WCTServiceFactory.class );
064    
065        private static WCTSConfiguration CONFIG;
066    
067        private WCTServiceFactory() {
068            // do nottin
069        }
070    
071        /**
072         * @param configURL
073         *            to read the configuration from.
074         */
075        public static synchronized void setConfiguration( URL configURL ) {
076            if ( configURL != null ) {
077                try {
078                    WCTSConfigurationDocument doc = new WCTSConfigurationDocument( configURL );
079                    CONFIG = doc.parseConfiguration();
080                } catch ( IOException e ) {
081                    LOG.logError( e.getMessage(), e );
082                } catch ( SAXException e ) {
083                    LOG.logError( e.getMessage(), e );
084                } catch ( InvalidCapabilitiesException e ) {
085                    LOG.logError( e.getMessage(), e );
086                }
087            }
088        }
089    
090        /**
091         * @return the configuration
092         * @throws OGCWebServiceException
093         *             if no configuration has been created yet.
094         */
095        public static synchronized WCTSConfiguration getConfiguration()
096                                throws OGCWebServiceException {
097            if ( CONFIG == null ) {
098                throw new OGCWebServiceException( "Configuration has not been initialized yet",
099                                                  ExceptionCode.INTERNAL_SERVER_ERROR );
100            }
101            return CONFIG;
102        }
103    
104        /**
105         *
106         * @return a new {@link WCTService} instance.
107         * @throws OGCWebServiceException
108         *             if the configuration was not initialized yet.
109         */
110        public static synchronized WCTService createServiceInstance()
111                                throws OGCWebServiceException {
112            if ( CONFIG == null ) {
113                throw new OGCWebServiceException( "Configuration has not been initialized yet",
114                                                  ExceptionCode.INTERNAL_SERVER_ERROR );
115            }
116            return new WCTService( CONFIG );
117        }
118    
119    }