001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/wass/common/WASServiceFactory.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/exse/
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 Jens Fitzke
035 lat/lon GmbH
036 Aennchenstraße 19
037 53177 Bonn
038 Germany
039 E-Mail: jens.fitzke@uni-bonn.de
040
041 ---------------------------------------------------------------------------*/
042
043 package org.deegree.ogcwebservices.wass.common;
044
045 import java.io.IOException;
046 import java.net.URL;
047
048 import org.deegree.framework.log.ILogger;
049 import org.deegree.framework.log.LoggerFactory;
050 import org.deegree.framework.xml.InvalidConfigurationException;
051 import org.deegree.framework.xml.XMLFragment;
052 import org.deegree.i18n.Messages;
053 import org.deegree.ogcwebservices.OGCWebServiceException;
054 import org.deegree.ogcwebservices.getcapabilities.InvalidCapabilitiesException;
055 import org.deegree.ogcwebservices.wass.was.WAService;
056 import org.deegree.ogcwebservices.wass.was.configuration.WASConfiguration;
057 import org.deegree.ogcwebservices.wass.was.configuration.WASConfigurationDocument;
058 import org.deegree.ogcwebservices.wass.wss.WSService;
059 import org.deegree.ogcwebservices.wass.wss.configuration.WSSConfiguration;
060 import org.deegree.ogcwebservices.wass.wss.configuration.WSSConfigurationDocument;
061 import org.xml.sax.SAXException;
062
063 /**
064 * A <code>WASServiceFactory</code> class currently just creates uncached service instances.
065 *
066 * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
067 *
068 * @author last edited by: $Author: aschmitz $
069 *
070 * @version $Revision: 7341 $, $Date: 2007-05-29 14:03:14 +0200 (Di, 29 Mai 2007) $
071 */
072
073 public class WASServiceFactory {
074
075 private static final ILogger LOG = LoggerFactory.getLogger( WASServiceFactory.class );
076
077 private static WSSConfiguration wssConfiguration = null;
078
079 private static WASConfiguration wasConfiguration = null;
080
081 /**
082 * Dispatches the configuration url to the appropriate methods.
083 * @param url
084 * @throws OGCWebServiceException
085 */
086 public static void setConfiguration( URL url ) throws OGCWebServiceException{
087 if( url != null ){
088 String service = null;
089 try {
090 XMLFragment doc = new XMLFragment( );
091 doc.load( url );
092 service = doc.getRootElement().getLocalName();
093 } catch ( IOException e ) {
094 LOG.logError( e.getMessage(), e );
095 throw new OGCWebServiceException( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_READ","WASS"));
096 } catch ( SAXException e ) {
097 LOG.logError( e.getMessage(), e );
098 throw new OGCWebServiceException( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_PARSED","WASS"));
099 }
100
101 if( service != null ){
102 if( service.contains("WAS") ){
103 setWASConfiguration(url);
104 } else if ( service.contains("WSS") ){
105 setWSSConfiguration(url);
106 }
107 }
108 }
109 }
110
111 /**
112 * @param url
113 * @throws OGCWebServiceException
114 */
115 private static void setWASConfiguration( URL url )
116 throws OGCWebServiceException {
117 try {
118 wasConfiguration = new WASConfigurationDocument().parseConfiguration( url );
119 } catch ( InvalidConfigurationException e ) {
120 LOG.logError( e.getMessage(), e );
121 throw new OGCWebServiceException( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_PARSED","WAS"));
122 } catch ( InvalidCapabilitiesException e ) {
123 LOG.logError( e.getMessage(), e );
124 throw new OGCWebServiceException( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_PARSED","WAS"));
125 }
126 }
127
128 /**
129 * @param url
130 * @throws OGCWebServiceException
131 */
132 private static void setWSSConfiguration( URL url )
133 throws OGCWebServiceException {
134 try {
135 wssConfiguration = new WSSConfigurationDocument().parseConfiguration( url );
136 } catch ( InvalidConfigurationException e ) {
137 LOG.logError( e.getMessage(), e );
138 throw new OGCWebServiceException( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_PARSED","WSS"));
139 }
140 }
141
142 /**
143 * @return a new WSS service instance
144 * @throws OGCWebServiceException
145 */
146 public static WSService getUncachedWSService()
147 throws OGCWebServiceException {
148 if ( wssConfiguration == null ) {
149 LOG.logError( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_SET", "WASServiceFactory#getUncachedWSService"));
150 throw new OGCWebServiceException( WASServiceFactory.class.getName(),
151 Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_SET","WSS"));
152 }
153 WSService service = new WSService( wssConfiguration );
154 return service;
155 }
156
157 /**
158 * @return a new WAS service instance
159 * @throws OGCWebServiceException
160 */
161 public static WAService getUncachedWAService()
162 throws OGCWebServiceException {
163 if ( wasConfiguration == null ) {
164 LOG.logError( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_SET", "WASServiceFactory#getUncachedWAService"));
165 throw new OGCWebServiceException( WASServiceFactory.class.getName(),
166 Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_SET","WAS"));
167 }
168 return new WAService( wasConfiguration );
169 }
170
171 }