root / trunk / extensions / extCatalogAndGazetteer / src / es / gva / cit / gvsig / catalog / loaders / LayerLoader.java @ 15557
History | View | Annotate | Download (3.91 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package es.gva.cit.gvsig.catalog.loaders; |
42 |
|
43 |
import java.lang.reflect.InvocationTargetException; |
44 |
import java.util.TreeMap; |
45 |
|
46 |
import com.iver.andami.PluginServices; |
47 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
48 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
49 |
|
50 |
import es.gva.cit.catalog.schemas.Resource; |
51 |
|
52 |
/**
|
53 |
* This class has to be inherited by all the classes
|
54 |
* that have to load a layer in the current view
|
55 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
56 |
*/
|
57 |
public abstract class LayerLoader { |
58 |
private static TreeMap loadersPool = new TreeMap(); |
59 |
|
60 |
static {
|
61 |
LayerLoader.addLoader(Resource.WMS, WMSLayerLoader.class); |
62 |
LayerLoader.addLoader(Resource.POSTGIS, PostgisLayerLoader.class); |
63 |
LayerLoader.addLoader(Resource.WCS, WCSLayerLoader.class); |
64 |
LayerLoader.addLoader(Resource.WEBSITE, LinkLoader.class); |
65 |
LayerLoader.addLoader(Resource.DOWNLOAD, LinkLoader.class); |
66 |
LayerLoader.addLoader(Resource.WFS, WFSLayerLoader.class); |
67 |
LayerLoader.addLoader(Resource.ARCIMS_IMAGE, ARCIMSLayerLoader.class); |
68 |
LayerLoader.addLoader(Resource.ARCIMS_VECTORIAL, ARCIMSLayerLoader.class); |
69 |
} |
70 |
|
71 |
public static void addLoader(String key, Class loader) { |
72 |
LayerLoader.loadersPool.put(key, loader); |
73 |
} |
74 |
|
75 |
public static LayerLoader getLoader(Resource resource) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { |
76 |
if (LayerLoader.loadersPool.containsKey(resource.getType())) {
|
77 |
Class llClass = (Class) LayerLoader.loadersPool.get(resource.getType()); |
78 |
Class [] args = {Resource.class}; |
79 |
Object [] params = {resource}; |
80 |
return (LayerLoader) llClass.getConstructor(args).newInstance(params);
|
81 |
} |
82 |
return null; |
83 |
} |
84 |
|
85 |
private Resource resource = null; |
86 |
|
87 |
public LayerLoader(Resource resource){
|
88 |
this.resource = resource;
|
89 |
} |
90 |
|
91 |
abstract public void loadLayer() throws LayerLoaderException; |
92 |
|
93 |
/**
|
94 |
* It returns the error message
|
95 |
* @return
|
96 |
* Error Message
|
97 |
*/
|
98 |
abstract protected String getErrorMessage(); |
99 |
|
100 |
/**
|
101 |
* It returns the window title for an window error message
|
102 |
* @return
|
103 |
* Window title
|
104 |
*/
|
105 |
abstract protected String getWindowMessage(); |
106 |
|
107 |
/**
|
108 |
* It adds a new layer to the current view
|
109 |
* @param lyr
|
110 |
* Layer lo load
|
111 |
*/
|
112 |
protected void addLayerToView(FLayer lyr) { |
113 |
View theView =
|
114 |
(View) PluginServices.getMDIManager().getActiveWindow();
|
115 |
|
116 |
if (lyr != null) { |
117 |
theView.getMapControl().getMapContext().beginAtomicEvent(); |
118 |
theView.getMapControl().getMapContext().getLayers().addLayer(lyr); |
119 |
theView.getMapControl().getMapContext().endAtomicEvent(); |
120 |
PluginServices.getMainFrame().enableControls(); |
121 |
} |
122 |
} |
123 |
|
124 |
public Resource getResource() {
|
125 |
return resource;
|
126 |
} |
127 |
|
128 |
public void setResource(Resource resource) { |
129 |
this.resource = resource;
|
130 |
} |
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
} |