Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wms / branches / org.gvsig.raster.wms_dataaccess_refactoring / org.gvsig.raster.wms.io / src / main / java / org / gvsig / raster / wms / io / WMSDataParametersImpl.java @ 2378

History | View | Annotate | Download (14.4 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
        
66
        private DelegatedDynObject       delegatedDynObject    = null;
67
        protected static DynClass        DYNCLASS              = null;
68
        private ICancellable             cancel                = null;
69
        
70
        public WMSDataParametersImpl() {
71
                super();
72
                initialize();
73
        }
74
        
75
        protected void initialize() {
76
                this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
77
                                .getDynObjectManager().createDynObject(registerDynClass());
78
        }
79
        
80
        public static DynStruct registerDynClass() {
81
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
82
                DynStruct definition = manager.getDefinition("WMSDataParameters_Persistent");
83
                if( definition == null ) {
84
                        definition = manager.addDefinition(
85
                                        WMSDataParametersImpl.class,
86
                                        "WMSDataParameters_Persistent",
87
                                        "WMS DataParameters Persistency",
88
                                        null, 
89
                                        null
90
                        );
91
                }
92

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

    
168
                return definition;
169
        }
170
        
171
        
172
        /*@SuppressWarnings("unchecked")
173
        @Override
174
        public void loadFromState(PersistentState state)
175
                        throws PersistenceException {
176
                super.loadFromState(state);
177
                
178
                if (state.hasValue(FIELD_STYLES)) {
179
                        List<RemoteWMSStyle> styleList = state.getList(FIELD_STYLES);
180
                        if(styleList != null) {
181
                                Vector<RemoteWMSStyle> v = new Vector<RemoteWMSStyle>();
182
                                v.addAll(styleList);
183
                                setStyles(v);
184
                        }
185
                }
186
                if (state.hasValue(FIELD_DIMENSIONS)) {
187
                        List<String> dimList = state.getList(FIELD_DIMENSIONS);
188
                        if(dimList != null) {
189
                                Vector<String> v = new Vector<String>();
190
                                v.addAll(dimList);
191
                                setDimensions(v);
192
                        }
193
                }
194
                
195
                if(state.getMap(FIELD_ONLINERESOURC) != null)
196
                        setOnlineResources(new Hashtable<String, String>(state.getMap(FIELD_ONLINERESOURC)));
197
                
198
                if (state.hasValue(FIELD_FIXEDSIZE)) {
199
                        setFixedSize((Dimension) state.get(FIELD_FIXEDSIZE));
200
                } else {
201
                        setFixedSize(null);
202
                }
203
                setExtent((Rectangle2D)state.get(FIELD_EXTENT));
204
        }*/
205
        
206
        /**
207
         * Gets the format
208
         * @return
209
         */
210
        public String getFormat() {
211
                return (String) this.getDynValue(FIELD_FORMAT);
212
        }
213

    
214
        /**
215
         * Sets the format
216
         * @param format
217
         */
218
        public void setFormat(String format) {
219
                this.setDynValue(FIELD_FORMAT, format);
220
        }
221
        
222
        /**
223
         * Gets the info by point format
224
         * @return
225
         */
226
        public String getInfoFormat() {
227
                String o = (String) this.getDynValue(FIELD_INFOFORMAT);
228
                if(o == null)
229
                        return "text/plain";
230
                return o;
231
        }
232

    
233
        /**
234
         * Sets the info by point format
235
         */
236
        public void setInfoFormat(String format) {
237
                this.setDynValue(FIELD_INFOFORMAT, format);
238
        }
239
        
240
        public String getLayerQuery() {
241
                return (String) this.getDynValue(FIELD_LAYERQUERY);
242
        }
243

    
244
        public void setLayerQuery(String layerQuery) {
245
                this.setDynValue(FIELD_LAYERQUERY, layerQuery);
246
        }
247
        
248
        /**
249
         * Devuelve el SRS.
250
         * @return SRS.
251
         */
252
        public String getSRSCode() {
253
                return (String) this.getDynValue(FIELD_SRSSTR);
254
        }
255
        
256
        /**
257
         * Inserta el SRS.
258
         * @param m_srs SRS.
259
         */
260
        public void setSRS(String m_srs) {
261
                this.setDynValue(FIELD_SRSSTR, m_srs);
262
                if(m_srs.equals("CRS:84"))
263
                        m_srs = "EPSG:4326";
264
                setSRS(CRSFactory.getCRS(m_srs));
265
        }
266
        
267
        public void setSRSID(String srsid) {
268
                if (srsid == null) {
269
                        setDynValue(FIELD_SRSSTR, null);
270
                } else {
271
                        setDynValue(FIELD_SRSSTR, CRSFactory.getCRS(srsid));
272
                }
273
        }
274
        
275
        public String getName() {
276
                return (String) this.getDynValue(FIELD_NAME);
277
        }
278

    
279
        public void setName(String name) {
280
                this.setDynValue(FIELD_NAME, name);
281
        }
282
        
283
        public boolean isWmsTransparent() {
284
                Boolean b = (Boolean)getDynValue(FIELD_TRANSPARENCY);
285
                if(b != null)
286
                        return ((Boolean)b).booleanValue();
287
                return false;
288
        }
289

    
290
        /**
291
         * @param wmsTransparency The wmsTransparency to set.
292
         */
293
        public void setWmsTransparency(boolean wmsTransparency) {
294
                this.setDynValue(FIELD_TRANSPARENCY, new Boolean(wmsTransparency));
295
        }
296
        
297
        public String getInfoLayerQuery() {
298
                return (String) this.getDynValue(FIELD_INFOLAYERQUERY);
299
        }
300

    
301
        public void setInfoLayerQuery(String infoLayerQuery) {
302
                this.setDynValue(FIELD_INFOLAYERQUERY, infoLayerQuery);
303
        }
304
        
305

    
306
        /**
307
         * If it is true, this layer accepts GetFeatureInfo operations. This WMS operations
308
         * maps to FMap's infoByPoint(p) operation.
309
         * @param b
310
         */
311
        public void setQueryable(boolean b) {
312
                this.setDynValue(FIELD_QUERYABLE, new Boolean(b));
313
        }
314
        
315
        public void setCancellable(ICancellable cancel) {
316
                this.cancel = cancel;
317
        }
318
        
319
        public ICancellable getCancellable() {
320
                return cancel;
321
        }
322
        
323
        public boolean isQueryable() {
324
                Boolean b = (Boolean)getDynValue(FIELD_QUERYABLE);
325
                if(b != null)
326
                        return ((Boolean)b).booleanValue();
327
                return false;
328
        }
329
        
330
        public boolean isOverridingHost() {
331
                Boolean b = (Boolean)getDynValue(FIELD_OVERRIDE);
332
                if(b != null)
333
                        return ((Boolean)b).booleanValue();
334
                return false;
335
        }
336
        
337
        public void setOverrideHost(boolean over) {
338
                this.setDynValue(FIELD_OVERRIDE, new Boolean(over));;
339
        }
340
        
341
        public void setStyles(List<RemoteWMSStyle> styles) {
342
                this.setDynValue(FIELD_STYLES, styles);
343
        }
344
        
345
        /**
346
         * @param styles
347
         */
348
        @SuppressWarnings("unchecked")
349
        public List<RemoteWMSStyle> getStyles() {
350
                return (List<RemoteWMSStyle>) this.getDynValue(FIELD_STYLES);
351
        }
352
        
353
        public void setDimensions(Vector<String> dimensions) {
354
                this.setDynValue(FIELD_DIMENSIONS, dimensions);
355
        }
356
        
357
        /**
358
         * Gets the dimension vector that is a list of key-value pairs containing
359
         * the name of the dimension and the value for it
360
         * @return
361
         */
362
        @SuppressWarnings("unchecked")
363
        public Vector<String> getDimensions() {
364
                return (Vector<String>) this.getDynValue(FIELD_DIMENSIONS);
365
        }
366

    
367
        public void setOnlineResources(Map<String, String> onlineResources) {
368
                this.setDynValue(FIELD_ONLINERESOURC, onlineResources);
369
        }
370
        
371
        public String getOnlineResource(String operation) {
372
                return (String) getOnlineResource().get(operation);
373
        }
374
        
375
        @SuppressWarnings("unchecked")
376
        public Map<String,String> getOnlineResource() {
377
                return (Map<String,String>) this.getDynValue(FIELD_ONLINERESOURC);
378
        }
379
        
380
        /**
381
         * When a server is not fully featured and it only can serve constant map
382
         * sizes this value must be set. It expresses the size in pixels (width, height)
383
         * that the map will be requested.
384
         * @param Dimension sz
385
         */
386
        public void setFixedSize(Dimension sz) {
387
                this.setDynValue(FIELD_FIXEDSIZE, sz);
388
        }
389

    
390
        /**
391
         * Tells whether if this layer must deal with the server with the constant-size
392
         * limitations or not.
393
         * @return boolean.
394
         */
395
        public boolean isSizeFixed() {
396
                return (getDynValue(FIELD_FIXEDSIZE) != null);
397
        }
398
        
399
        /**
400
         * Gets the value of the fixed size
401
         * @return
402
         */
403
        public Dimension getFixedSize() {
404
                return (Dimension) this.getDynValue(FIELD_FIXEDSIZE);
405
        }
406
        
407
        /**
408
         * Assigns the extent. 
409
         * When a provider is initialized this will need to know what is the extent before the request.
410
         * 
411
         * @param bBox
412
         */
413
        public void setExtent(Rectangle2D bBox) {
414
                this.setDynValue(FIELD_EXTENT, bBox);
415
        }
416
        
417
        public void setWidth(int w) {
418
                this.setDynValue(FIELD_WIDTH, new Integer(w));
419
        }
420
        
421
        public void setHeight(int h) {
422
                this.setDynValue(FIELD_HEIGHT, new Integer(h));
423
        }
424
        
425
        /**
426
         * Gets the bounding box
427
         * @return
428
         */
429
        public Rectangle2D getExtent() {
430
                return (Rectangle2D)getDynValue(FIELD_EXTENT);
431
        }
432
        
433
        /**
434
         * Gets the width
435
         * @return
436
         */
437
        public int getWidth() {
438
                Integer b = (Integer)getDynValue(FIELD_WIDTH);
439
                if(b != null)
440
                        return ((Integer)b).intValue();
441
                return 0;
442
        }
443
        
444
        /**
445
         * Gets the height
446
         * @return
447
         */
448
        public int getHeight() {
449
                Integer b = (Integer)getDynValue(FIELD_HEIGHT);
450
                if(b != null)
451
                        return ((Integer)b).intValue();
452
                return 0;
453
        }
454
        
455
        
456
        //**********************************************
457
        
458
        public String getDataStoreName() {
459
                return WMSProvider.NAME;
460
        }
461
        
462
        public String getDescription() {
463
                return WMSProvider.DESCRIPTION;
464
        }
465

    
466
        public String getExplorerName() {
467
                return WMSServerExplorer.NAME;
468
        }
469
        
470
        public boolean isValid() {
471
                return (this.getURI() != null);
472
        }
473
        
474
        protected DelegatedDynObject getDelegatedDynObject() {
475
                return delegatedDynObject;
476
        }
477
        
478
        public void deleteCache(boolean deleteCache) {
479
                this.setDynValue(FIELD_DELETECACHE, new Boolean(deleteCache));
480
        }
481
        
482
        public boolean isDeletingCache() {
483
                return ((Boolean)getDynValue(FIELD_DELETECACHE)).booleanValue();
484
        }
485
        
486
        @SuppressWarnings("unchecked")
487
        public WMSDataParameters clone() {
488
                WMSDataParametersImpl p = new WMSDataParametersImpl();
489
                p.setFormat(getFormat());
490
                p.setFixedSize(getFixedSize());
491
                p.setHeight(getHeight());
492
                p.setWidth(getWidth());
493
                p.setExtent(getExtent());
494
                p.setURI(getURI());
495
                p.setInfoLayerQuery(getInfoLayerQuery());
496
                p.setLayerQuery(getLayerQuery());
497
                p.setName(getName());
498
                p.setOnlineResources((Hashtable<String, String>)this.getDynValue(FIELD_ONLINERESOURC));
499
                p.setOverrideHost(isOverridingHost());
500
                p.setQueryable(isQueryable());
501
                p.setSRS(getSRS());
502
                p.setSRS(getSRSCode());
503
                p.setStyles(getStyles());
504
                p.setWmsTransparency(isWmsTransparent());
505
                p.setDimensions(getDimensions());
506
                p.setCancellable(getCancellable());
507
                return p;
508
        }
509
        
510
        public void assignFields(RasterDataParameters par, RasterDataServerExplorer explorer) {
511
                super.assignFields(par, explorer);
512
                WMSDataParametersImpl p = null;
513
                if(par instanceof WMSDataParametersImpl)
514
                        p = (WMSDataParametersImpl)par;
515
                else
516
                        return;
517
                setFormat(p.getFormat());
518
                setFixedSize(p.getFixedSize());
519
                setHeight(p.getHeight());
520
                setWidth(p.getWidth());
521
                setExtent(p.getExtent());
522
                setURI(p.getURI());
523
                setInfoLayerQuery(p.getInfoLayerQuery());
524
                setLayerQuery(p.getLayerQuery());
525
                setName(getName());
526
                setOnlineResources((Map<String, String>)p.getDynValue(FIELD_ONLINERESOURC));
527
                setOverrideHost(p.isOverridingHost());
528
                setQueryable(p.isQueryable());
529
                setSRS(p.getSRSCode());
530
                setStyles(p.getStyles());
531
                setWmsTransparency(p.isWmsTransparent());
532
                setDimensions(p.getDimensions());
533
                setCancellable(p.getCancellable());
534
        }
535
}