Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.image.extension / src / main / java / org / gvsig / arcims / image / fmap / datasource / ArcImsImageWizardData.java @ 32321

History | View | Annotate | Download (7.74 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
 * 2010 Prodevelop S.L. main development
26
 * http://www.prodevelop.es
27
 */
28

    
29
package org.gvsig.arcims.image.fmap.datasource;
30

    
31
import java.net.URL;
32
import java.util.TreeMap;
33

    
34
import org.cresques.cts.IProjection;
35
import org.gvsig.arcims.image.fmap.drivers.ArcImsImageDriver;
36
import org.gvsig.arcims.image.fmap.layers.FRasterLyrArcIMS;
37
import org.gvsig.fmap.mapcontext.layers.FLayer;
38
import org.gvsig.fmap.mapcontrol.MapControl;
39
import org.gvsig.remoteclient.arcims.ArcImsProtImageHandler;
40
import org.gvsig.remoteclient.arcims.ArcImsStatus;
41
import org.gvsig.remoteclient.arcims.utils.MyCancellable;
42
import org.gvsig.remoteclient.arcims.utils.ServiceInfoTags;
43
import org.gvsig.remoteclient.arcims.utils.ServiceInformation;
44
import org.gvsig.utils.swing.threads.DefaultCancellableMonitorable;
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

    
48
/**
49
 * This class implements a data source object, owned by the ArcImsImageWizard object.
50
 * It will create the ArcIMS layer and load some basic data.
51
 * 
52
 * @author jldominguez
53
 * @author vsanjaime version 2.0 
54
 */
55
public class ArcImsImageWizardData {
56
        
57
        private static Logger logger = LoggerFactory
58
                        .getLogger(ArcImsImageWizardData.class.getName());
59

    
60
        @SuppressWarnings("unused")
61
        private MapControl mapControl;
62
        private ArcImsStatus status;
63
        private String testInfo;
64
        private String serviceType;
65
        private ArcImsImageDriver imageDriver = null;
66
        private boolean missingSrs = false;
67
        private MyCancellable myCanc;
68

    
69
        /**
70
         * Constructor
71
         */
72
        public ArcImsImageWizardData() {
73
                myCanc = new MyCancellable(new DefaultCancellableMonitorable());
74
        }
75

    
76
        /**
77
         * set host service
78
         * 
79
         * @param host
80
         * @param service
81
         * @param svcType
82
         * @throws Exception
83
         */
84
        public void setHostService(URL host, String service, String svcType)
85
                        throws Exception {
86
                
87
                this.serviceType = svcType;
88

    
89
                boolean nogood = true;
90

    
91
                if (this.serviceType.compareToIgnoreCase(ServiceInfoTags.vIMAGESERVICE) == 0) {
92
                        nogood = false;
93
                        this.imageDriver = new ArcImsImageDriver(host.toString(),
94
                                        service, svcType);
95

    
96
                        // Send a getCapabilities request;
97
                        if (!imageDriver.connect(myCanc)) {
98
                                Exception de = new Exception("cant_connect");
99
                                logger.error("While trying to connect ", de);
100
                                throw de;
101
                        }
102
                        this.testInfo = "Connected successfully.";
103
                }
104

    
105
                if (nogood) {
106
                        logger.error("Nothing done. Unable to find out serviceType ");
107
                }
108
        }
109

    
110
        /**
111
         * 
112
         * @param host
113
         * @param service
114
         * @param svcType
115
         * @param lyr
116
         * @throws Exception
117
         */
118
        public void setHostService(URL host, String service, String svcType,
119
                        FLayer lyr) throws Exception {
120
                
121
                this.serviceType = svcType;
122

    
123
                boolean nogood = true;
124

    
125
                if (this.serviceType.compareToIgnoreCase(ServiceInfoTags.vIMAGESERVICE) == 0) {
126
                        nogood = false;
127

    
128
                        this.imageDriver = ((FRasterLyrArcIMS) lyr)
129
                                        .getDriver();
130

    
131
                        // Send a getCapabilities request;
132
                        if (!imageDriver.connect(myCanc)) {
133
                                Exception de = new Exception("cant_connect");
134
                                logger.error("While trying to connect ", de);
135
                                throw de;
136
                        }
137
                        this.testInfo = "Connected successfully.";
138
                }
139

    
140
                if (nogood) {
141
                        logger.error("Nothing done. Unable to find out serviceType ");
142
                }
143
        }
144

    
145
        /**
146
         * Get service type
147
         * 
148
         * @return
149
         */
150
        public String getServiceType() {
151
                return this.serviceType;
152
        }
153

    
154
        /**
155
         * Set service type
156
         * 
157
         * @param t
158
         */
159
        public void setServiceType(String t) {
160
                this.serviceType = t;
161
        }
162

    
163
        /**
164
         * Get driver
165
         * 
166
         * @return
167
         */
168
        public ArcImsImageDriver getDriver() {
169

    
170
                if (this.serviceType.compareToIgnoreCase(ServiceInfoTags.vIMAGESERVICE) == 0) {
171
                        return this.imageDriver;
172
                }
173

    
174
                logger.error("Null value returned. Unable to find out serviceType ");
175
                return null;
176
        }
177

    
178
        /**
179
         * Set driver
180
         * 
181
         * @param d
182
         */
183
        public void setDriver(ArcImsImageDriver d) {
184
                boolean nogood = true;
185

    
186
                if (d instanceof ArcImsImageDriver) {
187
                        imageDriver = (ArcImsImageDriver) d;
188
                        nogood = false;
189
                }
190

    
191
                if (nogood) {
192
                        logger.error("Nothing done. Unable to find out serviceType ");
193
                }
194
        }
195

    
196
        /**
197
         * Get status
198
         * 
199
         * @return
200
         */
201
        public ArcImsStatus getStatus() {
202
                return status;
203
        }
204

    
205
        /**
206
         * Set status
207
         * 
208
         * @param s
209
         */
210
        public void setStatus(ArcImsStatus s) {
211
                status = s;
212
        }
213

    
214
        /**
215
         * Gets available layers from the current server and service
216
         * 
217
         * @return a TreeMap with available layers
218
         */
219
        public TreeMap getLayers() {
220

    
221
                if (serviceType.compareToIgnoreCase(ServiceInfoTags.vIMAGESERVICE) == 0) {
222
                        return imageDriver.getLayers();
223
                }
224

    
225
                logger
226
                                .error("Null value returned. Unable to find out serviceType in method "
227
                                                + "TreeMap getLayers()"
228
                                                + ", class: "
229
                                                + this.getClass().toString());
230

    
231
                return null;
232
        }
233

    
234
        /**
235
         * This method is invoqued by the wizard's <tt>getLayer()</tt> method to
236
         * create an ArcIMS raster layer.
237
         * 
238
         * @param host
239
         *            server's URL
240
         * @param service
241
         *            service name
242
         * @param sLayer
243
         *            comma-separated list of selected layers
244
         * @param name
245
         *            new gvSIG layer's name
246
         * @param srs
247
         *            project's coordinate system
248
         * @return the new layer (of class FRasterLyrArcIMS, which is a subclass of
249
         *         _FLyrArcIMS which is a subclass of FLayer)
250
         */
251
        public FRasterLyrArcIMS createArcImsRasterLayer(String host,
252
                        String service, String sLayer, String name, IProjection srs,
253
                        String imgFormat) throws Exception {
254
                ArcImsImageDriver drv = new ArcImsImageDriver(host, service,
255
                                this.serviceType);
256

    
257
                if (!drv.connect(myCanc)) {
258
                        throw new Exception();
259
                }
260

    
261
                FRasterLyrArcIMS flyr = new FRasterLyrArcIMS();
262
                flyr.setDriver(drv);
263
                flyr.setHost(new URL(host));
264
                flyr.setService(service);
265
                flyr.setServiceType(this.serviceType);
266
                flyr.setServiceInformationInStatus(drv.getClient()
267
                                .getServiceInformation());
268
                ArcImsStatus status = flyr.getArcimsStatus();
269
                ServiceInformation si = status.getServiceInfo();
270

    
271
                if ((si.getFeaturecoordsys() == null)
272
                                || (si.getFeaturecoordsys().equals(""))) {
273
                        missingSrs = true;
274
                        si.setFeaturecoordsys(srs.getAbrev().substring(
275
                                        ServiceInfoTags.vINI_SRS.length()).trim());
276
                        logger.warn("Server provides no SRS. ");
277
                } else {
278
                        missingSrs = false;
279
                }
280

    
281
                flyr.setFullExtent(((ArcImsProtImageHandler) drv.getClient()
282
                                .getHandler()).getServiceExtent(srs, flyr.getArcimsStatus()));
283
                
284
                flyr.setFormat(imgFormat);
285
                flyr.setTransparency(0);
286
                flyr.setLayerQuery(sLayer);
287
                flyr.setProjection(srs);
288
                flyr.setName(name);
289
        
290
                return flyr;
291
        }
292

    
293
        public String getTestInfo() {
294
                return testInfo;
295
        }
296

    
297
        /**
298
         * Tells whether the SRS was missing on the server.
299
         * 
300
         * @return <tt>true</tt> if and only if the Srs was not provided by the
301
         *         server.
302
         */
303
        public boolean isMissingSrs() {
304
                return missingSrs;
305
        }
306

    
307
        /**
308
         * Set missing srs
309
         * @param missingSrs
310
         */
311
        public void setMissingSrs(boolean missingSrs) {
312
                this.missingSrs = missingSrs;
313
        }
314

    
315
        /**
316
         * Set map control
317
         * @param mapControl
318
         */
319
        public void setMapControl(MapControl mapControl) {
320
                this.mapControl = mapControl;
321
        }
322
}