Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wms / trunk / org.gvsig.raster.wms / org.gvsig.raster.wms.io / src / main / java / org / gvsig / raster / wms / io / WMSDataParametersImpl.java @ 22299

History | View | Annotate | Download (14.1 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.wms.io;
24

    
25
import java.awt.Dimension;
26
import java.awt.geom.Rectangle2D;
27
import java.util.Hashtable;
28
import java.util.List;
29
import java.util.Map;
30
import java.util.Vector;
31

    
32
import org.gvsig.compat.net.ICancellable;
33
import org.gvsig.fmap.crs.CRSFactory;
34
import org.gvsig.fmap.dal.DataStoreParameters;
35
import org.gvsig.fmap.dal.coverage.store.RasterDataServerExplorer;
36
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
37
import org.gvsig.raster.impl.store.AbstractRasterDataParameters;
38
import org.gvsig.tools.ToolsLocator;
39
import org.gvsig.tools.dynobject.DelegatedDynObject;
40
import org.gvsig.tools.dynobject.DynClass;
41
import org.gvsig.tools.dynobject.DynStruct;
42
import org.gvsig.tools.persistence.PersistenceManager;
43

    
44
/**
45
 * Parameters for the WMS provider
46
 * @author Nacho Brodin (nachobrodin@gmail.com)
47
 */
48
public class WMSDataParametersImpl extends AbstractRasterDataParameters implements WMSDataParameters {
49
        private static final String      FIELD_FORMAT          = "format";
50
        private static final String      FIELD_INFOFORMAT      = "infoformat";
51
        public static final String      FIELD_LAYERQUERY      = "layer_query";
52
        private static final String      FIELD_NAME            = "name";
53
        private static final String      FIELD_SRSSTR          = "srsstr";
54
        private static final String      FIELD_TRANSPARENCY    = "transparency";
55
        private static final String      FIELD_INFOLAYERQUERY  = "infolayerquery";
56
        private static final String      FIELD_QUERYABLE       = "queryable";
57
        private static final String      FIELD_OVERRIDE        = "override";
58
        private static final String      FIELD_STYLES          = "styles";
59
        private static final String      FIELD_DIMENSIONS      = "dimensions";
60
        private static final String      FIELD_ONLINERESOURC   = "onlineresources";
61
        private static final String      FIELD_FIXEDSIZE       = "fixedsize";
62
        private static final String      FIELD_EXTENT          = "extent";
63
        private static final String      FIELD_WIDTH           = "width";
64
        private static final String      FIELD_HEIGHT          = "height";
65
        private static final String      FIELD_DELETECACHE     = "deletecache";
66
        private static final String      FIELD_ASSUMEXYAXISORDER = "assumeXY";
67
        
68
        private DelegatedDynObject       delegatedDynObject    = null;
69
        protected static DynClass        DYNCLASS              = null;
70
        private ICancellable             cancel                = null;
71
        
72
        public WMSDataParametersImpl() {
73
                super();
74
                initialize();
75
        }
76
        
77
        protected void initialize() {
78
                this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
79
                                .getDynObjectManager().createDynObject(registerDynClass());
80
        }
81
        
82
        public static DynStruct registerDynClass() {
83
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
84
                DynStruct definition = manager.getDefinition("WMSDataParameters_Persistent");
85
                if( definition == null ) {
86
                        definition = manager.addDefinition(
87
                                        WMSDataParametersImpl.class,
88
                                        "WMSDataParameters_Persistent",
89
                                        "WMS DataParameters Persistency",
90
                                        null, 
91
                                        null
92
                        );
93
                }
94

    
95
                AbstractRasterDataParameters.registerDynClass(definition);
96
                
97
                definition.addDynFieldObject(FIELD_EXTENT)
98
                .setDescription("Bounding box")
99
                .setClassOfValue(Rectangle2D.class)
100
                .setMandatory(false);
101
                
102
                definition.addDynFieldInt(FIELD_WIDTH)
103
                .setDescription("Width")
104
                .setMandatory(false);
105
                
106
                definition.addDynFieldInt(FIELD_HEIGHT)
107
                .setDescription("Height")
108
                .setMandatory(false);
109
                
110
                definition.addDynFieldString(FIELD_FORMAT)
111
                .setDescription("Format")
112
                .setMandatory(false);
113
                
114
                definition.addDynFieldString(FIELD_INFOFORMAT)
115
                .setDescription("Info by point format")
116
                .setMandatory(false);
117
                
118
                definition.addDynFieldString(FIELD_LAYERQUERY)
119
                .setDescription("Layer Query")
120
                .setMandatory(false);
121
                
122
                definition.addDynFieldString(FIELD_NAME)
123
                .setDescription("Name")
124
                .setMandatory(false);                        
125
                
126
                definition.addDynFieldString(FIELD_SRSSTR)
127
                .setDescription("String that represents the SRS")
128
                .setMandatory(false);
129
                
130
                definition.addDynFieldBoolean(FIELD_TRANSPARENCY)
131
                .setDescription("Transparency")
132
                .setMandatory(false);
133
                
134
                definition.addDynFieldString(FIELD_INFOLAYERQUERY)
135
                .setDescription("InfoLayerQuery")
136
                .setMandatory(false);
137
                
138
                definition.addDynFieldBoolean(FIELD_QUERYABLE)
139
                .setDescription("Queryable")
140
                .setMandatory(false);
141
                
142
                definition.addDynFieldBoolean(FIELD_OVERRIDE)
143
                .setDescription("Override a host capabilities")
144
                .setMandatory(false);
145
                
146
                definition.addDynFieldList(FIELD_STYLES)
147
                .setDescription("Styles")
148
                .setClassOfItems(RemoteWMSStyle.class)
149
                .setMandatory(false);
150
                
151
                definition.addDynFieldList(FIELD_DIMENSIONS)
152
                .setDescription("Dimensions")
153
                .setClassOfItems(String.class)
154
                .setMandatory(false);
155
                
156
                definition.addDynFieldMap(FIELD_ONLINERESOURC)
157
                .setDescription("online resources")
158
                .setClassOfItems(String.class)
159
                .setMandatory(false);
160
                
161
                definition.addDynFieldObject(FIELD_FIXEDSIZE)
162
                .setDescription("Fixed size")
163
                .setClassOfValue(Dimension.class)
164
                .setMandatory(false);
165
                
166
                definition.addDynFieldBoolean(FIELD_DELETECACHE)
167
                .setDescription("Flag to delete cache the next request")
168
                .setMandatory(false);
169

    
170
                definition.addDynFieldBoolean(FIELD_ASSUMEXYAXISORDER)
171
                .setDescription("Flag to decide the axis order behaviour")
172
                .setMandatory(false);
173

    
174
                return definition;
175
        }
176
        
177
        /**
178
         * Gets the format
179
         * @return
180
         */
181
        public String getFormat() {
182
                return (String) this.getDynValue(FIELD_FORMAT);
183
        }
184

    
185
        /**
186
         * Sets the format
187
         * @param format
188
         */
189
        public void setFormat(String format) {
190
                this.setDynValue(FIELD_FORMAT, format);
191
        }
192
        
193
        /**
194
         * Gets the info by point format
195
         * @return
196
         */
197
        public String getInfoFormat() {
198
                String o = (String) this.getDynValue(FIELD_INFOFORMAT);
199
                if(o == null)
200
                        return "text/plain";
201
                return o;
202
        }
203

    
204
        /**
205
         * Sets the info by point format
206
         */
207
        public void setInfoFormat(String format) {
208
                this.setDynValue(FIELD_INFOFORMAT, format);
209
        }
210
        
211
        public String getLayerQuery() {
212
                return (String) this.getDynValue(FIELD_LAYERQUERY);
213
        }
214

    
215
        public void setLayerQuery(String layerQuery) {
216
                this.setDynValue(FIELD_LAYERQUERY, layerQuery);
217
        }
218
        
219
        /**
220
         * Devuelve el SRS.
221
         * @return SRS.
222
         */
223
        public String getSRSCode() {
224
                return (String) this.getDynValue(FIELD_SRSSTR);
225
        }
226
        
227
        /**
228
         * Inserta el SRS.
229
         * @param m_srs SRS.
230
         */
231
        public void setSRS(String m_srs) {
232
                this.setDynValue(FIELD_SRSSTR, m_srs);
233
                if(m_srs.equals("CRS:84"))
234
                        m_srs = "EPSG:4326";
235
                setSRS(CRSFactory.getCRS(m_srs));
236
        }
237
        
238
        public void setSRSID(String srsid) {
239
                if (srsid == null) {
240
                        setDynValue(FIELD_SRSSTR, null);
241
                } else {
242
                        setDynValue(FIELD_SRSSTR, CRSFactory.getCRS(srsid));
243
                }
244
        }
245
        
246
        public String getName() {
247
                return (String) this.getDynValue(FIELD_NAME);
248
        }
249

    
250
        public void setName(String name) {
251
                this.setDynValue(FIELD_NAME, name);
252
        }
253
        
254
        public boolean isWmsTransparent() {
255
                Boolean b = (Boolean)getDynValue(FIELD_TRANSPARENCY);
256
                if(b != null)
257
                        return ((Boolean)b).booleanValue();
258
                return false;
259
        }
260

    
261
        /**
262
         * @param wmsTransparency The wmsTransparency to set.
263
         */
264
        public void setWmsTransparency(boolean wmsTransparency) {
265
                this.setDynValue(FIELD_TRANSPARENCY, new Boolean(wmsTransparency));
266
        }
267
        
268
        public String getInfoLayerQuery() {
269
                return (String) this.getDynValue(FIELD_INFOLAYERQUERY);
270
        }
271

    
272
        public void setInfoLayerQuery(String infoLayerQuery) {
273
                this.setDynValue(FIELD_INFOLAYERQUERY, infoLayerQuery);
274
        }
275
        
276

    
277
        /**
278
         * If it is true, this layer accepts GetFeatureInfo operations. This WMS operations
279
         * maps to FMap's infoByPoint(p) operation.
280
         * @param b
281
         */
282
        public void setQueryable(boolean b) {
283
                this.setDynValue(FIELD_QUERYABLE, new Boolean(b));
284
        }
285
        
286
        public void setCancellable(ICancellable cancel) {
287
                this.cancel = cancel;
288
        }
289
        
290
        public ICancellable getCancellable() {
291
                return cancel;
292
        }
293
        
294
        public boolean isQueryable() {
295
                Boolean b = (Boolean)getDynValue(FIELD_QUERYABLE);
296
                if(b != null)
297
                        return ((Boolean)b).booleanValue();
298
                return false;
299
        }
300
        
301
        public boolean isOverridingHost() {
302
                Boolean b = (Boolean)getDynValue(FIELD_OVERRIDE);
303
                if(b != null)
304
                        return ((Boolean)b).booleanValue();
305
                return false;
306
        }
307
        
308
        public void setOverrideHost(boolean over) {
309
                this.setDynValue(FIELD_OVERRIDE, new Boolean(over));;
310
        }
311
        
312
        public void setStyles(List<RemoteWMSStyle> styles) {
313
                this.setDynValue(FIELD_STYLES, styles);
314
        }
315
        
316
        /**
317
         * @param styles
318
         */
319
        @SuppressWarnings("unchecked")
320
        public List<RemoteWMSStyle> getStyles() {
321
                return (List<RemoteWMSStyle>) this.getDynValue(FIELD_STYLES);
322
        }
323
        
324
        public void setDimensions(Vector<String> dimensions) {
325
                this.setDynValue(FIELD_DIMENSIONS, dimensions);
326
        }
327
        
328
        /**
329
         * Gets the dimension vector that is a list of key-value pairs containing
330
         * the name of the dimension and the value for it
331
         * @return
332
         */
333
        @SuppressWarnings("unchecked")
334
        public Vector<String> getDimensions() {
335
                return (Vector<String>) this.getDynValue(FIELD_DIMENSIONS);
336
        }
337

    
338
        public void setOnlineResources(Map<String, String> onlineResources) {
339
                this.setDynValue(FIELD_ONLINERESOURC, onlineResources);
340
        }
341
        
342
        public String getOnlineResource(String operation) {
343
                return (String) getOnlineResource().get(operation);
344
        }
345
        
346
        @SuppressWarnings("unchecked")
347
        public Map<String,String> getOnlineResource() {
348
                return (Map<String,String>) this.getDynValue(FIELD_ONLINERESOURC);
349
        }
350
        
351
        /**
352
         * When a server is not fully featured and it only can serve constant map
353
         * sizes this value must be set. It expresses the size in pixels (width, height)
354
         * that the map will be requested.
355
         * @param Dimension sz
356
         */
357
        public void setFixedSize(Dimension sz) {
358
                this.setDynValue(FIELD_FIXEDSIZE, sz);
359
        }
360

    
361
        /**
362
         * Tells whether if this layer must deal with the server with the constant-size
363
         * limitations or not.
364
         * @return boolean.
365
         */
366
        public boolean isSizeFixed() {
367
                return (getDynValue(FIELD_FIXEDSIZE) != null);
368
        }
369
        
370
        /**
371
         * Gets the value of the fixed size
372
         * @return
373
         */
374
        public Dimension getFixedSize() {
375
                return (Dimension) this.getDynValue(FIELD_FIXEDSIZE);
376
        }
377
        
378
        /**
379
         * Assigns the extent. 
380
         * When a provider is initialized this will need to know what is the extent before the request.
381
         * 
382
         * @param bBox
383
         */
384
        public void setExtent(Rectangle2D bBox) {
385
                this.setDynValue(FIELD_EXTENT, bBox);
386
        }
387
        
388
        public void setWidth(int w) {
389
                this.setDynValue(FIELD_WIDTH, new Integer(w));
390
        }
391
        
392
        public void setHeight(int h) {
393
                this.setDynValue(FIELD_HEIGHT, new Integer(h));
394
        }
395
        
396
        /**
397
         * Gets the bounding box
398
         * @return
399
         */
400
        public Rectangle2D getExtent() {
401
                return (Rectangle2D)getDynValue(FIELD_EXTENT);
402
        }
403
        
404
        /**
405
         * Gets the width
406
         * @return
407
         */
408
        public int getWidth() {
409
                Integer b = (Integer)getDynValue(FIELD_WIDTH);
410
                if(b != null)
411
                        return ((Integer)b).intValue();
412
                return 0;
413
        }
414
        
415
        /**
416
         * Gets the height
417
         * @return
418
         */
419
        public int getHeight() {
420
                Integer b = (Integer)getDynValue(FIELD_HEIGHT);
421
                if(b != null)
422
                        return ((Integer)b).intValue();
423
                return 0;
424
        }
425
        
426
        
427
        //**********************************************
428
        
429
        public String getDataStoreName() {
430
                return WMSProvider.NAME;
431
        }
432
        
433
        public String getDescription() {
434
                return WMSProvider.DESCRIPTION;
435
        }
436

    
437
        public String getExplorerName() {
438
                return WMSServerExplorer.NAME;
439
        }
440
        
441
        public boolean isValid() {
442
                return (this.getURI() != null);
443
        }
444
        
445
        protected DelegatedDynObject getDelegatedDynObject() {
446
                return delegatedDynObject;
447
        }
448
        
449
        public void deleteCache(boolean deleteCache) {
450
                this.setDynValue(FIELD_DELETECACHE, new Boolean(deleteCache));
451
        }
452
        
453
        public boolean isDeletingCache() {
454
                return ((Boolean)getDynValue(FIELD_DELETECACHE)).booleanValue();
455
        }
456
        
457
        @SuppressWarnings("unchecked")
458
        public WMSDataParameters clone() {
459
                WMSDataParametersImpl p = new WMSDataParametersImpl();
460
                p.setFormat(getFormat());
461
                p.setFixedSize(getFixedSize());
462
                p.setHeight(getHeight());
463
                p.setWidth(getWidth());
464
                p.setExtent(getExtent());
465
                p.setURI(getURI());
466
                p.setInfoLayerQuery(getInfoLayerQuery());
467
                p.setLayerQuery(getLayerQuery());
468
                p.setName(getName());
469
                p.setOnlineResources((Hashtable<String, String>)this.getDynValue(FIELD_ONLINERESOURC));
470
                p.setOverrideHost(isOverridingHost());
471
                p.setQueryable(isQueryable());
472
                p.setSRS(getSRS());
473
                p.setSRS(getSRSCode());
474
                p.setStyles(getStyles());
475
                p.setWmsTransparency(isWmsTransparent());
476
                p.setDimensions(getDimensions());
477
                p.setCancellable(getCancellable());
478
                p.setXyAxisOrder(isXyAxisOrder());
479
                return p;
480
        }
481
        
482
        public void assignFields(RasterDataParameters par, RasterDataServerExplorer explorer) {
483
                super.assignFields(par, explorer);
484
                WMSDataParametersImpl p = null;
485
                if(par instanceof WMSDataParametersImpl)
486
                        p = (WMSDataParametersImpl)par;
487
                else
488
                        return;
489
                setFormat(p.getFormat());
490
                setFixedSize(p.getFixedSize());
491
                setHeight(p.getHeight());
492
                setWidth(p.getWidth());
493
                setExtent(p.getExtent());
494
                setURI(p.getURI());
495
                setInfoLayerQuery(p.getInfoLayerQuery());
496
                setLayerQuery(p.getLayerQuery());
497
                setName(getName());
498
                setOnlineResources((Map<String, String>)p.getDynValue(FIELD_ONLINERESOURC));
499
                setOverrideHost(p.isOverridingHost());
500
                setQueryable(p.isQueryable());
501
                setSRS(p.getSRSCode());
502
                setStyles(p.getStyles());
503
                setWmsTransparency(p.isWmsTransparent());
504
                setDimensions(p.getDimensions());
505
                setCancellable(p.getCancellable());
506
                setXyAxisOrder(p.isXyAxisOrder());
507
        }
508

    
509
        public boolean isXyAxisOrder() {
510
                Boolean b = (Boolean)getDynValue(FIELD_ASSUMEXYAXISORDER);
511
                if(b != null)
512
                        return b.booleanValue();
513
                return false;
514
        }
515

    
516
        public void setXyAxisOrder(boolean assumeXY) {
517
                setDynValue(FIELD_ASSUMEXYAXISORDER, assumeXY);
518
        }
519

    
520
}