001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/ogcwebservices/wass/common/WASServiceFactory.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 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: Aennchenstr. 19
030: 53115 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:
045: package org.deegree.ogcwebservices.wass.common;
046:
047: import java.io.IOException;
048: import java.net.URL;
049:
050: import org.deegree.framework.log.ILogger;
051: import org.deegree.framework.log.LoggerFactory;
052: import org.deegree.framework.xml.InvalidConfigurationException;
053: import org.deegree.framework.xml.XMLFragment;
054: import org.deegree.i18n.Messages;
055: import org.deegree.ogcwebservices.OGCWebServiceException;
056: import org.deegree.ogcwebservices.getcapabilities.InvalidCapabilitiesException;
057: import org.deegree.ogcwebservices.wass.was.WAService;
058: import org.deegree.ogcwebservices.wass.was.configuration.WASConfiguration;
059: import org.deegree.ogcwebservices.wass.was.configuration.WASConfigurationDocument;
060: import org.deegree.ogcwebservices.wass.wss.WSService;
061: import org.deegree.ogcwebservices.wass.wss.configuration.WSSConfiguration;
062: import org.deegree.ogcwebservices.wass.wss.configuration.WSSConfigurationDocument;
063: import org.xml.sax.SAXException;
064:
065: /**
066: * A <code>WASServiceFactory</code> class currently just creates uncached service instances.
067: *
068: * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
069: *
070: * @author last edited by: $Author: apoth $
071: *
072: * @version $Revision: 9345 $, $Date: 2007-12-27 08:22:25 -0800 (Thu, 27 Dec 2007) $
073: */
074:
075: public class WASServiceFactory {
076:
077: private static final ILogger LOG = LoggerFactory
078: .getLogger(WASServiceFactory.class);
079:
080: private static WSSConfiguration wssConfiguration = null;
081:
082: private static WASConfiguration wasConfiguration = null;
083:
084: /**
085: * Dispatches the configuration url to the appropriate methods.
086: * @param url
087: * @throws OGCWebServiceException
088: */
089: public static void setConfiguration(URL url)
090: throws OGCWebServiceException {
091: if (url != null) {
092: String service = null;
093: try {
094: XMLFragment doc = new XMLFragment();
095: doc.load(url);
096: service = doc.getRootElement().getLocalName();
097: } catch (IOException e) {
098: LOG.logError(e.getMessage(), e);
099: throw new OGCWebServiceException(Messages.getMessage(
100: "WASS_ERROR_CONFIGURATION_NOT_READ", "WASS"));
101: } catch (SAXException e) {
102: LOG.logError(e.getMessage(), e);
103: throw new OGCWebServiceException(Messages.getMessage(
104: "WASS_ERROR_CONFIGURATION_NOT_PARSED", "WASS"));
105: }
106:
107: if (service != null) {
108: if (service.contains("WAS")) {
109: setWASConfiguration(url);
110: } else if (service.contains("WSS")) {
111: setWSSConfiguration(url);
112: }
113: }
114: }
115: }
116:
117: /**
118: * @param url
119: * @throws OGCWebServiceException
120: */
121: private static void setWASConfiguration(URL url)
122: throws OGCWebServiceException {
123: try {
124: wasConfiguration = new WASConfigurationDocument()
125: .parseConfiguration(url);
126: } catch (InvalidConfigurationException e) {
127: LOG.logError(e.getMessage(), e);
128: throw new OGCWebServiceException(Messages.getMessage(
129: "WASS_ERROR_CONFIGURATION_NOT_PARSED", "WAS"));
130: } catch (InvalidCapabilitiesException e) {
131: LOG.logError(e.getMessage(), e);
132: throw new OGCWebServiceException(Messages.getMessage(
133: "WASS_ERROR_CONFIGURATION_NOT_PARSED", "WAS"));
134: }
135: }
136:
137: /**
138: * @param url
139: * @throws OGCWebServiceException
140: */
141: private static void setWSSConfiguration(URL url)
142: throws OGCWebServiceException {
143: try {
144: wssConfiguration = new WSSConfigurationDocument()
145: .parseConfiguration(url);
146: } catch (InvalidConfigurationException e) {
147: LOG.logError(e.getMessage(), e);
148: throw new OGCWebServiceException(Messages.getMessage(
149: "WASS_ERROR_CONFIGURATION_NOT_PARSED", "WSS"));
150: }
151: }
152:
153: /**
154: * @return a new WSS service instance
155: * @throws OGCWebServiceException
156: */
157: public static WSService getUncachedWSService()
158: throws OGCWebServiceException {
159: if (wssConfiguration == null) {
160: LOG.logError(Messages.getMessage(
161: "WASS_ERROR_CONFIGURATION_NOT_SET",
162: "WASServiceFactory#getUncachedWSService"));
163: throw new OGCWebServiceException(WASServiceFactory.class
164: .getName(), Messages.getMessage(
165: "WASS_ERROR_CONFIGURATION_NOT_SET", "WSS"));
166: }
167: WSService service = new WSService(wssConfiguration);
168: return service;
169: }
170:
171: /**
172: * @return a new WAS service instance
173: * @throws OGCWebServiceException
174: */
175: public static WAService getUncachedWAService()
176: throws OGCWebServiceException {
177: if (wasConfiguration == null) {
178: LOG.logError(Messages.getMessage(
179: "WASS_ERROR_CONFIGURATION_NOT_SET",
180: "WASServiceFactory#getUncachedWAService"));
181: throw new OGCWebServiceException(WASServiceFactory.class
182: .getName(), Messages.getMessage(
183: "WASS_ERROR_CONFIGURATION_NOT_SET", "WAS"));
184: }
185: return new WAService(wasConfiguration);
186: }
187:
188: }
|