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 @ 3325

History | View | Annotate | Download (14 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.coverage.store.RasterDataServerExplorer;
35
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
36
import org.gvsig.raster.impl.store.AbstractRasterDataParameters;
37
import org.gvsig.tools.ToolsLocator;
38
import org.gvsig.tools.dynobject.DelegatedDynObject;
39
import org.gvsig.tools.dynobject.DynClass;
40
import org.gvsig.tools.dynobject.DynStruct;
41
import org.gvsig.tools.persistence.PersistenceManager;
42

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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