001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/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 17:22:25 +0100 (Do, 27 Dez 2007) $ 073 */ 074 075 public class WASServiceFactory { 076 077 private static final ILogger LOG = LoggerFactory.getLogger( WASServiceFactory.class ); 078 079 private static WSSConfiguration wssConfiguration = null; 080 081 private static WASConfiguration wasConfiguration = null; 082 083 /** 084 * Dispatches the configuration url to the appropriate methods. 085 * @param url 086 * @throws OGCWebServiceException 087 */ 088 public static void setConfiguration( URL url ) throws OGCWebServiceException{ 089 if( url != null ){ 090 String service = null; 091 try { 092 XMLFragment doc = new XMLFragment( ); 093 doc.load( url ); 094 service = doc.getRootElement().getLocalName(); 095 } catch ( IOException e ) { 096 LOG.logError( e.getMessage(), e ); 097 throw new OGCWebServiceException( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_READ","WASS")); 098 } catch ( SAXException e ) { 099 LOG.logError( e.getMessage(), e ); 100 throw new OGCWebServiceException( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_PARSED","WASS")); 101 } 102 103 if( service != null ){ 104 if( service.contains("WAS") ){ 105 setWASConfiguration(url); 106 } else if ( service.contains("WSS") ){ 107 setWSSConfiguration(url); 108 } 109 } 110 } 111 } 112 113 /** 114 * @param url 115 * @throws OGCWebServiceException 116 */ 117 private static void setWASConfiguration( URL url ) 118 throws OGCWebServiceException { 119 try { 120 wasConfiguration = new WASConfigurationDocument().parseConfiguration( url ); 121 } catch ( InvalidConfigurationException e ) { 122 LOG.logError( e.getMessage(), e ); 123 throw new OGCWebServiceException( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_PARSED","WAS")); 124 } catch ( InvalidCapabilitiesException e ) { 125 LOG.logError( e.getMessage(), e ); 126 throw new OGCWebServiceException( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_PARSED","WAS")); 127 } 128 } 129 130 /** 131 * @param url 132 * @throws OGCWebServiceException 133 */ 134 private static void setWSSConfiguration( URL url ) 135 throws OGCWebServiceException { 136 try { 137 wssConfiguration = new WSSConfigurationDocument().parseConfiguration( url ); 138 } catch ( InvalidConfigurationException e ) { 139 LOG.logError( e.getMessage(), e ); 140 throw new OGCWebServiceException( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_PARSED","WSS")); 141 } 142 } 143 144 /** 145 * @return a new WSS service instance 146 * @throws OGCWebServiceException 147 */ 148 public static WSService getUncachedWSService() 149 throws OGCWebServiceException { 150 if ( wssConfiguration == null ) { 151 LOG.logError( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_SET", "WASServiceFactory#getUncachedWSService")); 152 throw new OGCWebServiceException( WASServiceFactory.class.getName(), 153 Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_SET","WSS")); 154 } 155 WSService service = new WSService( wssConfiguration ); 156 return service; 157 } 158 159 /** 160 * @return a new WAS service instance 161 * @throws OGCWebServiceException 162 */ 163 public static WAService getUncachedWAService() 164 throws OGCWebServiceException { 165 if ( wasConfiguration == null ) { 166 LOG.logError( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_SET", "WASServiceFactory#getUncachedWAService")); 167 throw new OGCWebServiceException( WASServiceFactory.class.getName(), 168 Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_SET","WAS")); 169 } 170 return new WAService( wasConfiguration ); 171 } 172 173 }