Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wmts / trunk / org.gvsig.raster.wmts / org.gvsig.raster.wmts.ogc / org.gvsig.raster.wmts.ogc.impl / src / main / java / org / gvsig / raster / wmts / ogc / impl / base / WMTSServerDescription.java @ 1806

History | View | Annotate | Download (7.32 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
package org.gvsig.raster.wmts.ogc.impl.base;
23

    
24
import java.lang.reflect.Constructor;
25
import java.lang.reflect.InvocationTargetException;
26
import java.util.ArrayList;
27

    
28
import org.gvsig.raster.wmts.ogc.exception.WMTSException;
29
import org.gvsig.raster.wmts.ogc.impl.Tags;
30
import org.gvsig.raster.wmts.ogc.impl.struct.WMTSLayerImpl;
31
import org.gvsig.raster.wmts.ogc.impl.struct.WMTSServiceIdentificationImpl;
32
import org.gvsig.raster.wmts.ogc.impl.struct.WMTSServiceProviderImpl;
33
import org.gvsig.raster.wmts.ogc.impl.struct.WMTSThemesImpl;
34

    
35

    
36
/**
37
 * Describes the status of a WMTSclient, so it adds to the Remote client status
38
 * a list of layers, a list of layer styles, the extent of the map.
39
 * 
40
 * @author Nacho Brodin (nachobrodin@gmail.com)
41
 */
42
public class WMTSServerDescription {
43
        // width and heigh of the map
44
    private int width;
45
    private int height;
46
    
47
    //format of the image to be retrieved
48
    private String format;
49
    private String infoFormat;
50
    // spatial reference system of the image to be retrieved
51
    private String srs;
52
    // exception format, to be retrieved in case of error
53
    private String exceptionFormat;
54
    
55
    //To set if the client has to use GET or POST
56
        private int protocol = Tags.PROTOCOL_UNDEFINED;
57
        private ArrayList                 layerList      = null;
58
        private ArrayList                 tileMatrixSet  = null;
59
        private WMTSThemesImpl                themes         = null;
60
        private WMTSServiceIdentificationImpl serviceId      = null;
61
        private WMTSServiceProviderImpl       serviceProv    = null;
62
        private String                    version        = null;
63
        
64
        public WMTSServerDescription(String version) {
65
                this.version = version;
66
        }
67
        
68
        public int getWidth() {        
69
        return width;
70
    }
71
    
72
    public void setWidth(int _width) {        
73
            width = _width;
74
    } 
75

    
76
    public int getHeight() {                
77
        return height;
78
    } 
79
    public void setHeight(int _height) {        
80
        height = _height;
81
    } 
82

    
83
    public String getFormat() {        
84
        return format;
85
    }
86
    
87
    public void setFormat(String _format) {        
88
        format = _format;
89
    } 
90
    
91
    public String getInfoFormat() {        
92
        return infoFormat;
93
    } 
94
    
95
    public void setInfoFormat(String _format) {        
96
        infoFormat = _format;
97
    } 
98

    
99
    public String getSrs() {        
100
        return srs;
101
    } 
102

    
103
    public void setSrs(String _srs) {        
104
        srs = _srs;
105
    } 
106

    
107
    public void setExceptionFormat(String _format) {        
108
        exceptionFormat = _format;
109
    } 
110
    
111
    public String getExceptionFormat() {        
112
        return exceptionFormat;
113
    }
114
    
115
        public int getProtocol() {
116
                return protocol;
117
        }
118
        
119
        public void setProtocol(int protocol) {
120
                this.protocol = protocol;
121
        }
122
        
123
        /**
124
         * Builds a new layer using the version number
125
         * @return
126
         */
127
        public WMTSLayerImpl buildNewLayer() {
128
                try {
129
                        Class clase;
130
                        version = version.replace('.', '_');
131
                        clase = Class.forName("org.gvsig.raster.wmts.ogc.impl.wmts_" + version + ".struct.WMTSLayer_" + version);
132
                        Class [] args = {WMTSServerDescription.class};
133
                        try {
134
                                Constructor hazNuevo = clase.getConstructor(args);
135
                                Object [] args2 = {this};
136
                                return (WMTSLayerImpl) hazNuevo.newInstance(args2);
137
                        } catch (SecurityException e) {
138
                                throw new WMTSException("Error SecurityException in open", e);
139
                        } catch (NoSuchMethodException e) {
140
                                throw new WMTSException("Error NoSuchMethodException in open", e);
141
                        } catch (IllegalArgumentException e) {
142
                                throw new WMTSException("Error IllegalArgumentException in open", e);
143
                        } catch (InstantiationException e) {
144
                                throw new WMTSException("Error InstantiationException in open", e);
145
                        } catch (IllegalAccessException e) {
146
                                throw new WMTSException("Error IllegalAccessException in open", e);
147
                        } catch (InvocationTargetException e) {
148
                                throw new WMTSException("Error opening this image with " + clase, e);
149
                        }
150
                } catch (Exception e) {
151
                        e.printStackTrace();
152
                        //throw new Exception("WMSDriverFactory. Unknown driver version " + e);
153
                        return null;
154
                }
155
        }
156
        
157
        /**
158
         * It creates an instance of a WMSDriver class.
159
         *
160
         * @param String, with the version of the driver to be created
161
         * @return WMSDriver.
162
         */
163
        public Object createVersionObject(String className) {
164
                return createVersionObject(className, version);
165
        }
166
        
167
    /**
168
     * It creates an instance of a WMSDriver class.
169
     *
170
     * @param String, with the version of the driver to be created
171
     * @return WMSDriver.
172
     */
173
        public Object createVersionObject(String className, String version) {
174
                try {
175
                        Class driver;
176
                        version = version.replace('.', '_');
177
                        driver = Class.forName("org.gvsig.raster.wmts.ogc.impl.wmts_" + version + ".struct." + className + "_" + version);
178
                        return driver.newInstance();
179
                } catch (Exception e) {
180
                        e.printStackTrace();
181
                        //throw new Exception("WMSDriverFactory. Unknown driver version " + e);
182
                        return null;
183
                }
184
        }
185

    
186
        /**
187
         * Gets the layer structure
188
         * @return
189
         */
190
        public WMTSServiceIdentificationImpl getServiceIdentification() {
191
                if(serviceId == null)
192
                        serviceId = (WMTSServiceIdentificationImpl)createVersionObject("WMTSServiceIdentification", version);
193
                return serviceId;
194
        }
195
        
196
        /**
197
         * Gets the layer structure
198
         * @return
199
         */
200
        public WMTSServiceProviderImpl getServiceProvider() {
201
                if(serviceProv == null)
202
                        serviceProv = (WMTSServiceProviderImpl)createVersionObject("WMTSServiceProvider", version);
203
                return serviceProv;
204
        }
205
        
206
        /**
207
         * Gets the list of WMTSLayer
208
         */
209
        public ArrayList getLayerList() {
210
                if(layerList == null)
211
                        layerList = new ArrayList();
212
                return layerList;
213
        }
214
        
215
        /**
216
         * Gets the list of WMTSTileMatrixSet
217
         * @return
218
         */
219
        public ArrayList getTileMatrixSet() {
220
                if(tileMatrixSet == null)
221
                        tileMatrixSet = new ArrayList();
222
                return tileMatrixSet;
223
        }
224
        
225
        /**
226
         * Gets the layer structure
227
         * @return
228
         */
229
        public WMTSThemesImpl getThemes() {
230
                if(themes == null)
231
                        themes = (WMTSThemesImpl)createVersionObject("WMTSThemes", version);
232
                return themes;
233
        }
234
        
235
        /**
236
         * Gets a layer by its title
237
         * @param titleLayer
238
         * @return
239
         */
240
        public WMTSLayerImpl getLayerByTitle(String titleLayer) {
241
                for (int i = 0; i < layerList.size(); i++) {
242
                        WMTSLayerImpl layer = ((WMTSLayerImpl)layerList.get(i));
243
                        if(layer.getTitle().compareTo(titleLayer) == 0) {
244
                                return layer;
245
                        }
246
                }
247
                return null;
248
        }
249
        
250
        /**
251
         * Clean all attributes
252
         */
253
        public void clear() {
254
                if(layerList != null)
255
                        layerList.clear();
256
                if(tileMatrixSet != null)
257
                        tileMatrixSet.clear();
258
                themes = null;
259
                serviceId = null;
260
                serviceProv = null;
261
        }
262
}