Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / wmts / WMTSServerDescription.java @ 40559

History | View | Annotate | Download (6.63 KB)

1 40559 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24 40435 jjdelcerro
/* gvSIG. Geographic Information System of the Valencian Government
25
*
26
* Copyright (C) 2007-2008 Infrastructures and Transports Department
27
* of the Valencian Government (CIT)
28
*
29
* This program is free software; you can redistribute it and/or
30
* modify it under the terms of the GNU General Public License
31
* as published by the Free Software Foundation; either version 2
32
* of the License, or (at your option) any later version.
33
*
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
* GNU General Public License for more details.
38
*
39
* You should have received a copy of the GNU General Public License
40
* along with this program; if not, write to the Free Software
41
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
42
* MA  02110-1301, USA.
43
*
44
*/
45
package org.gvsig.remoteclient.wmts;
46
47
import java.lang.reflect.Constructor;
48
import java.lang.reflect.InvocationTargetException;
49
import java.util.ArrayList;
50
51
import org.gvsig.remoteclient.wmts.exception.WMTSException;
52
import org.gvsig.remoteclient.wmts.struct.WMTSLayer;
53
import org.gvsig.remoteclient.wmts.struct.WMTSServiceIdentification;
54
import org.gvsig.remoteclient.wmts.struct.WMTSServiceProvider;
55
import org.gvsig.remoteclient.wmts.struct.WMTSThemes;
56
57
58
/**
59
 * Describes the status of a WMTSclient, so it adds to the Remote client status
60
 * a list of layers, a list of layer styles, the extent of the map.
61
 *
62
 * @author Nacho Brodin (nachobrodin@gmail.com)
63
 */
64
public class WMTSServerDescription extends org.gvsig.remoteclient.RemoteClientStatus {
65
        private ArrayList                 layerList      = null;
66
        private ArrayList                 tileMatrixSet  = null;
67
        private WMTSThemes                themes         = null;
68
        private WMTSServiceIdentification serviceId      = null;
69
        private WMTSServiceProvider       serviceProv    = null;
70
        private String                    version        = null;
71
72
        public WMTSServerDescription(String version) {
73
                this.version = version;
74
        }
75
76
        /**
77
         * Builds a new layer using the version number
78
         * @return
79
         */
80
        public WMTSLayer buildNewLayer() {
81
                try {
82
                        Class clase;
83
                        version = version.replace('.', '_');
84
                        clase = Class.forName("org.gvsig.remoteclient.wmts.wmts_" + version + ".struct.WMTSLayer_" + version);
85
                        Class [] args = {WMTSServerDescription.class};
86
                        try {
87
                                Constructor hazNuevo = clase.getConstructor(args);
88
                                Object [] args2 = {this};
89
                                return (WMTSLayer) hazNuevo.newInstance(args2);
90
                        } catch (SecurityException e) {
91
                                throw new WMTSException("Error SecurityException in open", e);
92
                        } catch (NoSuchMethodException e) {
93
                                throw new WMTSException("Error NoSuchMethodException in open", e);
94
                        } catch (IllegalArgumentException e) {
95
                                throw new WMTSException("Error IllegalArgumentException in open", e);
96
                        } catch (InstantiationException e) {
97
                                throw new WMTSException("Error InstantiationException in open", e);
98
                        } catch (IllegalAccessException e) {
99
                                throw new WMTSException("Error IllegalAccessException in open", e);
100
                        } catch (InvocationTargetException e) {
101
                                throw new WMTSException("Error opening this image with " + clase, e);
102
                        }
103
                } catch (Exception e) {
104
                        e.printStackTrace();
105
                        //throw new Exception("WMSDriverFactory. Unknown driver version " + e);
106
                        return null;
107
                }
108
        }
109
110
        /**
111
         * It creates an instance of a WMSDriver class.
112
         *
113
         * @param String, with the version of the driver to be created
114
         * @return WMSDriver.
115
         */
116
        public Object createVersionObject(String className) {
117
                return createVersionObject(className, version);
118
        }
119
120
    /**
121
     * It creates an instance of a WMSDriver class.
122
     *
123
     * @param String, with the version of the driver to be created
124
     * @return WMSDriver.
125
     */
126
        public Object createVersionObject(String className, String version) {
127
                try {
128
                        Class driver;
129
                        version = version.replace('.', '_');
130
                        driver = Class.forName("org.gvsig.remoteclient.wmts.wmts_" + version + ".struct." + className + "_" + version);
131
                        return driver.newInstance();
132
                } catch (Exception e) {
133
                        e.printStackTrace();
134
                        //throw new Exception("WMSDriverFactory. Unknown driver version " + e);
135
                        return null;
136
                }
137
        }
138
139
        /**
140
         * Gets the layer structure
141
         * @return
142
         */
143
        public WMTSServiceIdentification getServiceIdentification() {
144
                if(serviceId == null)
145
                        serviceId = (WMTSServiceIdentification)createVersionObject("WMTSServiceIdentification", version);
146
                return serviceId;
147
        }
148
149
        /**
150
         * Gets the layer structure
151
         * @return
152
         */
153
        public WMTSServiceProvider getServiceProvider() {
154
                if(serviceProv == null)
155
                        serviceProv = (WMTSServiceProvider)createVersionObject("WMTSServiceProvider", version);
156
                return serviceProv;
157
        }
158
159
        /**
160
         * Gets the list of WMTSLayer
161
         */
162
        public ArrayList getLayerList() {
163
                if(layerList == null)
164
                        layerList = new ArrayList();
165
                return layerList;
166
        }
167
168
        /**
169
         * Gets the list of WMTSTileMatrixSet
170
         * @return
171
         */
172
        public ArrayList getTileMatrixSet() {
173
                if(tileMatrixSet == null)
174
                        tileMatrixSet = new ArrayList();
175
                return tileMatrixSet;
176
        }
177
178
        /**
179
         * Gets the layer structure
180
         * @return
181
         */
182
        public WMTSThemes getThemes() {
183
                if(themes == null)
184
                        themes = (WMTSThemes)createVersionObject("WMTSThemes", version);
185
                return themes;
186
        }
187
188
        /**
189
         * Gets a layer by its title
190
         * @param titleLayer
191
         * @return
192
         */
193
        public WMTSLayer getLayerByTitle(String titleLayer) {
194
                for (int i = 0; i < layerList.size(); i++) {
195
                        WMTSLayer layer = ((WMTSLayer)layerList.get(i));
196
                        if(layer.getTitle().compareTo(titleLayer) == 0) {
197
                                return layer;
198
                        }
199
                }
200
                return null;
201
        }
202
203
        /**
204
         * Clean all attributes
205
         */
206
        public void clear() {
207
                if(layerList != null)
208
                        layerList.clear();
209
                if(tileMatrixSet != null)
210
                        tileMatrixSet.clear();
211
                themes = null;
212
                serviceId = null;
213
                serviceProv = null;
214
        }
215
}