001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wpvs/configuration/LocalWMSDataSource.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.xml.InvalidConfigurationException; 054 import org.deegree.i18n.Messages; 055 import org.deegree.model.spatialschema.Surface; 056 import org.deegree.ogcwebservices.OGCWebService; 057 import org.deegree.ogcwebservices.OGCWebServiceException; 058 import org.deegree.ogcwebservices.wms.WMServiceFactory; 059 import org.deegree.ogcwebservices.wms.configuration.WMSConfigurationDocument; 060 import org.deegree.ogcwebservices.wms.configuration.WMSConfigurationType; 061 import org.deegree.ogcwebservices.wms.operation.GetMap; 062 import org.deegree.ogcwebservices.wpvs.capabilities.OWSCapabilities; 063 import org.xml.sax.SAXException; 064 065 /** 066 * This class represents a local WMS dataSource object. 067 * 068 * @author <a href="mailto:mays@lat-lon.de">Judit Mays</a> 069 * @author last edited by: $Author: apoth $ 070 * 071 * @version $Revision: 9345 $, $Date: 2007-12-27 17:22:25 +0100 (Do, 27 Dez 2007) $ 072 * 073 */ 074 public class LocalWMSDataSource extends AbstractDataSource { 075 076 private Color[] transparentColors; 077 078 private static Map<URL, WMSConfigurationType> cache = new ConcurrentHashMap<URL, WMSConfigurationType>(); 079 080 /** 081 * Creates a new <code>LocalWMSDataSource</code> object from the given parameters. 082 * 083 * @param name 084 * @param owsCapabilities 085 * @param validArea 086 * @param minScaleDenominator 087 * @param maxScaleDenominator 088 * @param filterCondition 089 * @param transparentColors 090 */ 091 public LocalWMSDataSource( QualifiedName name, OWSCapabilities owsCapabilities, 092 Surface validArea, double minScaleDenominator, 093 double maxScaleDenominator, GetMap filterCondition, 094 Color[] transparentColors ) { 095 096 super( AbstractDataSource.LOCAL_WMS, name, owsCapabilities, validArea, minScaleDenominator, 097 maxScaleDenominator, filterCondition ); 098 this.transparentColors = transparentColors; 099 } 100 101 /** 102 * The <code>filterCondition</code> is a map of key-value-pairs of an incomplete WMSRequest. 103 * 104 * @return Returns the filterCondition as a map of key-value-pairs. 105 */ 106 public GetMap getPartialGetMapRequest() { 107 return (GetMap) getFilterCondition(); 108 } 109 110 /** 111 * @return Returns the transparentColors. 112 */ 113 public Color[] getTransparentColors() { 114 return transparentColors; 115 } 116 117 /** 118 * @throws OGCWebServiceException 119 * @see org.deegree.ogcwebservices.wpvs.configuration.AbstractDataSource#getOGCWebService() 120 */ 121 @Override 122 public OGCWebService getOGCWebService() 123 throws OGCWebServiceException { 124 WMSConfigurationType wmsConfig = null; 125 synchronized ( this ) { 126 URL url = getOwsCapabilities().getOnlineResource(); 127 wmsConfig = cache.get( url ); 128 if ( !cache.containsKey( url ) || wmsConfig == null ) { 129 WMSConfigurationDocument wmsDoc = new WMSConfigurationDocument(); 130 try { 131 wmsDoc.load( getOwsCapabilities().getOnlineResource() ); 132 wmsConfig = wmsDoc.parseConfiguration(); 133 cache.put( url, wmsConfig ); 134 } catch ( IOException e ) { 135 throw new OGCWebServiceException( 136 Messages.getMessage( 137 "WPVS_DATASOURCE_CAP_ERROR", 138 toString() ) 139 + e.getMessage() ); 140 } catch ( SAXException e ) { 141 throw new OGCWebServiceException( 142 Messages.getMessage( 143 "WPVS_DATASOURCE_CAP_ERROR", 144 toString() ) 145 + e.getMessage() ); 146 } catch ( InvalidConfigurationException e ) { 147 throw new OGCWebServiceException( 148 Messages.getMessage( 149 "WPVS_DATASOURCE_CAP_ERROR", 150 toString() ) 151 + e.getMessage() ); 152 } 153 } 154 } 155 return WMServiceFactory.getWMSInstance( wmsConfig ); 156 } 157 158 }