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