001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/wass/common/WASServiceFactory.java $
002    /*----------------------------------------------------------------------------
003     This file is part of deegree, http://deegree.org/
004     Copyright (C) 2001-2009 by:
005       Department of Geography, University of Bonn
006     and
007       lat/lon GmbH
008    
009     This library is free software; you can redistribute it and/or modify it under
010     the terms of the GNU Lesser General Public License as published by the Free
011     Software Foundation; either version 2.1 of the License, or (at your option)
012     any later version.
013     This library is distributed in the hope that it will be useful, but WITHOUT
014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016     details.
017     You should have received a copy of the GNU Lesser General Public License
018     along with this library; if not, write to the Free Software Foundation, Inc.,
019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020    
021     Contact information:
022    
023     lat/lon GmbH
024     Aennchenstr. 19, 53177 Bonn
025     Germany
026     http://lat-lon.de/
027    
028     Department of Geography, University of Bonn
029     Prof. Dr. Klaus Greve
030     Postfach 1147, 53001 Bonn
031     Germany
032     http://www.geographie.uni-bonn.de/deegree/
033    
034     e-mail: info@deegree.org
035    ----------------------------------------------------------------------------*/
036    
037    package org.deegree.ogcwebservices.wass.common;
038    
039    import java.io.IOException;
040    import java.net.URL;
041    
042    import org.deegree.framework.log.ILogger;
043    import org.deegree.framework.log.LoggerFactory;
044    import org.deegree.framework.xml.InvalidConfigurationException;
045    import org.deegree.framework.xml.XMLFragment;
046    import org.deegree.i18n.Messages;
047    import org.deegree.ogcwebservices.OGCWebServiceException;
048    import org.deegree.ogcwebservices.getcapabilities.InvalidCapabilitiesException;
049    import org.deegree.ogcwebservices.wass.was.WAService;
050    import org.deegree.ogcwebservices.wass.was.configuration.WASConfiguration;
051    import org.deegree.ogcwebservices.wass.was.configuration.WASConfigurationDocument;
052    import org.deegree.ogcwebservices.wass.wss.WSService;
053    import org.deegree.ogcwebservices.wass.wss.configuration.WSSConfiguration;
054    import org.deegree.ogcwebservices.wass.wss.configuration.WSSConfigurationDocument;
055    import org.xml.sax.SAXException;
056    
057    /**
058     * A <code>WASServiceFactory</code> class currently just creates uncached service instances.
059     *
060     * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
061     *
062     * @author last edited by: $Author: mschneider $
063     *
064     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
065     */
066    
067    public class WASServiceFactory {
068    
069        private static final ILogger LOG = LoggerFactory.getLogger( WASServiceFactory.class );
070    
071        private static WSSConfiguration wssConfiguration = null;
072    
073        private static WASConfiguration wasConfiguration = null;
074    
075        /**
076         * Dispatches the configuration url to the appropriate methods.
077         * @param url
078         * @throws OGCWebServiceException
079         */
080        public static void setConfiguration( URL url ) throws OGCWebServiceException{
081            if( url != null ){
082                String service = null;
083                try {
084                    XMLFragment doc = new XMLFragment( );
085                    doc.load( url );
086                    service = doc.getRootElement().getLocalName();
087                } catch ( IOException e ) {
088                    LOG.logError( e.getMessage(), e );
089                    throw new OGCWebServiceException( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_READ","WASS"));
090                } catch ( SAXException e ) {
091                    LOG.logError( e.getMessage(), e );
092                    throw new OGCWebServiceException( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_PARSED","WASS"));
093                }
094    
095                if( service != null ){
096                    if( service.contains("WAS") ){
097                        setWASConfiguration(url);
098                    } else if ( service.contains("WSS") ){
099                        setWSSConfiguration(url);
100                    }
101                }
102            }
103        }
104    
105        /**
106         * @param url
107         * @throws OGCWebServiceException
108         */
109        private static void setWASConfiguration( URL url )
110                                throws OGCWebServiceException {
111            try {
112                wasConfiguration = new WASConfigurationDocument().parseConfiguration( url );
113            } catch ( InvalidConfigurationException e ) {
114                LOG.logError( e.getMessage(), e );
115                throw new OGCWebServiceException( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_PARSED","WAS"));
116            } catch ( InvalidCapabilitiesException e ) {
117                LOG.logError( e.getMessage(), e );
118                throw new OGCWebServiceException( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_PARSED","WAS"));
119            }
120        }
121    
122        /**
123         * @param url
124         * @throws OGCWebServiceException
125         */
126        private static void setWSSConfiguration( URL url )
127                                throws OGCWebServiceException {
128            try {
129                wssConfiguration = new WSSConfigurationDocument().parseConfiguration( url );
130            } catch ( InvalidConfigurationException e ) {
131                LOG.logError( e.getMessage(), e );
132                throw new OGCWebServiceException( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_PARSED","WSS"));
133            }
134        }
135    
136        /**
137         * @return a new WSS service instance
138         * @throws OGCWebServiceException
139         */
140        public static WSService getUncachedWSService()
141                                throws OGCWebServiceException {
142            if ( wssConfiguration == null ) {
143                LOG.logError( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_SET", "WASServiceFactory#getUncachedWSService"));
144                throw new OGCWebServiceException( WASServiceFactory.class.getName(),
145                                                  Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_SET","WSS"));
146            }
147            WSService service = new WSService( wssConfiguration );
148            return service;
149        }
150    
151        /**
152         * @return a new WAS service instance
153         * @throws OGCWebServiceException
154         */
155        public static WAService getUncachedWAService()
156                                throws OGCWebServiceException {
157            if ( wasConfiguration == null ) {
158                LOG.logError( Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_SET", "WASServiceFactory#getUncachedWAService"));
159                throw new OGCWebServiceException( WASServiceFactory.class.getName(),
160                                                  Messages.getMessage("WASS_ERROR_CONFIGURATION_NOT_SET","WAS"));
161            }
162            return new WAService( wasConfiguration );
163        }
164    
165    }