root / trunk / extensions / extWFS / src / com / iver / cit / gvsig / fmap / layers / FLyrWFS.java @ 4252
History | View | Annotate | Download (8.96 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.fmap.layers; |
42 |
|
43 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
44 |
|
45 |
import com.iver.andami.PluginServices; |
46 |
|
47 |
import com.iver.cit.gvsig.fmap.DriverException; |
48 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
49 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
50 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
51 |
import com.iver.cit.gvsig.fmap.drivers.wfs.WFSDriver; |
52 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
53 |
import com.iver.cit.gvsig.fmap.operations.strategies.WFSStrategy; |
54 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
55 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
56 |
|
57 |
import com.iver.utiles.XMLEntity; |
58 |
|
59 |
import org.cresques.cts.IProjection; |
60 |
import org.cresques.cts.ProjectionPool; |
61 |
|
62 |
import java.awt.Component; |
63 |
|
64 |
import java.io.IOException; |
65 |
|
66 |
import javax.swing.JOptionPane; |
67 |
|
68 |
|
69 |
/**
|
70 |
* DOCUMENT ME!
|
71 |
*
|
72 |
* @author Vicente Caballero Navarro
|
73 |
*/
|
74 |
public class FLyrWFS extends FLyrVect { |
75 |
private WFSStrategy wfsStrategy = new WFSStrategy(this); |
76 |
|
77 |
/*private String layerName;
|
78 |
private String url;
|
79 |
private String user;
|
80 |
private String pwd;
|
81 |
private String[] layers;
|
82 |
private boolean protocol;
|
83 |
private int numfeatures;
|
84 |
private int timeout;
|
85 |
private IProjection proj;
|
86 |
*/
|
87 |
private WFSDriver wfsDriver;
|
88 |
VectorialAdapter vad = null;
|
89 |
|
90 |
private VectorialLegend legend;
|
91 |
|
92 |
/**
|
93 |
* Crea un nuevo FLyrWFS.
|
94 |
*/
|
95 |
public FLyrWFS() {
|
96 |
} |
97 |
|
98 |
/**
|
99 |
* Crea un RandomVectorialWFS con el driver que se le pasa como par?metro y
|
100 |
* guard?ndose la URL del servidor que se pasa como par?metro
|
101 |
*
|
102 |
* @param layerName Driver WFS.
|
103 |
* @param url URL.
|
104 |
* @param user DOCUMENT ME!
|
105 |
* @param pwd DOCUMENT ME!
|
106 |
* @param layers DOCUMENT ME!
|
107 |
* @param protocol DOCUMENT ME!
|
108 |
* @param numfeatures DOCUMENT ME!
|
109 |
* @param timeout DOCUMENT ME!
|
110 |
* @param proj Proyecci?n.
|
111 |
*
|
112 |
* @return Capa creada.
|
113 |
* @throws Exception
|
114 |
*/
|
115 |
public FLyrWFS(String layerName, String url, |
116 |
String user, String pwd, String[] layers, boolean protocol, |
117 |
int numfeatures, int timeout, IProjection proj) throws Exception { |
118 |
//throw new UnsupportedOperationException();
|
119 |
//FLyrWFS layer = new FLyrWFS();
|
120 |
|
121 |
/*layer.layerName=layerName;
|
122 |
layer.url=url;
|
123 |
layer.user=user;
|
124 |
layer.pwd=pwd;
|
125 |
layer.layers=layers;
|
126 |
layer.protocol=protocol;
|
127 |
layer.numfeatures=numfeatures;
|
128 |
layer.timeout=timeout;
|
129 |
layer.proj=proj;
|
130 |
*/
|
131 |
|
132 |
//layer.setName(name);
|
133 |
VectorialAdapter adapter = new WFSAdapter();
|
134 |
wfsDriver = new WFSDriver();
|
135 |
|
136 |
try {
|
137 |
wfsDriver.setData(url, user, pwd, layers, protocol, numfeatures, |
138 |
timeout, 2);
|
139 |
} catch (IOException e) { |
140 |
JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), |
141 |
"Fallo de la conexi?n con el servidor");
|
142 |
throw new Exception(e); |
143 |
} |
144 |
|
145 |
adapter.setDriver(wfsDriver); |
146 |
|
147 |
//WithDefaultLegend aux=(WithDefaultLegend)driver;
|
148 |
setName(layerName); |
149 |
setSource(adapter); |
150 |
IProjection prj = ProjectionPool.get(wfsDriver.getProjection()); |
151 |
setProjection(prj); // En el cuadro de dialogo de AddLayer se hace
|
152 |
// un chequeo de esto y se aplica una transformaci?n de coordenadas si es necesario.
|
153 |
|
154 |
try {
|
155 |
setLegend(LegendFactory.createSingleSymbolLegend( |
156 |
getShapeType())); |
157 |
} catch (FieldNotFoundException e) {
|
158 |
e.printStackTrace(); |
159 |
} catch (DriverException e) {
|
160 |
e.printStackTrace(); |
161 |
} |
162 |
|
163 |
//layer.setHost(host);
|
164 |
} |
165 |
/**
|
166 |
* DOCUMENT ME!
|
167 |
*
|
168 |
* @return DOCUMENT ME!
|
169 |
*/
|
170 |
public Strategy getStrategy() {
|
171 |
return wfsStrategy;
|
172 |
} |
173 |
|
174 |
/**
|
175 |
* DOCUMENT ME!
|
176 |
*
|
177 |
* @param s DOCUMENT ME!
|
178 |
*/
|
179 |
public void setStrategy(Strategy s) { |
180 |
wfsStrategy = (WFSStrategy) s; |
181 |
} |
182 |
|
183 |
/**
|
184 |
* DOCUMENT ME!
|
185 |
*
|
186 |
* @param va DOCUMENT ME!
|
187 |
*/
|
188 |
public void setSource(VectorialAdapter va) { |
189 |
vad = va; |
190 |
super.setSource(va);
|
191 |
} |
192 |
|
193 |
|
194 |
/**
|
195 |
* DOCUMENT ME!
|
196 |
*
|
197 |
* @return DOCUMENT ME!
|
198 |
*/
|
199 |
public String getClassName() { |
200 |
return this.getClassName(); |
201 |
} |
202 |
|
203 |
/*public XMLEntity getXMLEntity() throws XMLException {
|
204 |
XMLEntity xml=
|
205 |
///XMLEntity xml=((FLyrDefault)this).getXMLEntity();
|
206 |
//XMLEntity xml=new XMLEntity();
|
207 |
|
208 |
xml.putProperty("layerName",layerName);
|
209 |
xml.putProperty("url",url);
|
210 |
xml.putProperty("user",user);
|
211 |
xml.putProperty("pwd",pwd);
|
212 |
xml.putProperty("layers",layers);
|
213 |
xml.putProperty("protocol",protocol);
|
214 |
xml.putProperty("numfeatures",numfeatures);
|
215 |
xml.putProperty("timeout",timeout);
|
216 |
//xml.putProperty(proj.getAbrev());
|
217 |
return xml;
|
218 |
}
|
219 |
*/
|
220 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
221 |
setActive(xml.getBooleanProperty("active"));
|
222 |
setName(xml.getStringProperty("name"));
|
223 |
setMinScale(xml.getDoubleProperty("minScale"));
|
224 |
setMaxScale(xml.getDoubleProperty("maxScale"));
|
225 |
setVisible(xml.getBooleanProperty("visible"));
|
226 |
|
227 |
if (xml.contains("proj")) { |
228 |
setProjection(ProjectionPool.get(xml.getStringProperty("proj")));
|
229 |
} |
230 |
|
231 |
if (xml.contains("transparency")) { |
232 |
setTransparency(xml.getIntProperty("transparency"));
|
233 |
} |
234 |
legend=LegendFactory.createFromXML(xml.getChild(0));
|
235 |
getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
236 |
wfsDriver = WFSDriver.createWFSDriverFromXML(xml.getChild(2));
|
237 |
|
238 |
/*this.layerName=xml.getStringProperty("layerName");
|
239 |
this.url=xml.getStringProperty("url");
|
240 |
this.user=xml.getStringProperty("user");
|
241 |
this.pwd=xml.getStringProperty("pwd");
|
242 |
this.layers=xml.getStringArrayProperty("layers");
|
243 |
this.protocol=xml.getBooleanProperty("protocol");
|
244 |
this.numfeatures=xml.getIntProperty("numfeatures");
|
245 |
this.timeout=xml.getIntProperty("timeout");*/
|
246 |
} |
247 |
|
248 |
/**
|
249 |
* DOCUMENT ME!
|
250 |
*
|
251 |
* @throws DriverIOException DOCUMENT ME!
|
252 |
*/
|
253 |
public void load() throws DriverIOException { |
254 |
WFSAdapter adapter = new WFSAdapter();
|
255 |
|
256 |
try {
|
257 |
wfsDriver.doRelateID_FID(); |
258 |
} catch (IOException e1) { |
259 |
throw new DriverIOException(e1); |
260 |
} |
261 |
|
262 |
adapter.setDriver((VectorialDriver) wfsDriver); |
263 |
|
264 |
this.setSource(adapter);
|
265 |
|
266 |
try {
|
267 |
// Le asignamos tambi?n una legenda por defecto acorde con
|
268 |
// el tipo de shape que tenga. Tampoco s? si es aqu? el
|
269 |
// sitio adecuado, pero en fin....
|
270 |
if (wfsDriver instanceof WithDefaultLegend) { |
271 |
WithDefaultLegend aux = (WithDefaultLegend) wfsDriver; |
272 |
adapter.start(); |
273 |
|
274 |
try {
|
275 |
this.setLegend((VectorialLegend) aux.getDefaultLegend());
|
276 |
} catch (DriverException e) {
|
277 |
throw new DriverIOException(e); |
278 |
} |
279 |
|
280 |
adapter.stop(); |
281 |
} else {
|
282 |
try {
|
283 |
this.setLegend(LegendFactory.createSingleSymbolLegend(
|
284 |
this.getShapeType()));
|
285 |
} catch (DriverException e) {
|
286 |
throw new DriverIOException(e); |
287 |
} |
288 |
} |
289 |
} catch (FieldNotFoundException e) {
|
290 |
//Esta no puede saltar
|
291 |
} |
292 |
try {
|
293 |
if (legend!=null) |
294 |
setLegend(legend); |
295 |
} catch (FieldNotFoundException e) {
|
296 |
// TODO Auto-generated catch block
|
297 |
e.printStackTrace(); |
298 |
} catch (DriverException e) {
|
299 |
// TODO Auto-generated catch block
|
300 |
e.printStackTrace(); |
301 |
} |
302 |
|
303 |
} |
304 |
} |