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