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