001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/wpvs/WPVServiceFactory.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2006 by:
006 EXSE, Department of Geography, University of Bonn
007 http://www.giub.uni-bonn.de/deegree/
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.wpvs;
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.wpvs.configuration.WPVSConfiguration;
053 import org.deegree.ogcwebservices.wpvs.configuration.WPVSConfigurationDocument;
054 import org.xml.sax.SAXException;
055
056 /**
057 * Factory class for creating instances of <code>WFService</code>.
058 *
059 * @author <a href="mailto:taddei@lat-lon.de">Ugo Taddei</a>
060 * @author last edited by: $Author: rbezema $
061 *
062 * $Revision: 7966 $, $Date: 2007-08-09 12:04:18 +0200 (Do, 09 Aug 2007) $
063 *
064 */
065 public class WPVServiceFactory {
066
067 private static final ILogger LOG = LoggerFactory.getLogger( WPVServiceFactory.class );
068
069 private static WPVSConfiguration CONFIG;
070
071 private WPVServiceFactory() {
072 // prevent instantiation
073 }
074
075 /**
076 * Creates an instance of a WPVService
077 *
078 * @return a wpvService class with the WPVSConfiguration if the WPVSConfiguration ==
079 * <code>null</code> null will be returned.
080 */
081 public static WPVService createInstance() {
082 if ( CONFIG != null )
083 return new WPVService( CONFIG );
084 return null;
085 }
086
087 /**
088 * Creates a new instance of a WPVService based on <code>config</code>
089 *
090 * @param config
091 * the configuration object used to initalize the new instance
092 * @return a new WPVService Instance, instantiated with the given WPVSConfiguration
093 */
094 public static WPVService getInstance( WPVSConfiguration config ) {
095 return new WPVService( config );
096 }
097
098 /**
099 * Sets the <code>WPVSConfiguration</code>. Afterwards, all <code>WPVSService</code>
100 * instances returned by <code>createInstance()</code> will use this configuration.
101 *
102 * @param wpvsConfiguration
103 */
104 public synchronized static void setConfiguration( WPVSConfiguration wpvsConfiguration ) {
105 CONFIG = wpvsConfiguration;
106 }
107
108 /**
109 * Sets the service configuration used in this object to be that pointed at by the
110 * serviceConfigurationURL
111 *
112 * @param serviceConfigurationURL
113 * the URL pointing at the configuration file for a WPV Service
114 * @throws InvalidConfigurationException
115 * if the configuration is invalid
116 * @throws IOException
117 */
118 public synchronized static void setConfiguration( URL serviceConfigurationURL )
119 throws InvalidConfigurationException, IOException {
120 try {
121 WPVSConfigurationDocument wpvsConfigDoc = new WPVSConfigurationDocument();
122 wpvsConfigDoc.load( serviceConfigurationURL );
123 WPVServiceFactory.setConfiguration( wpvsConfigDoc.parseConfiguration() );
124 } catch ( InvalidConfigurationException e ) {
125 throw new InvalidConfigurationException( "WPVServiceFactory", e.getMessage() );
126 } catch ( SAXException e ) {
127 throw new InvalidConfigurationException( "WPVServiceFactory", e.getMessage() );
128 }
129 }
130 }