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-2008 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: apoth $
065: *
066: * @version 1.0. $Revision: 9345 $, $Date: 2007-12-27 08:22:25 -0800 (Thu, 27 Dec 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
076: .getLogger(WMServiceFactory.class);
077:
078: private WMServiceFactory() {
079: CONFIG = null;
080: }
081:
082: /**
083: * Creates a new WMS service instance configured with the given configuration.
084: *
085: * @param config
086: * @return a new service instance
087: */
088: public static WMService getWMSInstance(WMSConfigurationType config) {
089: return new WMService(config);
090: }
091:
092: /**
093: * Sets the default configuration by value.
094: *
095: * @param wmsConfiguration
096: */
097: public static void setConfiguration(
098: WMSConfigurationType wmsConfiguration) {
099: CONFIG = wmsConfiguration;
100: // if service instance are already created
101: // destroy all instances
102: // create new service instances and put in pool
103:
104: LOG.logInfo(CONFIG.getServiceIdentification().getTitle() + " ("
105: + CONFIG.getVersion() + ") service pool initialized.");
106: }
107:
108: /**
109: * Sets the default configuration by URL.
110: *
111: * @param serviceConfigurationUrl
112: * @throws InvalidConfigurationException
113: */
114: public static void setConfiguration(URL serviceConfigurationUrl)
115: throws InvalidConfigurationException {
116:
117: try {
118: WMSConfigurationDocument doc = new WMSConfigurationDocument();
119: WMSConfigurationDocument_1_3_0 doc130 = new WMSConfigurationDocument_1_3_0();
120:
121: // changes start here
122: int dc = 50;
123: boolean configured = false;
124: while (!configured) {
125: try {
126: doc.load(serviceConfigurationUrl);
127:
128: if ("1.3.0".equals(doc.getRootElement()
129: .getAttribute("version"))) {
130: LOG.logInfo(Messages
131: .getMessage("WMS_VERSION130"));
132: doc130.load(serviceConfigurationUrl);
133: doc = null;
134: } else {
135: LOG.logInfo(Messages
136: .getMessage("WMS_VERSIONDEFAULT"));
137: doc130 = null;
138: }
139:
140: configured = true;
141: } catch (IOException ioe) {
142: if (serviceConfigurationUrl.getProtocol()
143: .startsWith("http")
144: && dc > 0) {
145: LOG
146: .logWarning("No successful connection to the WMS-Configuration-URL, "
147: + "trying again in 10 seconds. Will try "
148: + dc
149: + " more times to connect.");
150: Thread.sleep(10000);
151: dc--;
152: } else {
153: throw (ioe);
154: }
155: }
156: }
157: // changes end here
158:
159: WMSConfigurationType conf;
160:
161: if (doc != null) {
162: conf = doc.parseConfiguration();
163: } else {
164: conf = doc130.parseConfiguration();
165: }
166:
167: WMServiceFactory.setConfiguration(conf);
168:
169: } catch (Exception e) {
170: LOG.logError(e.getMessage(), e);
171: throw new InvalidConfigurationException("WMServiceFactory",
172: e.getMessage());
173: }
174:
175: }
176:
177: /**
178: * Returns a new WMS service instance configured with a previously set default configuration.
179: *
180: * @return a new service instance
181: */
182: public static WMService getService() {
183: return WMServiceFactory.getWMSInstance(CONFIG);
184: }
185:
186: }
|