gvsig-raster / org.gvsig.raster.wmts / trunk / org.gvsig.raster.wmts / org.gvsig.raster.wmts.io / src / main / java / org / gvsig / raster / wmts / io / WMTSDataParametersImpl.java @ 768
History | View | Annotate | Download (14.3 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
package org.gvsig.raster.wmts.io; |
24 |
|
25 |
import java.awt.geom.Rectangle2D; |
26 |
|
27 |
import org.cresques.cts.IProjection; |
28 |
import org.gvsig.compat.net.ICancellable; |
29 |
import org.gvsig.fmap.crs.CRSFactory; |
30 |
import org.gvsig.fmap.dal.DataTypes; |
31 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
32 |
import org.gvsig.remoteclient.wmts.struct.WMTSLayer; |
33 |
import org.gvsig.remoteclient.wmts.struct.WMTSStyle; |
34 |
import org.gvsig.tools.ToolsLocator; |
35 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
36 |
import org.gvsig.tools.dynobject.DynClass; |
37 |
import org.gvsig.tools.dynobject.DynField; |
38 |
import org.gvsig.tools.dynobject.DynObjectManager; |
39 |
import org.gvsig.tools.dynobject.DynStruct; |
40 |
import org.gvsig.tools.persistence.PersistenceManager; |
41 |
import org.gvsig.tools.persistence.PersistentState; |
42 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
43 |
|
44 |
/**
|
45 |
* Parameters for the WMTS provider
|
46 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
47 |
*/
|
48 |
public class WMTSDataParametersImpl extends AbstractRasterDataParameters implements WMTSDataParameters { |
49 |
public static final String DYNCLASS_NAME = "WMTSDataParameters"; |
50 |
private static final String FIELD_SRS = "srs"; |
51 |
private static final String FIELD_IMAGE_FORMAT = "imageformat"; |
52 |
private static final String FIELD_INFO_FORMAT = "infoformat"; |
53 |
private static final String FIELD_LAYER = "layer"; |
54 |
private static final String FIELD_STYLE = "style"; |
55 |
private static final String FIELD_NAME = "name"; |
56 |
private static final String FIELD_SRSSTR = "srsstr"; |
57 |
private static final String FIELD_OVERRIDE = "override"; |
58 |
private static final String FIELD_CANCEL = "cancellable"; |
59 |
private static final String FIELD_EXTENT = "extent"; |
60 |
private static final String FIELD_WIDTH = "width"; |
61 |
private static final String FIELD_HEIGHT = "height"; |
62 |
private static final String FIELD_DELETECACHE = "deletecache"; |
63 |
|
64 |
private DelegatedDynObject delegatedDynObject = null; |
65 |
protected static DynClass DYNCLASS = null; |
66 |
|
67 |
public static void registerPersistence() { |
68 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
69 |
DynStruct definition = manager.getDefinition("WMTSDataParametersImpl_Persistent");
|
70 |
if( definition == null ) { |
71 |
definition = manager.addDefinition( |
72 |
WMTSDataParametersImpl.class, |
73 |
"WMTSDataParametersImpl_Persistent",
|
74 |
"WMTS DataParameters Persistency",
|
75 |
null,
|
76 |
null
|
77 |
); |
78 |
AbstractRasterDataParameters.registerPersistence(definition); |
79 |
|
80 |
definition.addDynFieldObject(FIELD_EXTENT).setClassOfValue(Rectangle2D.class).setMandatory(false); |
81 |
definition.addDynFieldInt(FIELD_WIDTH).setMandatory(false);
|
82 |
definition.addDynFieldInt(FIELD_HEIGHT).setMandatory(false);
|
83 |
definition.addDynFieldString(FIELD_IMAGE_FORMAT).setMandatory(false);
|
84 |
definition.addDynFieldString(FIELD_INFO_FORMAT).setMandatory(false);
|
85 |
definition.addDynFieldString(FIELD_NAME).setMandatory(false);
|
86 |
definition.addDynFieldString(FIELD_SRSSTR).setMandatory(false);
|
87 |
definition.addDynFieldBoolean(FIELD_OVERRIDE).setMandatory(false);
|
88 |
} |
89 |
} |
90 |
|
91 |
@Override
|
92 |
public void saveToState(PersistentState state) throws PersistenceException { |
93 |
super.saveToState(state);
|
94 |
|
95 |
state.set(FIELD_NAME, getName()); |
96 |
state.set(FIELD_SRSSTR, getSRSCode()); |
97 |
state.set(FIELD_OVERRIDE, isOverridingHost()); |
98 |
state.set(FIELD_EXTENT, getExtent()); |
99 |
state.set(FIELD_WIDTH, getWidth()); |
100 |
state.set(FIELD_HEIGHT, getHeight()); |
101 |
state.set(FIELD_IMAGE_FORMAT, getImageFormat()); |
102 |
state.set(FIELD_INFO_FORMAT, getInfoFormat()); |
103 |
//state.set(FIELD_DELETECACHE, isDeletingCache());
|
104 |
} |
105 |
|
106 |
@SuppressWarnings("unchecked") |
107 |
@Override
|
108 |
public void loadFromState(PersistentState state) |
109 |
throws PersistenceException {
|
110 |
super.loadFromState(state);
|
111 |
|
112 |
setImageFormat(state.getString(FIELD_IMAGE_FORMAT)); |
113 |
setInfoFormat(state.getString(FIELD_INFO_FORMAT)); |
114 |
setName(state.getString(FIELD_NAME)); |
115 |
setSRS(state.getString(FIELD_SRSSTR)); |
116 |
setOverrideHost(state.getBoolean(FIELD_OVERRIDE)); |
117 |
setExtent((Rectangle2D)state.get(FIELD_EXTENT));
|
118 |
setWidth(state.getInt(FIELD_WIDTH)); |
119 |
setHeight(state.getInt(FIELD_HEIGHT)); |
120 |
} |
121 |
|
122 |
public WMTSDataParametersImpl() {
|
123 |
super();
|
124 |
initialize(); |
125 |
} |
126 |
|
127 |
protected void initialize() { |
128 |
this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
|
129 |
.getDynObjectManager().createDynObject( |
130 |
DYNCLASS); |
131 |
} |
132 |
|
133 |
@SuppressWarnings("deprecation") |
134 |
public static void registerDynClass() { |
135 |
DynObjectManager dynman = ToolsLocator.getDynObjectManager(); |
136 |
DynClass dynClass; |
137 |
DynField field; |
138 |
|
139 |
if(dynman == null) |
140 |
return;
|
141 |
|
142 |
if (DYNCLASS == null) { |
143 |
dynClass = AbstractRasterDataParameters.registerDynClass(WMTSDataParametersImpl.DYNCLASS_NAME); |
144 |
|
145 |
field = dynClass.addDynField(FIELD_LAYER); |
146 |
field.setTheTypeOfAvailableValues(DynField.ANY); |
147 |
field.setDescription("Layer");
|
148 |
field.setType(DataTypes.OBJECT); |
149 |
field.setMandatory(false);
|
150 |
|
151 |
field = dynClass.addDynField(FIELD_STYLE); |
152 |
field.setTheTypeOfAvailableValues(DynField.ANY); |
153 |
field.setDescription("Style");
|
154 |
field.setType(DataTypes.OBJECT); |
155 |
field.setMandatory(false);
|
156 |
|
157 |
field = dynClass.addDynField(FIELD_SRS); |
158 |
field.setTheTypeOfAvailableValues(DynField.ANY); |
159 |
field.setDescription("SRS");
|
160 |
field.setType(DataTypes.CRS); |
161 |
field.setMandatory(false);
|
162 |
|
163 |
field = dynClass.addDynField(FIELD_IMAGE_FORMAT); |
164 |
field.setTheTypeOfAvailableValues(DynField.ANY); |
165 |
field.setDescription("Image Format");
|
166 |
field.setType(DataTypes.STRING); |
167 |
field.setMandatory(false);
|
168 |
|
169 |
field = dynClass.addDynField(FIELD_INFO_FORMAT); |
170 |
field.setTheTypeOfAvailableValues(DynField.ANY); |
171 |
field.setDescription("Info Format");
|
172 |
field.setType(DataTypes.STRING); |
173 |
field.setMandatory(false);
|
174 |
|
175 |
field = dynClass.addDynField(FIELD_NAME); |
176 |
field.setTheTypeOfAvailableValues(DynField.ANY); |
177 |
field.setDescription("Name");
|
178 |
field.setType(DataTypes.STRING); |
179 |
field.setMandatory(false);
|
180 |
|
181 |
field = dynClass.addDynField(FIELD_SRSSTR); |
182 |
field.setTheTypeOfAvailableValues(DynField.ANY); |
183 |
field.setDescription("String that represents the SRS");
|
184 |
field.setType(DataTypes.STRING); |
185 |
field.setMandatory(false);
|
186 |
|
187 |
field = dynClass.addDynField(FIELD_OVERRIDE); |
188 |
field.setTheTypeOfAvailableValues(DynField.ANY); |
189 |
field.setDescription("Override a host capabilities");
|
190 |
field.setType(DataTypes.BOOLEAN); |
191 |
field.setMandatory(false);
|
192 |
|
193 |
field = dynClass.addDynField(FIELD_CANCEL); |
194 |
field.setTheTypeOfAvailableValues(DynField.ANY); |
195 |
field.setDescription("Cancellable");
|
196 |
field.setType(DataTypes.OBJECT); |
197 |
field.setMandatory(false);
|
198 |
|
199 |
field = dynClass.addDynField(FIELD_EXTENT); |
200 |
field.setTheTypeOfAvailableValues(DynField.ANY); |
201 |
field.setDescription("Extent");
|
202 |
field.setType(DataTypes.OBJECT); |
203 |
field.setMandatory(false);
|
204 |
|
205 |
field = dynClass.addDynField(FIELD_WIDTH); |
206 |
field.setTheTypeOfAvailableValues(DynField.ANY); |
207 |
field.setDescription("Width");
|
208 |
field.setType(DataTypes.INT); |
209 |
field.setMandatory(false);
|
210 |
|
211 |
field = dynClass.addDynField(FIELD_HEIGHT); |
212 |
field.setTheTypeOfAvailableValues(DynField.ANY); |
213 |
field.setDescription("Height");
|
214 |
field.setType(DataTypes.INT); |
215 |
field.setMandatory(false);
|
216 |
|
217 |
field = dynClass.addDynField(FIELD_DELETECACHE); |
218 |
field.setTheTypeOfAvailableValues(DynField.ANY); |
219 |
field.setDescription("Flag to delete cache the next request");
|
220 |
field.setType(DataTypes.BOOLEAN); |
221 |
field.setMandatory(false);
|
222 |
|
223 |
DYNCLASS = dynClass; |
224 |
} |
225 |
|
226 |
} |
227 |
|
228 |
/**
|
229 |
* Sets the style selected
|
230 |
* @param layer
|
231 |
*/
|
232 |
public void setStyle(WMTSStyle layer) { |
233 |
this.setDynValue(FIELD_STYLE, layer);
|
234 |
} |
235 |
|
236 |
/**
|
237 |
* Gets the style
|
238 |
* @return
|
239 |
*/
|
240 |
public WMTSStyle getStyle() {
|
241 |
return (WMTSStyle) this.getDynValue(FIELD_STYLE); |
242 |
} |
243 |
|
244 |
/**
|
245 |
* Gets the image format
|
246 |
* @return Format
|
247 |
*/
|
248 |
public String getImageFormat() { |
249 |
return (String) this.getDynValue(FIELD_IMAGE_FORMAT); |
250 |
} |
251 |
|
252 |
/**
|
253 |
* Sets the image format
|
254 |
* @param format
|
255 |
*/
|
256 |
public void setImageFormat(String format) { |
257 |
this.setDynValue(FIELD_IMAGE_FORMAT, format);
|
258 |
} |
259 |
|
260 |
/*
|
261 |
* (non-Javadoc)
|
262 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.WMTSStoreParameters#getImageFormat()
|
263 |
*/
|
264 |
public String getInfoFormat() { |
265 |
return (String) this.getDynValue(FIELD_INFO_FORMAT); |
266 |
} |
267 |
|
268 |
/*
|
269 |
* (non-Javadoc)
|
270 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.WMTSStoreParameters#setImageFormat(java.lang.String)
|
271 |
*/
|
272 |
public void setInfoFormat(String format) { |
273 |
this.setDynValue(FIELD_INFO_FORMAT, format);
|
274 |
} |
275 |
|
276 |
/**
|
277 |
* Sets the layer selected
|
278 |
* @param layer
|
279 |
*/
|
280 |
public void setLayer(WMTSLayer layer) { |
281 |
this.setDynValue(FIELD_LAYER, layer);
|
282 |
} |
283 |
|
284 |
/**
|
285 |
* Gets the layer
|
286 |
* @return
|
287 |
*/
|
288 |
public WMTSLayer getLayer() {
|
289 |
return (WMTSLayer) this.getDynValue(FIELD_LAYER); |
290 |
} |
291 |
|
292 |
/**
|
293 |
* Devuelve el SRS.
|
294 |
* @return SRS.
|
295 |
*/
|
296 |
public String getSRSCode() { |
297 |
return (String) this.getDynValue(FIELD_SRSSTR); |
298 |
} |
299 |
|
300 |
public void setSRS(String m_srs) { |
301 |
this.setDynValue(FIELD_SRSSTR, m_srs);
|
302 |
setSRS(CRSFactory.getCRS(getEPSG(m_srs))); |
303 |
} |
304 |
|
305 |
public void setSRS(IProjection srs) { |
306 |
setDynValue(FIELD_SRS, srs); |
307 |
} |
308 |
|
309 |
/**
|
310 |
* Returns the projection
|
311 |
* @return
|
312 |
*/
|
313 |
public IProjection getSRS() {
|
314 |
if (this.getSRSID() == null) { |
315 |
return null; |
316 |
} |
317 |
return (IProjection) getDynValue(FIELD_SRS);
|
318 |
} |
319 |
|
320 |
/**
|
321 |
* Returns true if the layer is projected
|
322 |
* @return
|
323 |
*/
|
324 |
public boolean isProjected() { |
325 |
IProjection proj = getSRS(); |
326 |
if(proj == null) |
327 |
return true; |
328 |
else
|
329 |
return proj.isProjected();
|
330 |
} |
331 |
|
332 |
public String getSRSID() { |
333 |
IProjection srs = (IProjection) getDynValue(FIELD_SRS); |
334 |
if (srs == null) { |
335 |
return null; |
336 |
} |
337 |
return srs.getAbrev();
|
338 |
} |
339 |
|
340 |
public void setSRSID(String srsid) { |
341 |
if (srsid == null) { |
342 |
setDynValue(FIELD_SRS, null);
|
343 |
} else {
|
344 |
setDynValue(FIELD_SRS, CRSFactory.getCRS(getEPSG(srsid))); |
345 |
} |
346 |
} |
347 |
|
348 |
/**
|
349 |
* Returns the current selected SRS.
|
350 |
* @return
|
351 |
*/
|
352 |
public String getEPSG(String value) { |
353 |
if(value != null) { |
354 |
String s = value.substring(value.lastIndexOf(":") + 1); |
355 |
return "EPSG:" + s; |
356 |
} |
357 |
return null; |
358 |
} |
359 |
|
360 |
public String getName() { |
361 |
return (String) this.getDynValue(FIELD_NAME); |
362 |
} |
363 |
|
364 |
public void setName(String name) { |
365 |
this.setDynValue(FIELD_NAME, name);
|
366 |
} |
367 |
|
368 |
public void setCancellable(ICancellable cancel) { |
369 |
this.setDynValue(FIELD_CANCEL, cancel);
|
370 |
} |
371 |
|
372 |
public ICancellable getCancellable() {
|
373 |
return (ICancellable) this.getDynValue(FIELD_CANCEL); |
374 |
} |
375 |
|
376 |
/*
|
377 |
* (non-Javadoc)
|
378 |
* @see org.gvsig.fmap.dal.coverage.store.RasterStoreParameters#isOverridingHost()
|
379 |
*/
|
380 |
public boolean isOverridingHost() { |
381 |
Boolean b = (Boolean)getDynValue(FIELD_OVERRIDE); |
382 |
if(b != null) |
383 |
return ((Boolean)b).booleanValue(); |
384 |
return false; |
385 |
} |
386 |
|
387 |
/*
|
388 |
* (non-Javadoc)
|
389 |
* @see org.gvsig.fmap.dal.coverage.store.RasterStoreParameters#setOverrideHost(boolean)
|
390 |
*/
|
391 |
public void setOverrideHost(boolean over) { |
392 |
this.setDynValue(FIELD_OVERRIDE, new Boolean(over));; |
393 |
} |
394 |
|
395 |
/**
|
396 |
* Assigns the extent.
|
397 |
* When a provider is initialized this will need to know what is the extent before the request.
|
398 |
*
|
399 |
* @param bBox
|
400 |
*/
|
401 |
public void setExtent(Rectangle2D bBox) { |
402 |
this.setDynValue(FIELD_EXTENT, bBox);
|
403 |
} |
404 |
|
405 |
/**
|
406 |
* Sets the width
|
407 |
* When a provider is initialized this will need to know what is the width before the request.
|
408 |
* @param w
|
409 |
*/
|
410 |
public void setWidth(int w) { |
411 |
this.setDynValue(FIELD_WIDTH, new Integer(w)); |
412 |
} |
413 |
|
414 |
/**
|
415 |
* Sets the height
|
416 |
* When a provider is initialized this will need to know what is the height before the request.
|
417 |
* @param h
|
418 |
*/
|
419 |
public void setHeight(int h) { |
420 |
this.setDynValue(FIELD_HEIGHT, new Integer(h)); |
421 |
} |
422 |
|
423 |
/**
|
424 |
* Gets the bounding box
|
425 |
* @return
|
426 |
*/
|
427 |
public Rectangle2D getExtent() { |
428 |
return (Rectangle2D)getDynValue(FIELD_EXTENT); |
429 |
} |
430 |
|
431 |
/**
|
432 |
* Gets the width
|
433 |
* @return
|
434 |
*/
|
435 |
public int getWidth() { |
436 |
Integer b = (Integer)getDynValue(FIELD_WIDTH); |
437 |
if(b != null) |
438 |
return ((Integer)b).intValue(); |
439 |
return 0; |
440 |
} |
441 |
|
442 |
/**
|
443 |
* Gets the height
|
444 |
* @return
|
445 |
*/
|
446 |
public int getHeight() { |
447 |
Integer b = (Integer)getDynValue(FIELD_HEIGHT); |
448 |
if(b != null) |
449 |
return ((Integer)b).intValue(); |
450 |
return 0; |
451 |
} |
452 |
|
453 |
//**********************************************
|
454 |
|
455 |
/*
|
456 |
* (non-Javadoc)
|
457 |
* @see org.gvsig.fmap.dal.DataStoreParameters#getDataStoreName()
|
458 |
*/
|
459 |
public String getDataStoreName() { |
460 |
return WMTSProvider.NAME;
|
461 |
} |
462 |
|
463 |
/*
|
464 |
* (non-Javadoc)
|
465 |
* @see org.gvsig.fmap.dal.DataStoreParameters#getDescription()
|
466 |
*/
|
467 |
public String getDescription() { |
468 |
return WMTSProvider.DESCRIPTION;
|
469 |
} |
470 |
|
471 |
public String getExplorerName() { |
472 |
return WMTSServerExplorer.NAME;
|
473 |
} |
474 |
|
475 |
public boolean isValid() { |
476 |
return (this.getURI() != null); |
477 |
} |
478 |
|
479 |
protected DelegatedDynObject getDelegatedDynObject() {
|
480 |
return delegatedDynObject;
|
481 |
} |
482 |
|
483 |
/**
|
484 |
* Clones this structure
|
485 |
* @return
|
486 |
*/
|
487 |
public WMTSDataParameters clone() {
|
488 |
WMTSDataParametersImpl p = new WMTSDataParametersImpl();
|
489 |
p.setImageFormat(getImageFormat()); |
490 |
p.setInfoFormat(getInfoFormat()); |
491 |
p.setHeight(getHeight()); |
492 |
p.setWidth(getWidth()); |
493 |
p.setExtent(getExtent()); |
494 |
p.setURI(getURI()); |
495 |
p.setName(getName()); |
496 |
p.setOverrideHost(isOverridingHost()); |
497 |
p.setSRS(getSRS()); |
498 |
p.setSRS(getSRSCode()); |
499 |
p.setCancellable(getCancellable()); |
500 |
return p;
|
501 |
} |
502 |
|
503 |
/*
|
504 |
* (non-Javadoc)
|
505 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.RemoteStoreParameters#isSizeFixed()
|
506 |
*/
|
507 |
public boolean isSizeFixed() { |
508 |
return true; |
509 |
} |
510 |
|
511 |
public void deleteCache(boolean deleteCache) { |
512 |
this.setDynValue(FIELD_DELETECACHE, new Boolean(deleteCache)); |
513 |
} |
514 |
|
515 |
public boolean isDeletingCache() { |
516 |
return ((Boolean)getDynValue(FIELD_DELETECACHE)).booleanValue(); |
517 |
} |
518 |
|
519 |
} |