001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wpvs/configuration/RemoteWMSDataSource.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     Aennchenstraße 19
030     53177 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    package org.deegree.ogcwebservices.wpvs.configuration;
045    
046    import java.awt.Color;
047    import java.io.IOException;
048    import java.net.URL;
049    import java.util.Map;
050    import java.util.concurrent.ConcurrentHashMap;
051    
052    import org.deegree.datatypes.QualifiedName;
053    import org.deegree.framework.log.ILogger;
054    import org.deegree.framework.log.LoggerFactory;
055    import org.deegree.framework.xml.XMLParsingException;
056    import org.deegree.i18n.Messages;
057    import org.deegree.model.spatialschema.Surface;
058    import org.deegree.ogcwebservices.OGCWebService;
059    import org.deegree.ogcwebservices.OGCWebServiceException;
060    import org.deegree.ogcwebservices.getcapabilities.InvalidCapabilitiesException;
061    import org.deegree.ogcwebservices.wms.RemoteWMService;
062    import org.deegree.ogcwebservices.wms.capabilities.WMSCapabilities;
063    import org.deegree.ogcwebservices.wms.capabilities.WMSCapabilitiesDocument;
064    import org.deegree.ogcwebservices.wms.capabilities.WMSCapabilitiesDocumentFactory;
065    import org.deegree.ogcwebservices.wms.operation.GetMap;
066    import org.deegree.ogcwebservices.wpvs.capabilities.OWSCapabilities;
067    import org.xml.sax.SAXException;
068    
069    /**
070     * This class represents a remote WPVS dataSource object.
071     * 
072     * @author <a href="mailto:mays@lat-lon.de">Judit Mays</a>
073     * @author last edited by: $Author: apoth $
074     * 
075     * @version $Revision: 9345 $, $Date: 2007-12-27 17:22:25 +0100 (Do, 27 Dez 2007) $
076     */
077    public class RemoteWMSDataSource extends LocalWMSDataSource {
078        
079        private static final ILogger LOG = LoggerFactory.getLogger( RemoteWMSDataSource.class );
080    
081        private static Map<URL, WMSCapabilities> cache = new ConcurrentHashMap<URL, WMSCapabilities>();
082    
083        /**
084         * Creates a new <code>RemoteWMSDataSource</code> object from the given parameters.
085         * 
086         * @param name
087         * @param owsCapabilities
088         * @param validArea
089         * @param minScaleDenominator
090         * @param maxScaleDenominator
091         * @param filterCondition
092         * @param transparentColors
093         */
094        public RemoteWMSDataSource( QualifiedName name, OWSCapabilities owsCapabilities, Surface validArea,
095                                    double minScaleDenominator, double maxScaleDenominator, GetMap filterCondition,
096                                    Color[] transparentColors ) {
097    
098            super( name, owsCapabilities, validArea, minScaleDenominator, maxScaleDenominator, filterCondition,
099                   transparentColors );
100            this.setServiceType( AbstractDataSource.REMOTE_WMS );
101    
102        }
103    
104        /**
105         * The <code>filterCondition</code> is a map of key-value-pairs of an incomplete WMSRequest.
106         * 
107         * @return Returns the filterCondition as a map of key-value-pairs.
108         */
109        public Map getFilterConditionMap() {
110            return (Map) getFilterCondition();
111        }
112    
113        /**
114         * @throws OGCWebServiceException
115         * @see org.deegree.ogcwebservices.wpvs.configuration.AbstractDataSource#getOGCWebService()
116         */
117        @Override
118        public OGCWebService getOGCWebService()
119                                throws OGCWebServiceException {
120            WMSCapabilities wmsCapabilities = null;
121            synchronized ( this ) {
122    
123                URL url = getOwsCapabilities().getOnlineResource();
124                wmsCapabilities = cache.get( url );
125                if ( !cache.containsKey( url ) || wmsCapabilities == null ) {
126                    try {
127                        WMSCapabilitiesDocument wmsCapsDoc = WMSCapabilitiesDocumentFactory.getWMSCapabilitiesDocument( url );
128                        wmsCapabilities = (WMSCapabilities) wmsCapsDoc.parseCapabilities();
129                        cache.put( url, wmsCapabilities );
130                    } catch ( IOException e ) {
131                        LOG.logError( e.getMessage(), e );
132                        String msg = Messages.getMessage( "WPVS_DATASOURCE_CAP_ERROR", toString() );
133                        throw new OGCWebServiceException( msg + e.getMessage() );
134                    } catch ( SAXException e ) {
135                        LOG.logError( e.getMessage(), e );
136                        String msg = Messages.getMessage( "WPVS_DATASOURCE_CAP_ERROR", toString() );
137                        throw new OGCWebServiceException( msg + e.getMessage() );
138                    } catch ( InvalidCapabilitiesException e ) {
139                        LOG.logError( e.getMessage(), e );
140                        String msg = Messages.getMessage( "WPVS_DATASOURCE_CAP_ERROR", toString() );
141                        throw new OGCWebServiceException( msg + e.getMessage() );
142                    } catch ( XMLParsingException e ) {
143                        LOG.logError( e.getMessage(), e );
144                        String msg = Messages.getMessage( "WPVS_DATASOURCE_CAP_ERROR", toString() );
145                        throw new OGCWebServiceException( msg + e.getMessage() );
146                    }
147                }
148    
149            }
150    
151            return new RemoteWMService( wmsCapabilities );
152        }
153    }