/*
 *    GeoTools - OpenSource mapping toolkit
 *    http://geotools.org
 *    (C) 2004-2006, Geotools Project Managment Committee (PMC)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation; either
 *    version 2.1 of the License, or (at your option) any later version.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */
package org.geotools.data.wfs.demo;

import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;

import org.geotools.data.DataStore;
import org.geotools.data.DefaultQuery;
import org.geotools.data.FeatureReader;
import org.geotools.data.Query;
import org.geotools.data.Transaction;
import org.geotools.data.wfs.WFSDataStoreFactory;
import org.geotools.feature.IllegalAttributeException;

/**
 * <p> 
 * An example use of the WFS data store
 * </p>
 * @author dzwiers Refractions Research
 *
 * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/wfs/src/test/java/org/geotools/data/wfs/demo/WFSDemo.java $
 */
public class WFSDemo {
    public static void main(String[] args){
        System.out.println("WFS Demo");
        try{
//            URL url = new URL("http://www2.dmsolutions.ca/cgi-bin/mswfs_gmap?version=1.0.0&request=getcapabilities&service=wfs");
        	URL url = new URL("http://www.refractions.net:8080/geoserver/wfs?REQUEST=GetCapabilities");
        
            Map m = new HashMap();
            m.put(WFSDataStoreFactory.URL.key,url);
            m.put(WFSDataStoreFactory.TIMEOUT.key,new Integer(10000));
            m.put(WFSDataStoreFactory.PROTOCOL.key,Boolean.FALSE);

            DataStore wfs = (new WFSDataStoreFactory()).createNewDataStore(m);
            Query query = new DefaultQuery(wfs.getTypeNames()[1]);
            FeatureReader ft = wfs.getFeatureReader(query,Transaction.AUTO_COMMIT);
            int count = 0;
            while(ft.hasNext())
                if(ft.next()!=null)
                    count++;
            System.out.println("Found "+count+" features");
        }catch(IOException e){
            e.printStackTrace();
        } catch (NoSuchElementException e) {
            e.printStackTrace();
        } catch (IllegalAttributeException e) {
            e.printStackTrace();
        }
    }
}
