svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.api / src / main / java / org / gvsig / fmap / mapcontext / layers / LayerFactory.java @ 44831
History | View | Annotate | Download (7.09 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.fmap.mapcontext.layers; |
25 |
|
26 |
import org.gvsig.fmap.dal.DataManager; |
27 |
import org.gvsig.fmap.dal.DataStore; |
28 |
import org.gvsig.fmap.dal.DataStoreParameters; |
29 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
30 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
31 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
32 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
33 |
|
34 |
/**
|
35 |
* Crea un adaptador del driver que se le pasa como par?metro en los m?todos
|
36 |
* createLayer. Si hay memoria suficiente se crea un FLyrMemory que pasa todas
|
37 |
* las features del driver a memoria
|
38 |
*
|
39 |
* @deprecated use MapContextManager
|
40 |
*/
|
41 |
public class LayerFactory { |
42 |
// final static private Logger logger = LoggerFactory.getLogger(LayerFactory.class);
|
43 |
|
44 |
private static LayerFactory instance = null; |
45 |
|
46 |
public static LayerFactory getInstance() { |
47 |
if (instance == null) { |
48 |
instance = new LayerFactory();
|
49 |
} |
50 |
return instance;
|
51 |
} |
52 |
|
53 |
/**
|
54 |
* Guarda registro de que clase de capa debe usar para un determinado Store
|
55 |
*
|
56 |
* como clave usamos el nombre de registro del dataStore
|
57 |
*/
|
58 |
// private Map layersToUseForStore = new HashMap();
|
59 |
|
60 |
/**
|
61 |
* Registra que clase tiene que usar para un {@link DataStore} determinado. <br>
|
62 |
* Por defecto, si el
|
63 |
*
|
64 |
*
|
65 |
* @param dataStoreName
|
66 |
* Nombre de registro del {@link DataStore} dentro del
|
67 |
* {@link DataManager}
|
68 |
* @param layerClassToUse
|
69 |
* clase que implementa {@link SingleLayer}
|
70 |
* @return
|
71 |
*/
|
72 |
|
73 |
public boolean registerLayerToUseForStore( |
74 |
String dataStoreName,
|
75 |
Class layerClassToUse
|
76 |
) { |
77 |
throw new UnsupportedOperationException("This method is deprecated use MapContextMananer.registerLayer"); |
78 |
// DataManager dm = DALLocator.getDataManager();
|
79 |
// DataStoreParameters dsparams;
|
80 |
// try {
|
81 |
// dsparams = dm.createStoreParameters(dataStoreName);
|
82 |
// } catch (InitializeException e) {
|
83 |
// e.printStackTrace();
|
84 |
// return false;
|
85 |
// } catch (ProviderNotRegisteredException e) {
|
86 |
// e.printStackTrace();
|
87 |
// return false;
|
88 |
// }
|
89 |
// if (!layerClassToUse.isAssignableFrom(SingleLayer.class)) {
|
90 |
// return false;
|
91 |
// }
|
92 |
// this.layersToUseForStore.put(dsparams.getDataStoreName(),
|
93 |
// layerClassToUse);
|
94 |
//
|
95 |
// return true;
|
96 |
} |
97 |
|
98 |
public boolean registerLayerToUseForStore( |
99 |
Class storeClass,
|
100 |
Class layerClassToUse)
|
101 |
{ |
102 |
MapContextManager manager = MapContextLocator.getMapContextManager(); |
103 |
manager.registerLayer(storeClass, layerClassToUse); |
104 |
//// DataManager dm = DALLocator.getDataManager();
|
105 |
// if (!DataStore.class.isAssignableFrom(storeClass)) {
|
106 |
// return false;
|
107 |
// }
|
108 |
//
|
109 |
// if (!SingleLayer.class.isAssignableFrom(layerClassToUse)
|
110 |
// || !FLayer.class.isAssignableFrom(layerClassToUse)) {
|
111 |
// return false;
|
112 |
// }
|
113 |
// this.layersToUseForStore.put(storeClass,
|
114 |
// layerClassToUse);
|
115 |
//
|
116 |
return true; |
117 |
} |
118 |
|
119 |
// private Class getLayerClassFor(DataStore store) {
|
120 |
// Class result = (Class) this.layersToUseForStore.get(store.getName());
|
121 |
// if (result == null) {
|
122 |
// Iterator iter = this.layersToUseForStore.entrySet().iterator();
|
123 |
// Map.Entry entry;
|
124 |
// Class key;
|
125 |
// while (iter.hasNext()) {
|
126 |
// entry = (Entry) iter.next();
|
127 |
// if (entry.getKey() instanceof Class) {
|
128 |
// key = (Class) entry.getKey();
|
129 |
// if (key.isAssignableFrom(store.getClass())) {
|
130 |
// result = (Class) entry.getValue();
|
131 |
// break;
|
132 |
// }
|
133 |
// }
|
134 |
// }
|
135 |
// }
|
136 |
// return result;
|
137 |
//
|
138 |
// }
|
139 |
|
140 |
|
141 |
|
142 |
/**
|
143 |
* @param layerName
|
144 |
* @param storeParameters
|
145 |
* @return
|
146 |
* @throws org.gvsig.fmap.mapcontext.exceptions.LoadLayerException
|
147 |
* @deprecated to be removed in gvSIG 2.1
|
148 |
* @see {@link MapContextManager}.
|
149 |
*/
|
150 |
public FLayer createLayer(
|
151 |
String layerName,
|
152 |
DataStoreParameters storeParameters |
153 |
) throws LoadLayerException {
|
154 |
MapContextManager manager = MapContextLocator.getMapContextManager(); |
155 |
return manager.createLayer(layerName, storeParameters);
|
156 |
// // Se obtiene el driver que lee
|
157 |
// try{
|
158 |
// DataManager dataManager=DALLocator.getDataManager();
|
159 |
// DataStore dataStore=dataManager.openStore(storeParameters.getDataStoreName(), storeParameters);
|
160 |
// return createLayer(layerName, dataStore);
|
161 |
// }catch (Exception e) {
|
162 |
// throw new LoadLayerException(layerName,e);
|
163 |
// }
|
164 |
} |
165 |
|
166 |
/**
|
167 |
* @param layerName
|
168 |
* @param dataStore
|
169 |
* @return
|
170 |
* @throws org.gvsig.fmap.mapcontext.exceptions.LoadLayerException
|
171 |
* @deprecated to be removed in gvSIG 2.1
|
172 |
* @see {@link MapContextManager}.
|
173 |
*/
|
174 |
public FLayer createLayer(
|
175 |
String layerName,
|
176 |
DataStore dataStore |
177 |
) throws LoadLayerException{
|
178 |
MapContextManager manager = MapContextLocator.getMapContextManager(); |
179 |
return manager.createLayer(layerName, dataStore);
|
180 |
// try{
|
181 |
// Class layerClass = this.getLayerClassFor(dataStore);
|
182 |
// if (layerClass == null) {
|
183 |
// throw new CantRetrieveLayerByStoreException(layerName,dataStore.getName());
|
184 |
// }
|
185 |
// FLayer layer;
|
186 |
// try {
|
187 |
// layer = (FLayer) layerClass.newInstance();
|
188 |
// } catch (InstantiationException e) {
|
189 |
// throw new LoadLayerException(layerName, e);
|
190 |
// } catch (IllegalAccessException e) {
|
191 |
// throw new LoadLayerException(layerName, e);
|
192 |
// }
|
193 |
//
|
194 |
// layer.setName(layerName);
|
195 |
// ((SingleLayer) layer).setDataStore(dataStore);
|
196 |
// IProjection proj = (IProjection)dataStore.getDynValue(FeatureStore.METADATA_CRS);
|
197 |
// if (proj != null) {
|
198 |
// layer.setProjection(proj);
|
199 |
// }
|
200 |
// layer.load();
|
201 |
// return layer;
|
202 |
// } catch (Exception e) {
|
203 |
// throw new LoadLayerException(layerName,e);
|
204 |
// }
|
205 |
} |
206 |
|
207 |
private class CantRetrieveLayerByStoreException extends LoadLayerException { |
208 |
|
209 |
/**
|
210 |
*
|
211 |
*/
|
212 |
private static final long serialVersionUID = 1442450896900126712L; |
213 |
|
214 |
CantRetrieveLayerByStoreException(String layerName, String storeName) { |
215 |
super(
|
216 |
"Can't retrieve the class leyer of %(layer) to use for store %(store).",
|
217 |
null,
|
218 |
"_Cant_retrieve_the_class_leyer_of_XlayerX_to_use_for_store_XstoreX",
|
219 |
serialVersionUID |
220 |
); |
221 |
setValue("layer", layerName);
|
222 |
setValue("store", storeName);
|
223 |
} |
224 |
} |
225 |
|
226 |
} |