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 / WMSServerExplorerParameters.java @ 4439

History | View | Annotate | Download (6.79 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
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 IVER T.I   {{Task}}
26
*/
27

    
28
package org.gvsig.raster.wms.io;
29

    
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

    
33
import org.gvsig.fmap.dal.DataServerExplorerParameters;
34
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
35
import org.gvsig.raster.impl.store.AbstractRasterDataParameters;
36
import org.gvsig.tools.ToolsLocator;
37
import org.gvsig.tools.dynobject.DelegatedDynObject;
38
import org.gvsig.tools.dynobject.DynClass;
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 WMS provider
46
 * @author Nacho Brodin (nachobrodin@gmail.com)
47
 */
48
public class WMSServerExplorerParameters extends AbstractDataParameters implements DataServerExplorerParameters {
49
        protected static final String  FIELD_HOST          = "host";
50
        protected static DynClass      DYNCLASS            = null;
51
        private DelegatedDynObject     delegatedDynObject  = null;
52
        private static final String    FIELD_XYAXISORDER   = "xyaxisorder";
53
    private static final String    OLD_FIELD_AXISORDER   = "axisorder";
54

    
55
    @SuppressWarnings("unused")
56
    private static final Logger logger = LoggerFactory.getLogger(WMSServerExplorerParameters.class);
57

    
58
        /**
59
         *
60
         */
61
        public WMSServerExplorerParameters() {
62
                super();
63
                initialize();
64
        }
65

    
66
        protected void initialize() {
67
                this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
68
                                .getDynObjectManager().createDynObject(
69
                                                registerDynClass());
70
        }
71

    
72
        /**
73
         * @return the dynstruct
74
         */
75
        public static DynStruct registerDynClass() {
76
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
77
                DynStruct definition = manager.getDefinition("WMSServerExplorerParameters_Persistent");
78
                if( definition == null ) {
79
                        definition = manager.addDefinition(
80
                                        WMSServerExplorerParameters.class,
81
                                        "WMSServerExplorerParameters_Persistent",
82
                                        "WMS Explorer DataParameters Persistency",
83
                                        null,
84
                                        null
85
                        );
86
                }
87

    
88
                AbstractRasterDataParameters.registerDynClass(definition);
89

    
90
                definition.addDynFieldBoolean(FIELD_XYAXISORDER)
91
                .setDescription("Longitude first in axis order")
92
                .setMandatory(false).setDefaultFieldValue(new Boolean(false));
93

    
94
                definition.addDynFieldString(FIELD_HOST)
95
                .setDescription("Uniform Resource Identifier (File name or URL)")
96
                .setMandatory(false);
97
                return definition;
98
        }
99

    
100
        protected DelegatedDynObject getDelegatedDynObject() {
101
                return delegatedDynObject;
102
        }
103

    
104
        /**
105
         * Gets the assigned host
106
         * @return the value of host field
107
         */
108
        public String getHost() {
109
                return (String) this.getDynValue(FIELD_HOST);
110
        }
111

    
112
        /**
113
         * Assign the host to this explorer
114
         * @param host
115
         */
116
        public void setHost(String host) {
117
                this.setDynValue(FIELD_HOST, host);
118
        }
119

    
120
        /**
121
         * @return the provider name
122
         */
123
        public String getDataStoreName() {
124
                return WMSProvider.NAME;
125
        }
126

    
127
    /**
128
     * @return the provider description
129
     */
130
        public String getDescription() {
131
                return WMSProvider.DESCRIPTION;
132
        }
133

    
134
        public String getExplorerName() {
135
                return WMSServerExplorer.NAME;
136
        }
137

    
138
        /**
139
         * <p>Gets the behaviour of the WMS client with regards the axis order</p>
140
         *
141
         * <p>Returns <code>true</code> if the WMS parser should assume that the
142
         * order of the coordinates follows the XY axis order
143
         * (the first coordinate corresponds to the horizontal X
144
         * axis, while the second  coordinate corresponds to the
145
         * vertical Y axis), regardless the protocol version and CRS in use.</p>
146
         *
147
         * <p>Returns <code>false</code> if the WMS parser should decide the
148
         * axis order based on the protocol version and the coordinate
149
         * reference system (CRS) in use. In particular, if protocol
150
         * version is >= 1.3.0, then the WMS parser assumes
151
         * the axis order defined in the official EPSG registry for the
152
         * CRS in use. For versions < 1.3.0, the XY axis order is assumed.</p>
153
         *
154
         * <p>The default value is <code>false</code></p>.
155
         * @see #setXyAxisOrder(boolean)
156
         * @return true if axis order is x-y
157
         */
158
        public boolean isXyAxisOrder() {
159
                if (hasDynValue(FIELD_XYAXISORDER)) {
160
                        Object obj = getDynValue(FIELD_XYAXISORDER);
161
                        if(obj instanceof Boolean) {
162
                                Boolean b = (Boolean)getDynValue(FIELD_XYAXISORDER);
163
                                if(b != null)
164
                                        return ((Boolean)b).booleanValue();
165
                        }
166
                        if(obj instanceof String) {
167
                                String b = (String)getDynValue(FIELD_XYAXISORDER);
168
                                if(b != null)
169
                                        return new Boolean(((String)b));
170
                        }
171
                }
172
                return false;
173
        }
174

    
175
        /**
176
         * <p>Sets the behaviour of the WMS client with regards the axis order.<p>
177
         *
178
         * <p>If set to <code>true</code>, then the XY axis order
179
         * is assumed for all the WMS
180
         * protocol versions and coordinate reference systems.</p>
181
         *
182
         * <p>If set to <code>false</code>
183
         * then the WMS parser will decide the axis order based on
184
         * the protocol version and the coordinate reference system (CRS)
185
         * in use. In particular, if protocol
186
         * version is >= 1.3.0, then the WMS parser assumes
187
         * the axis order defined in the official EPSG registry for the
188
         * CRS in use. For versions < 1.3.0, the XY axis order is assumed.</p>
189
         *
190
         *
191
         * @param assumeXY
192
         * @see #isXyAxisOrder()
193
         */
194
        public void setXyAxisOrder(boolean assumeXY) {
195
                this.setDynValue(FIELD_XYAXISORDER, new Boolean(assumeXY));
196
        }
197

    
198

    
199
    public void loadFromState(PersistentState state) throws PersistenceException {
200
        super.loadFromState(state);
201

    
202
        // Entre la 2.1 y la 2.2 cambi? la clave de la propiedad axisorder a xyaxisorder
203
        // El siguiente bloque try catch es para mantener compatibilidad con los proyectos de ambas versiones
204
        try {
205
            setDynValue(FIELD_XYAXISORDER, state.get(OLD_FIELD_AXISORDER));
206
        } catch(Throwable t){
207
            //do nothing;
208
        }
209
    }
210

    
211

    
212
    public void setDynValue(String name, Object value) {
213
        if (OLD_FIELD_AXISORDER.equalsIgnoreCase(name)) {
214
            super.setDynValue(FIELD_XYAXISORDER, value);
215
        } else {
216
            super.setDynValue(name, value);
217
        }
218
    }
219
}