Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / wfs / WFSDataSourceAdapter.java @ 2183

History | View | Annotate | Download (3.83 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*
19
* For more information, contact:
20
*
21
*  Generalitat Valenciana
22
*   Conselleria d'Infraestructures i Transport
23
*   Av. Blasco Ib??ez, 50
24
*   46010 VALENCIA
25
*   SPAIN
26
*
27
*      +34 963862235
28
*   gvsig@gva.es
29
*      www.gvsig.gva.es
30
*
31
*    or
32
*
33
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41
package com.iver.cit.gvsig.gui.wfs;
42

    
43
import java.awt.geom.Rectangle2D;
44
import java.io.IOException;
45
import java.net.URL;
46
import java.util.HashMap;
47
import java.util.Map;
48

    
49
import org.exolab.castor.xml.ValidationException;
50
import org.geotools.data.DataStore;
51
import org.geotools.data.wfs.WFSDataStoreFactory;
52

    
53
import com.iver.cit.gvsig.gui.wms.LayerInfo;
54
import com.iver.cit.gvsig.gui.wms.WizardData;
55
import com.iver.cit.gvsig.gui.wms.WizardDataSource;
56
import com.iver.wmsclient.UnsupportedVersionException;
57
/**
58
 * Adaptador del dataSource.
59
 * 
60
 * @author Vicente Caballero Navarro
61
 */
62
public class WFSDataSourceAdapter implements WizardDataSource {
63
        private String urlS=null;//"http://localhost:8080/geoserver/wfs";
64
        private String versionS=null;//"version=1.0.0";
65
        private String requestS=null;//"request=getcapabilities";
66
        private String serviceS=null;//"service=wfs";
67
        private String userS=null;//"admin";
68
        private String pwdS=null;//"geoserver";
69
        private String[] layersS;
70
        private boolean protocolS=true;
71
        private int numFeaturesS=100;
72
        private int timeoutS=10000;
73
        
74
        public void setData(String user,String pwd,boolean protocol,int numFeatures,int timeout){
75
                userS=user;
76
                pwdS=pwd;
77
                protocolS=protocol;
78
                numFeaturesS=numFeatures;
79
                timeoutS=timeout;
80
        }
81
        public WizardData detalles(URL host)throws IllegalStateException,
82
        ValidationException, UnsupportedVersionException, IOException{
83
                
84
                DataStore ds=null;        
85
                URL url=host;
86
                //int timeout=10000;
87
                //boolean protocol=true;
88
                        
89
         Map m = new HashMap();
90
         m.put(WFSDataStoreFactory.URL.key,url);
91
         m.put(WFSDataStoreFactory.TIMEOUT.key,new Integer(timeoutS));
92
         m.put(WFSDataStoreFactory.PROTOCOL.key,new Boolean(protocolS));
93
                 m.put(WFSDataStoreFactory.PASSWORD.key,pwdS);
94
                 m.put(WFSDataStoreFactory.USERNAME.key,userS);
95
                 m.put(WFSDataStoreFactory.BUFFER_SIZE.key,new Integer(numFeaturesS));
96
        try {
97
                        ds = (new WFSDataStoreFactory()).createNewDataStore(m);
98
                } catch (IOException e) {
99
                        e.printStackTrace();
100
                }
101
                String[] names=null;
102
                try {
103
                        names = ds.getTypeNames();
104
                } catch (IOException e1) {
105
                        e1.printStackTrace();
106
                }
107
                //System.out.println("Capas :");
108
                WizardData data = new WizardData();
109
                LayerInfo root = new LayerInfo();
110
                root.text = "Capas";//l.getTitle().getContent();
111
        root.name = "Nombre";//name.getContent();
112
                for (int i=0;i<names.length;i++){
113
                        System.out.println("Capa "+i+" : "+names[i]);
114
                        LayerInfo hijo = new LayerInfo();
115
                        hijo.text = names[i];//l.getTitle().getContent();
116
                hijo.name = names[i];//name.getContent();
117
                        root.hijos.add(hijo);
118
                        
119
                        
120
                }
121
                data.setLayer(root);
122
                return data;
123
                
124
        }
125
        
126
        public Rectangle2D getBoundingBox(String[] layerName, String srs) {
127
                return null;
128
        }
129

    
130
}