svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / wmts / WMTSServerDescription.java @ 40769
History | View | Annotate | Download (5.76 KB)
1 |
/**
|
---|---|
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 |
package org.gvsig.remoteclient.wmts; |
25 |
|
26 |
import java.lang.reflect.Constructor; |
27 |
import java.lang.reflect.InvocationTargetException; |
28 |
import java.util.ArrayList; |
29 |
|
30 |
import org.gvsig.remoteclient.wmts.exception.WMTSException; |
31 |
import org.gvsig.remoteclient.wmts.struct.WMTSLayer; |
32 |
import org.gvsig.remoteclient.wmts.struct.WMTSServiceIdentification; |
33 |
import org.gvsig.remoteclient.wmts.struct.WMTSServiceProvider; |
34 |
import org.gvsig.remoteclient.wmts.struct.WMTSThemes; |
35 |
|
36 |
|
37 |
/**
|
38 |
* Describes the status of a WMTSclient, so it adds to the Remote client status
|
39 |
* a list of layers, a list of layer styles, the extent of the map.
|
40 |
*
|
41 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
42 |
*/
|
43 |
public class WMTSServerDescription extends org.gvsig.remoteclient.RemoteClientStatus { |
44 |
private ArrayList layerList = null; |
45 |
private ArrayList tileMatrixSet = null; |
46 |
private WMTSThemes themes = null; |
47 |
private WMTSServiceIdentification serviceId = null; |
48 |
private WMTSServiceProvider serviceProv = null; |
49 |
private String version = null; |
50 |
|
51 |
public WMTSServerDescription(String version) { |
52 |
this.version = version;
|
53 |
} |
54 |
|
55 |
/**
|
56 |
* Builds a new layer using the version number
|
57 |
* @return
|
58 |
*/
|
59 |
public WMTSLayer buildNewLayer() {
|
60 |
try {
|
61 |
Class clase;
|
62 |
version = version.replace('.', '_'); |
63 |
clase = Class.forName("org.gvsig.remoteclient.wmts.wmts_" + version + ".struct.WMTSLayer_" + version); |
64 |
Class [] args = {WMTSServerDescription.class}; |
65 |
try {
|
66 |
Constructor hazNuevo = clase.getConstructor(args);
|
67 |
Object [] args2 = {this}; |
68 |
return (WMTSLayer) hazNuevo.newInstance(args2);
|
69 |
} catch (SecurityException e) { |
70 |
throw new WMTSException("Error SecurityException in open", e); |
71 |
} catch (NoSuchMethodException e) { |
72 |
throw new WMTSException("Error NoSuchMethodException in open", e); |
73 |
} catch (IllegalArgumentException e) { |
74 |
throw new WMTSException("Error IllegalArgumentException in open", e); |
75 |
} catch (InstantiationException e) { |
76 |
throw new WMTSException("Error InstantiationException in open", e); |
77 |
} catch (IllegalAccessException e) { |
78 |
throw new WMTSException("Error IllegalAccessException in open", e); |
79 |
} catch (InvocationTargetException e) { |
80 |
throw new WMTSException("Error opening this image with " + clase, e); |
81 |
} |
82 |
} catch (Exception e) { |
83 |
e.printStackTrace(); |
84 |
//throw new Exception("WMSDriverFactory. Unknown driver version " + e);
|
85 |
return null; |
86 |
} |
87 |
} |
88 |
|
89 |
/**
|
90 |
* It creates an instance of a WMSDriver class.
|
91 |
*
|
92 |
* @param String, with the version of the driver to be created
|
93 |
* @return WMSDriver.
|
94 |
*/
|
95 |
public Object createVersionObject(String className) { |
96 |
return createVersionObject(className, version);
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* It creates an instance of a WMSDriver class.
|
101 |
*
|
102 |
* @param String, with the version of the driver to be created
|
103 |
* @return WMSDriver.
|
104 |
*/
|
105 |
public Object createVersionObject(String className, String version) { |
106 |
try {
|
107 |
Class driver;
|
108 |
version = version.replace('.', '_'); |
109 |
driver = Class.forName("org.gvsig.remoteclient.wmts.wmts_" + version + ".struct." + className + "_" + version); |
110 |
return driver.newInstance();
|
111 |
} catch (Exception e) { |
112 |
e.printStackTrace(); |
113 |
//throw new Exception("WMSDriverFactory. Unknown driver version " + e);
|
114 |
return null; |
115 |
} |
116 |
} |
117 |
|
118 |
/**
|
119 |
* Gets the layer structure
|
120 |
* @return
|
121 |
*/
|
122 |
public WMTSServiceIdentification getServiceIdentification() {
|
123 |
if(serviceId == null) |
124 |
serviceId = (WMTSServiceIdentification)createVersionObject("WMTSServiceIdentification", version);
|
125 |
return serviceId;
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* Gets the layer structure
|
130 |
* @return
|
131 |
*/
|
132 |
public WMTSServiceProvider getServiceProvider() {
|
133 |
if(serviceProv == null) |
134 |
serviceProv = (WMTSServiceProvider)createVersionObject("WMTSServiceProvider", version);
|
135 |
return serviceProv;
|
136 |
} |
137 |
|
138 |
/**
|
139 |
* Gets the list of WMTSLayer
|
140 |
*/
|
141 |
public ArrayList getLayerList() { |
142 |
if(layerList == null) |
143 |
layerList = new ArrayList(); |
144 |
return layerList;
|
145 |
} |
146 |
|
147 |
/**
|
148 |
* Gets the list of WMTSTileMatrixSet
|
149 |
* @return
|
150 |
*/
|
151 |
public ArrayList getTileMatrixSet() { |
152 |
if(tileMatrixSet == null) |
153 |
tileMatrixSet = new ArrayList(); |
154 |
return tileMatrixSet;
|
155 |
} |
156 |
|
157 |
/**
|
158 |
* Gets the layer structure
|
159 |
* @return
|
160 |
*/
|
161 |
public WMTSThemes getThemes() {
|
162 |
if(themes == null) |
163 |
themes = (WMTSThemes)createVersionObject("WMTSThemes", version);
|
164 |
return themes;
|
165 |
} |
166 |
|
167 |
/**
|
168 |
* Gets a layer by its title
|
169 |
* @param titleLayer
|
170 |
* @return
|
171 |
*/
|
172 |
public WMTSLayer getLayerByTitle(String titleLayer) { |
173 |
for (int i = 0; i < layerList.size(); i++) { |
174 |
WMTSLayer layer = ((WMTSLayer)layerList.get(i)); |
175 |
if(layer.getTitle().compareTo(titleLayer) == 0) { |
176 |
return layer;
|
177 |
} |
178 |
} |
179 |
return null; |
180 |
} |
181 |
|
182 |
/**
|
183 |
* Clean all attributes
|
184 |
*/
|
185 |
public void clear() { |
186 |
if(layerList != null) |
187 |
layerList.clear(); |
188 |
if(tileMatrixSet != null) |
189 |
tileMatrixSet.clear(); |
190 |
themes = null;
|
191 |
serviceId = null;
|
192 |
serviceProv = null;
|
193 |
} |
194 |
} |