root / tags / v2_0_0_Build_2049 / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / impl / DefaultMapContextManager.java @ 38488
History | View | Annotate | Download (19.2 KB)
1 | 28882 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | 31544 | cordinyana | * of the Valencian Government (CIT)
|
5 | 30183 | jmvivo | *
|
6 | 28882 | cordinyana | * 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 | 30183 | jmvivo | *
|
11 | 28882 | cordinyana | * 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 | 30183 | jmvivo | *
|
16 | 28882 | cordinyana | * 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 | 30183 | jmvivo | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 28882 | cordinyana | * MA 02110-1301, USA.
|
20 | 30183 | jmvivo | *
|
21 | 28882 | cordinyana | */
|
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2009 {DiSiD Technologies} {Create Manager to register MapContextDrawer implementation}
|
||
26 | */
|
||
27 | package org.gvsig.fmap.mapcontext.impl; |
||
28 | |||
29 | 30011 | cordinyana | import java.awt.Color; |
30 | import java.awt.Font; |
||
31 | import java.io.File; |
||
32 | 30892 | cordinyana | import java.io.FileFilter; |
33 | 33339 | jpiera | import java.io.FileInputStream; |
34 | 37491 | jpiera | import java.io.FileNotFoundException; |
35 | import java.io.IOException; |
||
36 | 33339 | jpiera | import java.lang.reflect.Method; |
37 | 30011 | cordinyana | import java.util.Collections; |
38 | import java.util.HashMap; |
||
39 | import java.util.Map; |
||
40 | |||
41 | 30748 | jpiera | import org.cresques.cts.IProjection; |
42 | 33615 | cordinyana | import org.slf4j.Logger; |
43 | import org.slf4j.LoggerFactory; |
||
44 | |||
45 | 33339 | jpiera | import org.gvsig.fmap.dal.DataServerExplorer; |
46 | 32923 | jjdelcerro | import org.gvsig.fmap.dal.DataStore; |
47 | import org.gvsig.fmap.dal.DataStoreParameters; |
||
48 | 33339 | jpiera | import org.gvsig.fmap.dal.exception.DataException; |
49 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
50 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
51 | 28882 | cordinyana | import org.gvsig.fmap.mapcontext.MapContextDrawer; |
52 | import org.gvsig.fmap.mapcontext.MapContextException; |
||
53 | 30892 | cordinyana | import org.gvsig.fmap.mapcontext.MapContextLocator; |
54 | 28882 | cordinyana | import org.gvsig.fmap.mapcontext.MapContextManager; |
55 | 30011 | cordinyana | import org.gvsig.fmap.mapcontext.MapContextRuntimeException; |
56 | 32923 | jjdelcerro | import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
57 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
58 | import org.gvsig.fmap.mapcontext.layers.LayerFactory; |
||
59 | 30011 | cordinyana | import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer; |
60 | 30183 | jmvivo | import org.gvsig.fmap.mapcontext.layers.vectorial.impl.DefaultGraphicLayer; |
61 | 30011 | cordinyana | import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
62 | import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
||
63 | 31631 | jpiera | import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend; |
64 | 30011 | cordinyana | import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendReader; |
65 | import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter; |
||
66 | 37491 | jpiera | import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
67 | 30011 | cordinyana | import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
68 | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
||
69 | import org.gvsig.fmap.mapcontext.rendering.symbols.IWarningSymbol; |
||
70 | 30892 | cordinyana | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolException; |
71 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
||
72 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences; |
||
73 | 33339 | jpiera | import org.gvsig.tools.ToolsLocator; |
74 | import org.gvsig.tools.dynobject.exception.DynMethodException; |
||
75 | import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException; |
||
76 | import org.gvsig.tools.persistence.PersistenceManager; |
||
77 | 28882 | cordinyana | |
78 | /**
|
||
79 | * Default implementation of the {@link MapContextManager}.
|
||
80 | 30183 | jmvivo | *
|
81 | 28882 | cordinyana | * @author <a href="mailto:cordinyana@gvsig.org">C?sar Ordi?ana</a>
|
82 | */
|
||
83 | public class DefaultMapContextManager implements MapContextManager { |
||
84 | 33339 | jpiera | |
85 | 33615 | cordinyana | private static final Logger LOG = LoggerFactory |
86 | .getLogger(DefaultMapContextManager.class); |
||
87 | |||
88 | 30011 | cordinyana | private Class drawerClazz = DefaultMapContextDrawer.class; |
89 | 28882 | cordinyana | |
90 | 30011 | cordinyana | private Map legends = Collections.synchronizedMap(new HashMap()); |
91 | 28882 | cordinyana | |
92 | 30011 | cordinyana | private Map legendReaders = Collections.synchronizedMap(new HashMap()); |
93 | 28882 | cordinyana | |
94 | 30011 | cordinyana | private Map legendWriters = Collections.synchronizedMap(new HashMap()); |
95 | 28882 | cordinyana | |
96 | 30011 | cordinyana | private String defaultVectorLegend; |
97 | |||
98 | 30892 | cordinyana | public SymbolManager getSymbolManager() {
|
99 | return MapContextLocator.getSymbolManager();
|
||
100 | } |
||
101 | 30011 | cordinyana | |
102 | 30892 | cordinyana | private SymbolPreferences getSymbolPreferences() {
|
103 | return getSymbolManager().getSymbolPreferences();
|
||
104 | 30011 | cordinyana | } |
105 | |||
106 | public String getSymbolLibraryPath() { |
||
107 | 30892 | cordinyana | return getSymbolPreferences().getSymbolLibraryPath();
|
108 | 30011 | cordinyana | } |
109 | |||
110 | public void setSymbolLibraryPath(String symbolLibraryPath) { |
||
111 | 30892 | cordinyana | getSymbolPreferences().setSymbolLibraryPath(symbolLibraryPath); |
112 | 30011 | cordinyana | } |
113 | |||
114 | public void resetSymbolLibraryPath() { |
||
115 | 30892 | cordinyana | getSymbolPreferences().resetSymbolLibraryPath(); |
116 | 30011 | cordinyana | } |
117 | |||
118 | public Color getDefaultSymbolColor() { |
||
119 | 30892 | cordinyana | return getSymbolPreferences().getDefaultSymbolColor();
|
120 | 30011 | cordinyana | } |
121 | |||
122 | 30892 | cordinyana | public Color getDefaultSymbolFillColor() { |
123 | return getSymbolPreferences().getDefaultSymbolFillColor();
|
||
124 | 30011 | cordinyana | } |
125 | |||
126 | 30892 | cordinyana | public Font getDefaultSymbolFont() { |
127 | return getSymbolPreferences().getDefaultSymbolFont();
|
||
128 | 30011 | cordinyana | } |
129 | |||
130 | 30892 | cordinyana | public String getSymbolFileExtension() { |
131 | return getSymbolPreferences().getSymbolFileExtension();
|
||
132 | 30011 | cordinyana | } |
133 | |||
134 | 30892 | cordinyana | public boolean isDefaultSymbolFillColorAleatory() { |
135 | return getSymbolPreferences().isDefaultSymbolFillColorAleatory();
|
||
136 | 30011 | cordinyana | } |
137 | |||
138 | 30892 | cordinyana | public void resetDefaultSymbolColor() { |
139 | getSymbolPreferences().resetDefaultSymbolColor(); |
||
140 | } |
||
141 | |||
142 | 30011 | cordinyana | public void resetDefaultSymbolFillColor() { |
143 | 30892 | cordinyana | getSymbolPreferences().resetDefaultSymbolFillColor(); |
144 | 30011 | cordinyana | } |
145 | |||
146 | 30892 | cordinyana | public void resetDefaultSymbolFillColorAleatory() { |
147 | getSymbolPreferences().resetDefaultSymbolFillColorAleatory(); |
||
148 | 30011 | cordinyana | } |
149 | |||
150 | 30892 | cordinyana | public void resetDefaultSymbolFont() { |
151 | getSymbolPreferences().resetDefaultSymbolFont(); |
||
152 | 30011 | cordinyana | } |
153 | 30183 | jmvivo | |
154 | 30892 | cordinyana | public void setDefaultSymbolColor(Color defaultSymbolColor) { |
155 | getSymbolPreferences().setDefaultSymbolColor(defaultSymbolColor); |
||
156 | 30011 | cordinyana | } |
157 | |||
158 | 30892 | cordinyana | public void setDefaultSymbolFillColor(Color defaultSymbolFillColor) { |
159 | getSymbolPreferences().setDefaultSymbolFillColor(defaultSymbolFillColor); |
||
160 | 30011 | cordinyana | } |
161 | |||
162 | 30892 | cordinyana | public void setDefaultSymbolFillColorAleatory( |
163 | boolean defaultSymbolFillColorAleatory) {
|
||
164 | getSymbolPreferences().setDefaultSymbolFillColorAleatory( |
||
165 | defaultSymbolFillColorAleatory); |
||
166 | } |
||
167 | |||
168 | 30011 | cordinyana | public void setDefaultSymbolFont(Font defaultSymbolFont) { |
169 | 30892 | cordinyana | getSymbolPreferences().setDefaultSymbolFont(defaultSymbolFont); |
170 | 30011 | cordinyana | } |
171 | 30183 | jmvivo | |
172 | 30892 | cordinyana | public void setSymbolFileExtension(String extension) { |
173 | getSymbolPreferences().setSymbolFileExtension(extension); |
||
174 | 30011 | cordinyana | } |
175 | |||
176 | public int getDefaultCartographicSupportMeasureUnit() { |
||
177 | 30892 | cordinyana | return getSymbolPreferences().getDefaultCartographicSupportMeasureUnit();
|
178 | 30011 | cordinyana | } |
179 | |||
180 | public void setDefaultCartographicSupportMeasureUnit( |
||
181 | int defaultCartographicSupportMeasureUnit) {
|
||
182 | 30892 | cordinyana | getSymbolPreferences().setDefaultCartographicSupportMeasureUnit( |
183 | defaultCartographicSupportMeasureUnit); |
||
184 | 30011 | cordinyana | } |
185 | |||
186 | public int getDefaultCartographicSupportReferenceSystem() { |
||
187 | 30892 | cordinyana | return getSymbolPreferences().getDefaultCartographicSupportReferenceSystem();
|
188 | 30011 | cordinyana | } |
189 | |||
190 | public void setDefaultCartographicSupportReferenceSystem( |
||
191 | int defaultCartographicSupportReferenceSystem) {
|
||
192 | 30892 | cordinyana | getSymbolPreferences().setDefaultCartographicSupportReferenceSystem( |
193 | defaultCartographicSupportReferenceSystem); |
||
194 | 30011 | cordinyana | } |
195 | |||
196 | public MapContextDrawer createMapContextDrawerInstance(Class drawerClazz) |
||
197 | 33339 | jpiera | throws MapContextException {
|
198 | 30011 | cordinyana | return createMapContextDrawerInstance(drawerClazz, "NONE"); |
199 | } |
||
200 | |||
201 | public MapContextDrawer createDefaultMapContextDrawerInstance()
|
||
202 | 33339 | jpiera | throws MapContextException {
|
203 | 30011 | cordinyana | |
204 | return createMapContextDrawerInstance(drawerClazz, "default"); |
||
205 | } |
||
206 | |||
207 | private MapContextDrawer createMapContextDrawerInstance(Class drawerClazz, |
||
208 | String name) throws RegisteredClassInstantiationException { |
||
209 | try {
|
||
210 | return (MapContextDrawer) drawerClazz.newInstance();
|
||
211 | } catch (Exception ex) { |
||
212 | throw new RegisteredClassInstantiationException( |
||
213 | MapContextDrawer.class, drawerClazz, name, ex); |
||
214 | } |
||
215 | } |
||
216 | |||
217 | public void setDefaultMapContextDrawer(Class drawerClazz) |
||
218 | 33339 | jpiera | throws MapContextException {
|
219 | 30011 | cordinyana | |
220 | validateMapContextDrawer(drawerClazz); |
||
221 | this.drawerClazz = drawerClazz;
|
||
222 | } |
||
223 | |||
224 | public void validateMapContextDrawer(Class drawerClazz) |
||
225 | 33339 | jpiera | throws MapContextException {
|
226 | 30011 | cordinyana | if (!MapContextDrawer.class.isAssignableFrom(drawerClazz)) {
|
227 | throw new InvalidRegisteredClassException(MapContextDrawer.class, |
||
228 | drawerClazz, "UNKNOWN");
|
||
229 | } |
||
230 | } |
||
231 | |||
232 | 30748 | jpiera | public GraphicLayer createGraphicsLayer(IProjection projection) {
|
233 | DefaultGraphicLayer layer = new DefaultGraphicLayer();
|
||
234 | try {
|
||
235 | layer.initialize(projection); |
||
236 | 31631 | jpiera | layer.setLegend((IVectorLegend)createLegend(IVectorialUniqueValueLegend.LEGEND_NAME)); |
237 | 30748 | jpiera | } catch (Exception e) { |
238 | 33030 | jjdelcerro | LOG.error("Error initializing the graphics layer", e);
|
239 | 30748 | jpiera | } |
240 | return layer;
|
||
241 | 30011 | cordinyana | } |
242 | |||
243 | public String getDefaultVectorLegend() { |
||
244 | return defaultVectorLegend;
|
||
245 | } |
||
246 | |||
247 | public void setDefaultVectorLegend(String defaultVectorLegend) { |
||
248 | this.defaultVectorLegend = defaultVectorLegend;
|
||
249 | } |
||
250 | |||
251 | public void registerLegend(String legendName, Class legendClass) |
||
252 | 33339 | jpiera | throws MapContextRuntimeException {
|
253 | 30011 | cordinyana | |
254 | if (legendClass == null || !ILegend.class.isAssignableFrom(legendClass)) { |
||
255 | throw new InvalidRegisteredClassException(ILegend.class, |
||
256 | legendClass, legendName); |
||
257 | } |
||
258 | |||
259 | legends.put(legendName, legendClass); |
||
260 | } |
||
261 | |||
262 | public ILegend createLegend(String legendName) |
||
263 | 33339 | jpiera | throws MapContextRuntimeException {
|
264 | 30011 | cordinyana | Class legendClass = (Class) legends.get(legendName); |
265 | |||
266 | if (legendClass != null) { |
||
267 | try {
|
||
268 | return (ILegend) legendClass.newInstance();
|
||
269 | } catch (InstantiationException e) { |
||
270 | throw new RegisteredClassInstantiationException(ILegend.class, |
||
271 | legendClass, legendName, e); |
||
272 | } catch (IllegalAccessException e) { |
||
273 | throw new RegisteredClassInstantiationException(ILegend.class, |
||
274 | legendClass, legendName, e); |
||
275 | } |
||
276 | } |
||
277 | return null; |
||
278 | } |
||
279 | |||
280 | 37298 | jpiera | public IVectorLegend createDefaultVectorLegend(int shapeType) |
281 | throws MapContextRuntimeException {
|
||
282 | try {
|
||
283 | 36666 | cordinyana | // Create legend
|
284 | IVectorLegend legend = |
||
285 | (IVectorLegend) createLegend(getDefaultVectorLegend()); |
||
286 | if (legend == null) { |
||
287 | return null; |
||
288 | } |
||
289 | // Set legend values
|
||
290 | 37298 | jpiera | legend.setShapeType(shapeType); |
291 | 36666 | cordinyana | legend.setDefaultSymbol(getSymbolManager().createSymbol(shapeType)); |
292 | 37298 | jpiera | return legend;
|
293 | } catch(Exception e) { |
||
294 | throw new MapContextRuntimeException(e); |
||
295 | } |
||
296 | } |
||
297 | 30011 | cordinyana | |
298 | public void registerLegendReader(String format, Class readerClass) |
||
299 | 33339 | jpiera | throws MapContextRuntimeException {
|
300 | 30011 | cordinyana | if (readerClass == null |
301 | || !ILegendReader.class.isAssignableFrom(readerClass)) { |
||
302 | throw new InvalidRegisteredClassException(ILegendReader.class, |
||
303 | readerClass, format); |
||
304 | } |
||
305 | |||
306 | legendReaders.put(format, readerClass); |
||
307 | } |
||
308 | |||
309 | public ILegendReader createLegendReader(String format) |
||
310 | 33339 | jpiera | throws MapContextRuntimeException {
|
311 | 30011 | cordinyana | Class legendReaderClazz = (Class) legendReaders.get(format); |
312 | |||
313 | if (legendReaderClazz != null) { |
||
314 | try {
|
||
315 | return (ILegendReader) legendReaderClazz.newInstance();
|
||
316 | } catch (InstantiationException e) { |
||
317 | throw new RegisteredClassInstantiationException( |
||
318 | ILegendReader.class, legendReaderClazz, format, e); |
||
319 | } catch (IllegalAccessException e) { |
||
320 | throw new RegisteredClassInstantiationException( |
||
321 | ILegendReader.class, legendReaderClazz, format, e); |
||
322 | } |
||
323 | } |
||
324 | return null; |
||
325 | } |
||
326 | |||
327 | public void registerLegendWriter(String legendName, String format, |
||
328 | Class writerClass) throws MapContextRuntimeException { |
||
329 | if (writerClass == null |
||
330 | || !ILegendWriter.class.isAssignableFrom(writerClass)) { |
||
331 | throw new InvalidRegisteredClassException(ILegendWriter.class, |
||
332 | writerClass, format.concat("-").concat(legendName));
|
||
333 | } |
||
334 | |||
335 | Map legendFormatWriters = (Map) legendWriters.get(format); |
||
336 | |||
337 | synchronized (legendWriters) {
|
||
338 | if (legendFormatWriters == null) { |
||
339 | legendFormatWriters = Collections
|
||
340 | 33339 | jpiera | .synchronizedMap(new HashMap()); |
341 | 30011 | cordinyana | legendWriters.put(format, legendFormatWriters); |
342 | } |
||
343 | } |
||
344 | |||
345 | legendFormatWriters.put(legendName, writerClass); |
||
346 | } |
||
347 | |||
348 | public ILegendWriter createLegendWriter(String legendName, String format) |
||
349 | 33339 | jpiera | throws MapContextRuntimeException {
|
350 | 30011 | cordinyana | Map legendFormatWriters = getLegendWritersForFormat(format);
|
351 | |||
352 | if (legendFormatWriters != null) { |
||
353 | Class legendWriterClazz = (Class) legendFormatWriters |
||
354 | 33339 | jpiera | .get(legendName); |
355 | 30011 | cordinyana | |
356 | if (legendWriterClazz != null) { |
||
357 | try {
|
||
358 | return (ILegendWriter) legendWriterClazz.newInstance();
|
||
359 | } catch (InstantiationException e) { |
||
360 | throw new RegisteredClassInstantiationException( |
||
361 | ILegendWriter.class, legendWriterClazz, format |
||
362 | 33339 | jpiera | .concat("-").concat(legendName), e);
|
363 | 30011 | cordinyana | } catch (IllegalAccessException e) { |
364 | throw new RegisteredClassInstantiationException( |
||
365 | ILegendWriter.class, legendWriterClazz, format |
||
366 | 33339 | jpiera | .concat("-").concat(legendName), e);
|
367 | 30011 | cordinyana | } |
368 | } |
||
369 | } |
||
370 | return null; |
||
371 | } |
||
372 | |||
373 | private Map getLegendWritersForFormat(String format) { |
||
374 | return (Map) legendWriters.get(format); |
||
375 | } |
||
376 | |||
377 | 30892 | cordinyana | public IMultiLayerSymbol createMultiLayerSymbol(int shapeType) |
378 | 33339 | jpiera | throws MapContextRuntimeException {
|
379 | 30892 | cordinyana | return getSymbolManager().createMultiLayerSymbol(shapeType);
|
380 | 30011 | cordinyana | } |
381 | |||
382 | 30892 | cordinyana | public IMultiLayerSymbol createMultiLayerSymbol(String symbolName) |
383 | 33339 | jpiera | throws MapContextRuntimeException {
|
384 | 30892 | cordinyana | return getSymbolManager().createMultiLayerSymbol(symbolName);
|
385 | 30011 | cordinyana | } |
386 | |||
387 | 30892 | cordinyana | public ISymbol createSymbol(int shapeType, Color color) |
388 | 33339 | jpiera | throws MapContextRuntimeException {
|
389 | 30892 | cordinyana | return getSymbolManager().createSymbol(shapeType, color);
|
390 | 30011 | cordinyana | } |
391 | |||
392 | 30892 | cordinyana | public ISymbol createSymbol(int shapeType) |
393 | 33339 | jpiera | throws MapContextRuntimeException {
|
394 | 30892 | cordinyana | return getSymbolManager().createSymbol(shapeType);
|
395 | 30011 | cordinyana | } |
396 | |||
397 | 30892 | cordinyana | public ISymbol createSymbol(String symbolName, Color color) |
398 | 33339 | jpiera | throws MapContextRuntimeException {
|
399 | 30892 | cordinyana | return getSymbolManager().createSymbol(symbolName, color);
|
400 | 30011 | cordinyana | } |
401 | |||
402 | 30892 | cordinyana | public ISymbol createSymbol(String symbolName) |
403 | 33339 | jpiera | throws MapContextRuntimeException {
|
404 | 30892 | cordinyana | return getSymbolManager().createSymbol(symbolName);
|
405 | } |
||
406 | 30011 | cordinyana | |
407 | 30892 | cordinyana | public IWarningSymbol getWarningSymbol(String message, String symbolDesc, |
408 | int symbolDrawExceptionType) throws MapContextRuntimeException { |
||
409 | return getSymbolManager().getWarningSymbol(message, symbolDesc,
|
||
410 | symbolDrawExceptionType); |
||
411 | 30011 | cordinyana | } |
412 | |||
413 | 30892 | cordinyana | public ISymbol[] loadSymbols(File folder, FileFilter filter) |
414 | 33339 | jpiera | throws SymbolException {
|
415 | 30892 | cordinyana | return getSymbolManager().loadSymbols(folder, filter);
|
416 | 30011 | cordinyana | } |
417 | |||
418 | 30892 | cordinyana | public ISymbol[] loadSymbols(File folder) throws SymbolException { |
419 | return getSymbolManager().loadSymbols(folder);
|
||
420 | 30011 | cordinyana | } |
421 | |||
422 | public void registerMultiLayerSymbol(String symbolName, Class symbolClass) |
||
423 | 33339 | jpiera | throws MapContextRuntimeException {
|
424 | 30892 | cordinyana | getSymbolManager().registerMultiLayerSymbol(symbolName, symbolClass); |
425 | 30011 | cordinyana | } |
426 | |||
427 | public void registerMultiLayerSymbol(String symbolName, int[] shapeTypes, |
||
428 | Class symbolClass) throws MapContextRuntimeException { |
||
429 | 30892 | cordinyana | getSymbolManager().registerMultiLayerSymbol(symbolName, shapeTypes, |
430 | symbolClass); |
||
431 | 30011 | cordinyana | } |
432 | |||
433 | 30892 | cordinyana | public void registerSymbol(String symbolName, Class symbolClass) |
434 | 33339 | jpiera | throws MapContextRuntimeException {
|
435 | 30892 | cordinyana | getSymbolManager().registerSymbol(symbolName, symbolClass); |
436 | } |
||
437 | 30011 | cordinyana | |
438 | 30892 | cordinyana | public void registerSymbol(String symbolName, int[] shapeTypes, |
439 | Class symbolClass) throws MapContextException { |
||
440 | getSymbolManager().registerSymbol(symbolName, shapeTypes, symbolClass); |
||
441 | } |
||
442 | 30011 | cordinyana | |
443 | 30892 | cordinyana | public void saveSymbol(ISymbol symbol, String fileName, File folder, |
444 | boolean overwrite) throws SymbolException { |
||
445 | getSymbolManager().saveSymbol(symbol, fileName, folder, overwrite); |
||
446 | 30011 | cordinyana | } |
447 | |||
448 | 30892 | cordinyana | public void saveSymbol(ISymbol symbol, String fileName, File folder) |
449 | 33339 | jpiera | throws SymbolException {
|
450 | 30892 | cordinyana | getSymbolManager().saveSymbol(symbol, fileName, folder); |
451 | 30011 | cordinyana | } |
452 | 32923 | jjdelcerro | |
453 | public FLayer createLayer(String layerName, DataStoreParameters parameters) |
||
454 | 33339 | jpiera | throws LoadLayerException {
|
455 | 32923 | jjdelcerro | return LayerFactory.getInstance().createLayer(layerName, parameters);
|
456 | } |
||
457 | |||
458 | public FLayer createLayer(String layerName, DataStore store) |
||
459 | 33339 | jpiera | throws LoadLayerException {
|
460 | 32923 | jjdelcerro | return LayerFactory.getInstance().createLayer(layerName, store);
|
461 | } |
||
462 | 33339 | jpiera | |
463 | public ILegend getLegend(DataStore dataStore) {
|
||
464 | ILegend legend = null;
|
||
465 | |||
466 | 37491 | jpiera | File file = getResourcePathByReflection(dataStore, SymbolManager.LEGEND_FILE_EXTENSION.substring(1)); |
467 | try{
|
||
468 | if ((file != null) && (file.exists())){ |
||
469 | PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
||
470 | FileInputStream is = new FileInputStream(file); |
||
471 | legend = (ILegend) persistenceManager.getObject(is); |
||
472 | is.close(); |
||
473 | } |
||
474 | } catch (FileNotFoundException e){ |
||
475 | LOG.error("Legend not found", e);
|
||
476 | } catch (IOException e) { |
||
477 | LOG.error("Error reading the legend", e);
|
||
478 | } |
||
479 | |||
480 | 33339 | jpiera | //If the legend is null, next option is to check if the store has the getLegend method
|
481 | if (legend == null){ |
||
482 | try {
|
||
483 | legend = (IVectorLegend) dataStore.invokeDynMethod( |
||
484 | "getLegend", null); |
||
485 | } catch (DynMethodNotSupportedException e) {
|
||
486 | 36725 | cordinyana | LOG.debug("This store {} does not provide a legend.",
|
487 | dataStore.getName()); |
||
488 | 33339 | jpiera | } catch (DynMethodException e) {
|
489 | 36725 | cordinyana | LOG.error( |
490 | "Can't load the specific legend provided for the store {}.",
|
||
491 | dataStore.getName(), e); |
||
492 | 33339 | jpiera | } |
493 | } |
||
494 | |||
495 | //If legend is null, last step is just try to create the legend by default
|
||
496 | if( legend == null ) { |
||
497 | FeatureType featureType; |
||
498 | try {
|
||
499 | featureType = (((FeatureStore)dataStore).getDefaultFeatureType()); |
||
500 | int indexGeom = featureType.getDefaultGeometryAttributeIndex();
|
||
501 | int typeShape = featureType.getAttributeDescriptor(indexGeom).getGeometryType();
|
||
502 | 38443 | cordinyana | legend = createDefaultVectorLegend(typeShape); |
503 | 33339 | jpiera | } catch (DataException e) {
|
504 | LOG.error("Error getting the default feature type", e);
|
||
505 | } |
||
506 | } |
||
507 | |||
508 | return legend;
|
||
509 | } |
||
510 | |||
511 | 37491 | jpiera | public ILabelingStrategy getLabelingStrategy(DataStore dataStore) {
|
512 | ILabelingStrategy labelingStrategy = null;
|
||
513 | |||
514 | File file = getResourcePathByReflection(dataStore, SymbolManager.LABELINGSTRATEGY_FILE_EXTENSION.substring(1)); |
||
515 | try{
|
||
516 | if ((file != null) && (file.exists())){ |
||
517 | PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
||
518 | FileInputStream is = new FileInputStream(file); |
||
519 | labelingStrategy = (ILabelingStrategy) persistenceManager.getObject(is); |
||
520 | is.close(); |
||
521 | } |
||
522 | } catch (FileNotFoundException e){ |
||
523 | LOG.error("Label strategy not found", e);
|
||
524 | } catch (IOException e) { |
||
525 | LOG.error("Error reading the labeling strategy", e);
|
||
526 | } |
||
527 | |||
528 | //If the legend is null, next option is to check if the store has the getLegend method
|
||
529 | if (labelingStrategy == null){ |
||
530 | try {
|
||
531 | labelingStrategy = |
||
532 | (ILabelingStrategy) dataStore.invokeDynMethod("getLabeling",
|
||
533 | null);
|
||
534 | } catch (DynMethodNotSupportedException e1) {
|
||
535 | labelingStrategy = null;
|
||
536 | } catch (DynMethodException e1) {
|
||
537 | LOG.error("Can't load the specific lebeling strategy provided for the datastore {}.",
|
||
538 | dataStore.getName(), |
||
539 | e1); |
||
540 | } |
||
541 | } |
||
542 | |||
543 | return labelingStrategy;
|
||
544 | } |
||
545 | |||
546 | private File getResourcePathByReflection(DataStore dataStore, String resource){ |
||
547 | //Loading the file from a store based on file
|
||
548 | DataServerExplorer dataServerExplorer = null;
|
||
549 | try {
|
||
550 | dataServerExplorer = dataStore.getExplorer(); |
||
551 | Class[] args = new Class[2]; |
||
552 | args[0] = DataStore.class;
|
||
553 | args[1] = String.class; |
||
554 | Method method = dataStore.getExplorer().getClass().getMethod("getResourcePath", args); |
||
555 | if (method != null){ |
||
556 | Object[] params = new Object[2]; |
||
557 | params[0] = dataStore;
|
||
558 | params[1] = resource;
|
||
559 | return (File)method.invoke(dataServerExplorer, params); |
||
560 | } |
||
561 | } catch (Exception e) { |
||
562 | LOG.debug( |
||
563 | "Can't load the specific legend provided by the explorer "
|
||
564 | + dataServerExplorer, e); |
||
565 | } |
||
566 | return null; |
||
567 | } |
||
568 | 28882 | cordinyana | } |