001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wpvs/configuration/RemoteWFSDataSource.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.io.IOException;
047    import java.net.URL;
048    import java.util.Map;
049    import java.util.concurrent.ConcurrentHashMap;
050    
051    import org.deegree.datatypes.QualifiedName;
052    import org.deegree.i18n.Messages;
053    import org.deegree.model.filterencoding.Filter;
054    import org.deegree.model.spatialschema.Surface;
055    import org.deegree.ogcbase.PropertyPath;
056    import org.deegree.ogcwebservices.OGCWebService;
057    import org.deegree.ogcwebservices.OGCWebServiceException;
058    import org.deegree.ogcwebservices.wfs.RemoteWFService;
059    import org.deegree.ogcwebservices.wfs.capabilities.WFSCapabilities;
060    import org.deegree.ogcwebservices.wfs.capabilities.WFSCapabilitiesDocument;
061    import org.deegree.ogcwebservices.wpvs.capabilities.OWSCapabilities;
062    import org.xml.sax.SAXException;
063    
064    /**
065     * This class represents a remote WFS dataSource object.
066     * 
067     * @author <a href="mailto:mays@lat-lon.de">Judit Mays</a>
068     * @author last edited by: $Author: apoth $
069     * 
070     * $Revision: 9345 $, $Date: 2007-12-27 17:22:25 +0100 (Do, 27 Dez 2007) $
071     * 
072     */
073    public class RemoteWFSDataSource extends LocalWFSDataSource {
074    
075        // private static final ILogger LOG = LoggerFactory.getLogger( RemoteWFSDataSource.class );
076        private static Map<URL, WFSCapabilities> cache = new ConcurrentHashMap<URL, WFSCapabilities>();
077    
078        /**
079         * Creates a new <code>RemoteWFSDataSource</code> object from the given parameters.
080         * 
081         * @param name
082         * @param owsCapabilities
083         * @param validArea
084         * @param minScaleDenominator
085         * @param maxScaleDenominator
086         * @param geometryProperty
087         * @param filterCondition
088         * @param maxFeatures 
089         */
090        public RemoteWFSDataSource( QualifiedName name, OWSCapabilities owsCapabilities,
091                                    Surface validArea, double minScaleDenominator,
092                                    double maxScaleDenominator, PropertyPath geometryProperty,
093                                    Filter filterCondition, int maxFeatures) {
094    
095            super( name, owsCapabilities, validArea, minScaleDenominator, maxScaleDenominator,
096                   geometryProperty, filterCondition,  maxFeatures );
097            setServiceType( REMOTE_WFS );
098    
099        }
100    
101        @Override
102        public OGCWebService getOGCWebService()
103                                throws OGCWebServiceException {
104            WFSCapabilities wfsCapabilities = null;
105            synchronized ( this ) {
106                URL url = getOwsCapabilities().getOnlineResource();
107                wfsCapabilities = cache.get( url );
108                if ( !cache.containsKey( url ) || wfsCapabilities == null ) {
109                    WFSCapabilitiesDocument wfsCapsDoc = new WFSCapabilitiesDocument();
110                    try {
111                        wfsCapsDoc.load( url );
112                        wfsCapabilities = (WFSCapabilities) wfsCapsDoc.parseCapabilities();
113                        cache.put( url, wfsCapabilities );
114                    } catch ( IOException e ) {
115                        throw new OGCWebServiceException(
116                                                          Messages.getMessage(
117                                                                               "WPVS_DATASOURCE_CAP_ERROR",
118                                                                               toString() )
119                                                                                  + e.getMessage() );
120                    } catch ( SAXException e ) {
121                        throw new OGCWebServiceException(
122                                                          Messages.getMessage(
123                                                                               "WPVS_DATASOURCE_CAP_ERROR",
124                                                                               toString() )
125                                                                                  + e.getMessage() );
126                    }
127                }
128    
129            }
130            return new RemoteWFService( wfsCapabilities );
131        }
132    
133    }