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 / WMSDataParameters.java @ 483

History | View | Annotate | Download (16.8 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.Map;
29
import java.util.Vector;
30

    
31
import org.cresques.cts.IProjection;
32
import org.gvsig.compat.net.ICancellable;
33
import org.gvsig.fmap.crs.CRSFactory;
34
import org.gvsig.fmap.dal.DataTypes;
35
import org.gvsig.fmap.dal.coverage.store.parameter.RemoteStoreParameters;
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.DynField;
41
import org.gvsig.tools.dynobject.DynObjectManager;
42

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

    
94
                        field = dynClass.addDynField(FIELD_SRS);
95
                        field.setTheTypeOfAvailableValues(DynField.ANY);
96
                        field.setDescription("SRS");
97
                        field.setType(DataTypes.CRS);
98
                        field.setMandatory(false);
99

    
100
                        field = dynClass.addDynField(FIELD_FORMAT);
101
                        field.setTheTypeOfAvailableValues(DynField.ANY);
102
                        field.setDescription("Format");
103
                        field.setType(DataTypes.STRING);
104
                        field.setMandatory(true);
105
                        
106
                        field = dynClass.addDynField(FIELD_INFOFORMAT);
107
                        field.setTheTypeOfAvailableValues(DynField.ANY);
108
                        field.setDescription("Info Format");
109
                        field.setType(DataTypes.STRING);
110
                        field.setMandatory(false);
111
                        
112
                        field = dynClass.addDynField(FIELD_LAYERQUERY);
113
                        field.setTheTypeOfAvailableValues(DynField.ANY);
114
                        field.setDescription("Layer Query");
115
                        field.setType(DataTypes.STRING);
116
                        field.setMandatory(false);
117
                        
118
                        field = dynClass.addDynField(FIELD_NAME);
119
                        field.setTheTypeOfAvailableValues(DynField.ANY);
120
                        field.setDescription("Name");
121
                        field.setType(DataTypes.STRING);
122
                        field.setMandatory(true);
123
                        
124
                        field = dynClass.addDynField(FIELD_SRSSTR);
125
                        field.setTheTypeOfAvailableValues(DynField.ANY);
126
                        field.setDescription("String that represents the SRS");
127
                        field.setType(DataTypes.STRING);
128
                        field.setMandatory(true);
129
                        
130
                        field = dynClass.addDynField(FIELD_TRANSPARENCY);
131
                        field.setTheTypeOfAvailableValues(DynField.ANY);
132
                        field.setDescription("Transparency");
133
                        field.setType(DataTypes.BOOLEAN);
134
                        field.setMandatory(true);
135
                        
136
                        field = dynClass.addDynField(FIELD_INFOLAYERQUERY);
137
                        field.setTheTypeOfAvailableValues(DynField.ANY);
138
                        field.setDescription("InfoLayerQuery");
139
                        field.setType(DataTypes.STRING);
140
                        field.setMandatory(false);
141
                        
142
                        field = dynClass.addDynField(FIELD_QUERYABLE);
143
                        field.setTheTypeOfAvailableValues(DynField.ANY);
144
                        field.setDescription("Queryable");
145
                        field.setType(DataTypes.BOOLEAN);
146
                        field.setMandatory(false);
147
                        
148
                        field = dynClass.addDynField(FIELD_OVERRIDE);
149
                        field.setTheTypeOfAvailableValues(DynField.ANY);
150
                        field.setDescription("Override a host capabilities");
151
                        field.setType(DataTypes.BOOLEAN);
152
                        field.setMandatory(false);
153
                        
154
                        field = dynClass.addDynField(FIELD_STYLES);
155
                        field.setTheTypeOfAvailableValues(DynField.ANY);
156
                        field.setDescription("Styles");
157
                        field.setType(DataTypes.OBJECT);
158
                        field.setMandatory(false);
159
                        
160
                        field = dynClass.addDynField(FIELD_DIMENSIONS);
161
                        field.setTheTypeOfAvailableValues(DynField.ANY);
162
                        field.setDescription("Dimensions");
163
                        field.setType(DataTypes.OBJECT);
164
                        field.setMandatory(false);
165
                        
166
                        field = dynClass.addDynField(FIELD_ONLINERESOURC);
167
                        field.setTheTypeOfAvailableValues(DynField.ANY);
168
                        field.setDescription("online resources");
169
                        field.setType(DataTypes.MAP);
170
                        field.setMandatory(false);
171
                        
172
                        field = dynClass.addDynField(FIELD_FIXEDSIZE);
173
                        field.setTheTypeOfAvailableValues(DynField.ANY);
174
                        field.setDescription("Fixed size");
175
                        field.setType(DataTypes.OBJECT);
176
                        field.setMandatory(false);
177
                        
178
                        field = dynClass.addDynField(FIELD_CANCEL);
179
                        field.setTheTypeOfAvailableValues(DynField.ANY);
180
                        field.setDescription("Cancellable");
181
                        field.setType(DataTypes.OBJECT);
182
                        field.setMandatory(false);
183
                        
184
                        field = dynClass.addDynField(FIELD_EXTENT);
185
                        field.setTheTypeOfAvailableValues(DynField.ANY);
186
                        field.setDescription("Extent");
187
                        field.setType(DataTypes.OBJECT);
188
                        field.setMandatory(false);
189
                        
190
                        field = dynClass.addDynField(FIELD_WIDTH);
191
                        field.setTheTypeOfAvailableValues(DynField.ANY);
192
                        field.setDescription("Width");
193
                        field.setType(DataTypes.INT);
194
                        field.setMandatory(false);
195
                        
196
                        field = dynClass.addDynField(FIELD_HEIGHT);
197
                        field.setTheTypeOfAvailableValues(DynField.ANY);
198
                        field.setDescription("Height");
199
                        field.setType(DataTypes.INT);
200
                        field.setMandatory(false);
201
                        
202
                        DYNCLASS = dynClass;
203
                }
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
        
241
        /*
242
         * (non-Javadoc)
243
         * @see org.gvsig.fmap.dal.coverage.store.parameter.WMSStoreParameters#getLayerQuery()
244
         */
245
        public String getLayerQuery() {
246
                return (String) this.getDynValue(FIELD_LAYERQUERY);
247
        }
248

    
249
        /*
250
         * (non-Javadoc)
251
         * @see org.gvsig.fmap.dal.coverage.store.parameter.WMSStoreParameters#setLayerQuery(java.lang.String)
252
         */
253
        public void setLayerQuery(String layerQuery) {
254
                this.setDynValue(FIELD_LAYERQUERY, layerQuery);
255
        }
256
        
257
        /**
258
         * Devuelve el SRS.
259
         * @return SRS.
260
         */
261
        public String getSRSCode() {
262
                return (String) this.getDynValue(FIELD_SRSSTR);
263
        }
264
        
265
        /**
266
         * Inserta el SRS.
267
         * @param m_srs SRS.
268
         */
269
        public void setSRS(String m_srs) {
270
                this.setDynValue(FIELD_SRSSTR, m_srs);
271
                setSRS(CRSFactory.getCRS(m_srs));
272
        }
273
        
274
        public void setSRS(IProjection srs) {
275
                setDynValue(FIELD_SRS, srs);
276
        }
277

    
278
        /**
279
         * Returns the projection
280
         * @return
281
         */
282
        public IProjection getSRS() {
283
                if (this.getSRSID() == null) {
284
                        return null;
285
                }
286
                return (IProjection) getDynValue(FIELD_SRS);
287
        }
288
        
289
        public String getSRSID() {
290
                IProjection srs = (IProjection) getDynValue(FIELD_SRS);
291
                if (srs == null) {
292
                        return null;
293
                }
294
                return srs.getAbrev();
295
        }
296

    
297
        public void setSRSID(String srsid) {
298
                if (srsid == null) {
299
                        setDynValue(FIELD_SRS, null);
300
                } else {
301
                        setDynValue(FIELD_SRS, CRSFactory.getCRS(srsid));
302
                }
303
        }
304
        
305
        /*
306
         * (non-Javadoc)
307
         * @see org.gvsig.fmap.dal.coverage.store.parameter.WMSStoreParameters#getName()
308
         */
309
        public String getName() {
310
                return (String) this.getDynValue(FIELD_NAME);
311
        }
312

    
313
        /*
314
         * (non-Javadoc)
315
         * @see org.gvsig.fmap.dal.coverage.store.parameter.WMSStoreParameters#setName(java.lang.String)
316
         */
317
        public void setName(String name) {
318
                this.setDynValue(FIELD_NAME, name);
319
        }
320
        
321
        /**
322
         * @return Returns the wmsTransparency.
323
         */
324
        public boolean isWmsTransparent() {
325
                Boolean b = (Boolean)getDynValue(FIELD_TRANSPARENCY);
326
                if(b != null)
327
                        return ((Boolean)b).booleanValue();
328
                return false;
329
        }
330

    
331
        /**
332
         * @param wmsTransparency The wmsTransparency to set.
333
         */
334
        public void setWmsTransparency(boolean wmsTransparency) {
335
                this.setDynValue(FIELD_TRANSPARENCY, new Boolean(wmsTransparency));
336
        }
337
        
338
        /*
339
         * (non-Javadoc)
340
         * @see org.gvsig.fmap.dal.coverage.store.parameter.WMSStoreParameters#getInfoLayerQuery()
341
         */
342
        public String getInfoLayerQuery() {
343
                return (String) this.getDynValue(FIELD_INFOLAYERQUERY);
344
        }
345

    
346
        /*
347
         * (non-Javadoc)
348
         * @see org.gvsig.fmap.dal.coverage.store.parameter.WMSStoreParameters#setInfoLayerQuery(java.lang.String)
349
         */
350
        public void setInfoLayerQuery(String infoLayerQuery) {
351
                this.setDynValue(FIELD_INFOLAYERQUERY, infoLayerQuery);
352
        }
353
        
354

    
355
        /**
356
         * If it is true, this layer accepts GetFeatureInfo operations. This WMS operations
357
         * maps to FMap's infoByPoint(p) operation.
358
         * @param b
359
         */
360
        public void setQueryable(boolean b) {
361
                this.setDynValue(FIELD_QUERYABLE, new Boolean(b));
362
        }
363
        
364
        public void setCancellable(ICancellable cancel) {
365
                this.setDynValue(FIELD_CANCEL, cancel);
366
        }
367
        
368
        public ICancellable getCancellable() {
369
                return (ICancellable) this.getDynValue(FIELD_CANCEL);
370
        }
371
        
372
        /**
373
         * If it is true, this layer accepts GetFeatureInfo operations. This WMS operations
374
         * maps to FMap's infoByPoint(p) operation.
375
         */
376
        public boolean isQueryable() {
377
                Boolean b = (Boolean)getDynValue(FIELD_QUERYABLE);
378
                if(b != null)
379
                        return ((Boolean)b).booleanValue();
380
                return false;
381
        }
382
        
383
        /*
384
         * (non-Javadoc)
385
         * @see org.gvsig.fmap.dal.coverage.store.RasterStoreParameters#isOverridingHost()
386
         */
387
        public boolean isOverridingHost() {
388
                Boolean b = (Boolean)getDynValue(FIELD_OVERRIDE);
389
                if(b != null)
390
                        return ((Boolean)b).booleanValue();
391
                return false;
392
        }
393
        
394
        /*
395
         * (non-Javadoc)
396
         * @see org.gvsig.fmap.dal.coverage.store.RasterStoreParameters#setOverrideHost(boolean)
397
         */
398
        public void setOverrideHost(boolean over) {
399
                this.setDynValue(FIELD_OVERRIDE, new Boolean(over));;
400
        }
401
        
402
        /**
403
         * @param styles
404
         */
405
        public void setStyles(Vector<RemoteWMSStyle> styles) {
406
                this.setDynValue(FIELD_STYLES, styles);
407
        }
408
        
409
        /**
410
         * @param styles
411
         */
412
        @SuppressWarnings("unchecked")
413
        public Vector<RemoteWMSStyle> getStyles() {
414
                return (Vector<RemoteWMSStyle>) this.getDynValue(FIELD_STYLES);
415
        }
416
        
417
        /**
418
         * Sets the dimension vector that is a list of key-value pairs containing
419
         * the name of the dimension and the value for it
420
         * @param dimensions
421
         */
422
        public void setDimensions(Vector<String> dimensions) {
423
                this.setDynValue(FIELD_DIMENSIONS, dimensions);
424
        }
425
        
426
        /**
427
         * Gets the dimension vector that is a list of key-value pairs containing
428
         * the name of the dimension and the value for it
429
         * @return
430
         */
431
        @SuppressWarnings("unchecked")
432
        public Vector<String> getDimensions() {
433
                return (Vector<String>) this.getDynValue(FIELD_DIMENSIONS);
434
        }
435

    
436
        /**
437
         * Sets the set of URLs that should be accessed for each operation performed
438
         * to the server.
439
         *
440
         * @param onlineResources
441
         */
442
        public void setOnlineResources(Hashtable<String, String> onlineResources) {
443
                this.setDynValue(FIELD_ONLINERESOURC, onlineResources);
444
        }
445
        
446
        /**
447
         * Gets the URL that should be accessed for an operation performed
448
         * to the server.
449
         *
450
         * @param onlineResources
451
         */
452
        public String getOnlineResource(String operation) {
453
                return (String) getOnlineResource().get(operation);
454
        }
455
        
456
        /**
457
         * Gets the online resource map
458
         *
459
         * @param onlineResources
460
         */
461
        @SuppressWarnings("unchecked")
462
        public Map<String,String> getOnlineResource() {
463
                return (Map<String,String>) this.getDynValue(FIELD_ONLINERESOURC);
464
        }
465
        
466
        /**
467
         * When a server is not fully featured and it only can serve constant map
468
         * sizes this value must be set. It expresses the size in pixels (width, height)
469
         * that the map will be requested.
470
         * @param Dimension sz
471
         */
472
        public void setFixedSize(Dimension sz) {
473
                this.setDynValue(FIELD_FIXEDSIZE, sz);
474
        }
475

    
476
        /**
477
         * Tells whether if this layer must deal with the server with the constant-size
478
         * limitations or not.
479
         * @return boolean.
480
         */
481
        public boolean isSizeFixed() {
482
                return (getDynValue(FIELD_FIXEDSIZE) != null);
483
        }
484
        
485
        /**
486
         * Gets the value of the fixed size
487
         * @return
488
         */
489
        public Dimension getFixedSize() {
490
                return (Dimension) this.getDynValue(FIELD_FIXEDSIZE);
491
        }
492
        
493
        /**
494
         * Assigns the extent. 
495
         * When a provider is initialized this will need to know what is the extent before the request.
496
         * 
497
         * @param bBox
498
         */
499
        public void setExtent(Rectangle2D bBox) {
500
                this.setDynValue(FIELD_EXTENT, bBox);
501
        }
502
        
503
        /*
504
         * (non-Javadoc)
505
         * @see org.gvsig.fmap.dal.coverage.store.parameter.RemoteStoreParameters#setWidth(int)
506
         */
507
        public void setWidth(int w) {
508
                this.setDynValue(FIELD_WIDTH, new Integer(w));
509
        }
510
        
511
        /*
512
         * (non-Javadoc)
513
         * @see org.gvsig.fmap.dal.coverage.store.parameter.RemoteStoreParameters#setHeight(int)
514
         */
515
        public void setHeight(int h) {
516
                this.setDynValue(FIELD_HEIGHT, new Integer(h));
517
        }
518
        
519
        /**
520
         * Gets the bounding box
521
         * @return
522
         */
523
        public Rectangle2D getExtent() {
524
                return (Rectangle2D)getDynValue(FIELD_EXTENT);
525
        }
526
        
527
        /**
528
         * Gets the width
529
         * @return
530
         */
531
        public int getWidth() {
532
                Integer b = (Integer)getDynValue(FIELD_WIDTH);
533
                if(b != null)
534
                        return ((Integer)b).intValue();
535
                return 0;
536
        }
537
        
538
        /**
539
         * Gets the height
540
         * @return
541
         */
542
        public int getHeight() {
543
                Integer b = (Integer)getDynValue(FIELD_HEIGHT);
544
                if(b != null)
545
                        return ((Integer)b).intValue();
546
                return 0;
547
        }
548
        
549
        /*public void setConnector(Object connector) {
550
                this.setDynValue(FIELD_CONNECTOR, connector);
551
        }
552
        
553
        public Object getConnector() {
554
                return (Object)getDynValue(FIELD_CONNECTOR);
555
        }*/
556
        
557
        //**********************************************
558
        
559
        /*
560
         * (non-Javadoc)
561
         * @see org.gvsig.fmap.dal.DataStoreParameters#getDataStoreName()
562
         */
563
        public String getDataStoreName() {
564
                return WMSProvider.NAME;
565
        }
566
        
567
        /*
568
         * (non-Javadoc)
569
         * @see org.gvsig.fmap.dal.DataStoreParameters#getDescription()
570
         */
571
        public String getDescription() {
572
                return WMSProvider.DESCRIPTION;
573
        }
574

    
575
        public String getExplorerName() {
576
                return WMSServerExplorer.NAME;
577
        }
578
        
579
        public boolean isValid() {
580
                return (this.getURI() != null);
581
        }
582
        
583
        protected DelegatedDynObject getDelegatedDynObject() {
584
                return delegatedDynObject;
585
        }
586
        
587
        /*
588
         * (non-Javadoc)
589
         * @see java.lang.Object#clone()
590
         */
591
        @SuppressWarnings("unchecked")
592
        public WMSDataParameters clone() {
593
                WMSDataParameters p = new WMSDataParameters();
594
                p.setFormat(getFormat());
595
                p.setFixedSize(getFixedSize());
596
                p.setHeight(getHeight());
597
                p.setWidth(getWidth());
598
                p.setExtent(getExtent());
599
                p.setURI(getURI());
600
                p.setInfoLayerQuery(getInfoLayerQuery());
601
                p.setLayerQuery(getLayerQuery());
602
                p.setName(getName());
603
                p.setOnlineResources((Hashtable<String, String>)this.getDynValue(FIELD_ONLINERESOURC));
604
                p.setOverrideHost(isOverridingHost());
605
                p.setQueryable(isQueryable());
606
                p.setSRS(getSRS());
607
                p.setSRS(getSRSCode());
608
                p.setStyles(getStyles());
609
                p.setWmsTransparency(isWmsTransparent());
610
                p.setDimensions(getDimensions());
611
                p.setCancellable(getCancellable());
612
                return p;
613
        }
614
        
615
}