001 // $HeadURL:
002 // /cvsroot/deegree/src/org/deegree/ogcwebservices/wcs/WCSServiceFactory.java,v
003 // 1.4 2004/06/18 15:50:30 tf Exp $
004 /*---------------- FILE HEADER ------------------------------------------
005
006 This file is part of deegree.
007 Copyright (C) 2001-2006 by:
008 EXSE, Department of Geography, University of Bonn
009 http://www.giub.uni-bonn.de/deegree/
010 lat/lon GmbH
011 http://www.lat-lon.de
012
013 This library is free software; you can redistribute it and/or
014 modify it under the terms of the GNU Lesser General Public
015 License as published by the Free Software Foundation; either
016 version 2.1 of the License, or (at your option) any later version.
017
018 This library is distributed in the hope that it will be useful,
019 but WITHOUT ANY WARRANTY; without even the implied warranty of
020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
021 Lesser General Public License for more details.
022
023 You should have received a copy of the GNU Lesser General Public
024 License along with this library; if not, write to the Free Software
025 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
026
027 Contact:
028
029 Andreas Poth
030 lat/lon GmbH
031 Aennchenstr. 19
032 53115 Bonn
033 Germany
034 E-Mail: poth@lat-lon.de
035
036 Prof. Dr. Klaus Greve
037 Department of Geography
038 University of Bonn
039 Meckenheimer Allee 166
040 53115 Bonn
041 Germany
042 E-Mail: greve@giub.uni-bonn.de
043
044
045 ---------------------------------------------------------------------------*/
046 package org.deegree.ogcwebservices.wms;
047
048 import java.io.IOException;
049 import java.net.URL;
050
051 import org.deegree.framework.log.ILogger;
052 import org.deegree.framework.log.LoggerFactory;
053 import org.deegree.i18n.Messages;
054 import org.deegree.ogcwebservices.wcs.configuration.InvalidConfigurationException;
055 import org.deegree.ogcwebservices.wms.configuration.WMSConfigurationDocument;
056 import org.deegree.ogcwebservices.wms.configuration.WMSConfigurationDocument_1_3_0;
057 import org.deegree.ogcwebservices.wms.configuration.WMSConfigurationType;
058
059 /**
060 *
061 *
062 *
063 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
064 * @author last edited by: $Author: bezema $
065 *
066 * @version 1.0. $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $
067 *
068 * @since 2.0
069 *
070 */
071 public final class WMServiceFactory {
072
073 private static WMSConfigurationType CONFIG;
074
075 private static final ILogger LOG = LoggerFactory.getLogger( WMServiceFactory.class );
076
077 private WMServiceFactory() {
078 CONFIG = null;
079 }
080
081 /**
082 * Creates a new WMS service instance configured with the given configuration.
083 *
084 * @param config
085 * @return a new service instance
086 */
087 public static WMService getWMSInstance( WMSConfigurationType config ) {
088 return new WMService( config );
089 }
090
091 /**
092 * Sets the default configuration by value.
093 *
094 * @param wmsConfiguration
095 */
096 public static void setConfiguration( WMSConfigurationType wmsConfiguration ) {
097 CONFIG = wmsConfiguration;
098 // if service instance are already created
099 // destroy all instances
100 // create new service instances and put in pool
101
102 LOG.logInfo( CONFIG.getServiceIdentification().getTitle() + " (" + CONFIG.getVersion()
103 + ") service pool initialized." );
104 }
105
106 /**
107 * Sets the default configuration by URL.
108 *
109 * @param serviceConfigurationUrl
110 * @throws InvalidConfigurationException
111 */
112 public static void setConfiguration( URL serviceConfigurationUrl )
113 throws InvalidConfigurationException {
114
115 try {
116 WMSConfigurationDocument doc = new WMSConfigurationDocument();
117 WMSConfigurationDocument_1_3_0 doc130 = new WMSConfigurationDocument_1_3_0();
118
119 // changes start here
120 int dc = 50;
121 boolean configured = false;
122 while ( !configured ) {
123 try {
124 doc.load( serviceConfigurationUrl );
125
126 if ( "1.3.0".equals( doc.getRootElement().getAttribute( "version" ) ) ) {
127 LOG.logInfo( Messages.getMessage( "WMS_VERSION130" ) );
128 doc130.load( serviceConfigurationUrl );
129 doc = null;
130 } else {
131 LOG.logInfo( Messages.getMessage( "WMS_VERSIONDEFAULT" ) );
132 doc130 = null;
133 }
134
135 configured = true;
136 } catch ( IOException ioe ) {
137 if ( serviceConfigurationUrl.getProtocol().startsWith( "http" ) && dc > 0 ) {
138 LOG.logWarning( "No successful connection to the WMS-Configuration-URL, "
139 + "trying again in 10 seconds. Will try " + dc
140 + " more times to connect." );
141 Thread.sleep( 10000 );
142 dc--;
143 } else {
144 throw ( ioe );
145 }
146 }
147 }
148 // changes end here
149
150 WMSConfigurationType conf;
151
152 if ( doc != null ) {
153 conf = doc.parseConfiguration();
154 } else {
155 conf = doc130.parseConfiguration();
156 }
157
158 WMServiceFactory.setConfiguration( conf );
159
160 } catch ( Exception e ) {
161 LOG.logError( e.getMessage(), e );
162 throw new InvalidConfigurationException( "WMServiceFactory", e.getMessage() );
163 }
164
165 }
166
167 /**
168 * Returns a new WMS service instance configured with a previously set default
169 * configuration.
170 *
171 * @return a new service instance
172 */
173 public static WMService getService() {
174 return WMServiceFactory.getWMSInstance( CONFIG );
175 }
176
177 }/* ********************************************************************
178 Changes to this class. What the people have been up to:
179 $Log$
180 Revision 1.18 2006/11/29 13:00:36 schmitz
181 Cleaned up WMS messages.
182
183 Revision 1.17 2006/11/24 09:33:12 schmitz
184 Fixed a bug concerning layer specific scale hints.
185 Using the central i18n mechanism.
186 Changed the localwfs mechanism to just use one WFS and not recreate them.
187
188 Revision 1.16 2006/10/27 12:23:24 schmitz
189 Formatting changes.
190
191 Revision 1.15 2006/09/08 08:42:01 schmitz
192 Updated the WMS to be 1.1.1 conformant once again.
193 Cleaned up the WMS code.
194 Added cite WMS test data.
195
196 Revision 1.14 2006/07/28 08:01:27 schmitz
197 Updated the WMS for 1.1.1 compliance.
198 Fixed some documentation.
199
200 Revision 1.13 2006/07/12 14:46:17 poth
201 comment footer added
202
203 ********************************************************************** */