root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / LayerFactory.java @ 851
History | View | Annotate | Download (8.49 KB)
1 |
/* Generated by Together */
|
---|---|
2 |
package com.iver.cit.gvsig.fmap.layers; |
3 |
|
4 |
import com.hardcode.driverManager.Driver; |
5 |
import com.hardcode.driverManager.DriverLoadException; |
6 |
import com.hardcode.driverManager.DriverManager; |
7 |
|
8 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
9 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
10 |
|
11 |
import com.iver.cit.gvsig.fmap.DriverException; |
12 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
13 |
import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
14 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
15 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
16 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
17 |
import com.iver.cit.gvsig.fmap.drivers.WMSDriver; |
18 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
19 |
import com.iver.cit.gvsig.fmap.drivers.wfs.WFSDriver; |
20 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
21 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
22 |
|
23 |
import org.apache.log4j.Logger; |
24 |
|
25 |
import org.cresques.cts.IProjection; |
26 |
|
27 |
import java.awt.geom.Rectangle2D; |
28 |
import java.io.File; |
29 |
|
30 |
import java.net.URL; |
31 |
|
32 |
import java.util.TreeMap; |
33 |
|
34 |
|
35 |
/**
|
36 |
* Crea un adaptador del driver que se le pasa como par?metro en los m?todos
|
37 |
* createLayer. Si hay memoria suficiente se crea un FLyrMemory que pasa todas
|
38 |
* las features del driver a memoria
|
39 |
*/
|
40 |
public class LayerFactory { |
41 |
private static Logger logger = Logger.getLogger(LayerFactory.class.getName()); |
42 |
private static String driversPath = "../FMap 03/drivers"; |
43 |
private static DriverManager driverManager; |
44 |
|
45 |
/**
|
46 |
* Map en el que se guarda para cada fuente de datos a?adida al sistema, el
|
47 |
* adaptador que la maneja. Ha de ser un TreeMap ya que esta clase define
|
48 |
* la igualdad entre las claves a traves del m?todo equals de las mismas.
|
49 |
* Los objetos FileSource, DBSource y WFSSource tienen definido el m?todo
|
50 |
* equals de forma que devuelven true cuando dos objetos apuntan a la
|
51 |
* misma fuente de datos
|
52 |
*/
|
53 |
private static TreeMap sourceAdapter; |
54 |
|
55 |
/**
|
56 |
* Crea un RandomVectorialFile con el driver que se le pasa como par?metro
|
57 |
* y guard?ndose el nombre del fichero para realizar los accesos, la capa
|
58 |
* tendr? asociada la proyecci?n que se pasa como parametro tambi?n
|
59 |
*
|
60 |
* @param layerName DOCUMENT ME!
|
61 |
* @param driverName
|
62 |
* @param f DOCUMENT ME!
|
63 |
* @param proj DOCUMENT ME!
|
64 |
*
|
65 |
* @return DOCUMENT ME!
|
66 |
*
|
67 |
* @throws DriverException
|
68 |
*/
|
69 |
public static FLayer createLayer(String layerName, String driverName, |
70 |
File f, IProjection proj) throws DriverException { |
71 |
//Se obtiene el driver que lee
|
72 |
DriverManager dm = getDM();
|
73 |
|
74 |
try {
|
75 |
Driver d = dm.getDriver(driverName);
|
76 |
|
77 |
if (d instanceof VectorialFileDriver) { |
78 |
return createLayer(layerName, (VectorialFileDriver) d, f, proj);
|
79 |
} else if (d instanceof RasterDriver) { |
80 |
return createLayer(layerName, (RasterDriver) d, f, proj);
|
81 |
} |
82 |
} catch (DriverLoadException e) {
|
83 |
throw new DriverException(e); |
84 |
} |
85 |
|
86 |
return null; |
87 |
} |
88 |
|
89 |
/**
|
90 |
* Crea un RandomVectorialFile con el driver que se le pasa como par?metro
|
91 |
* y guard?ndose el nombre del fichero para realizar los accesos, la capa
|
92 |
* tendr? asociada la proyecci?n que se pasa como parametro tambi?n
|
93 |
*
|
94 |
* @param d
|
95 |
* @param f DOCUMENT ME!
|
96 |
* @param proj DOCUMENT ME!
|
97 |
*
|
98 |
* @return DOCUMENT ME!
|
99 |
*
|
100 |
* @throws DriverLoadException
|
101 |
* @throws DriverIOException
|
102 |
* @throws DriverException
|
103 |
*/
|
104 |
public static FLayer createLayer(String layerName, VectorialFileDriver d, File f, |
105 |
IProjection proj) throws DriverException {
|
106 |
//TODO Comprobar si hay un adaptador ya
|
107 |
VectorialFileAdapter adapter = new VectorialFileAdapter(f);
|
108 |
adapter.setDriver((VectorialDriver) d); |
109 |
|
110 |
FLyrVect capa = new FLyrVect();
|
111 |
capa.setName(layerName); |
112 |
|
113 |
//TODO Meter esto dentro de la comprobaci?n de si hay memoria
|
114 |
if (false) { |
115 |
} else {
|
116 |
capa.setSource(adapter); |
117 |
capa.setProjection(proj); |
118 |
} |
119 |
|
120 |
try {
|
121 |
// Le asignamos tambi?n una legenda por defecto acorde con
|
122 |
// el tipo de shape que tenga. Tampoco s? si es aqu? el
|
123 |
// sitio adecuado, pero en fin....
|
124 |
if (d instanceof WithDefaultLegend) |
125 |
{ |
126 |
WithDefaultLegend aux = (WithDefaultLegend) d; |
127 |
adapter.start(); |
128 |
capa.setLegend((VectorialLegend) aux.getDefaultLegend()); |
129 |
adapter.stop(); |
130 |
} |
131 |
else
|
132 |
capa.setLegend(LegendFactory.createSingleSymbolLegend(capa.getShapeType())); |
133 |
} catch (FieldNotFoundException e) {
|
134 |
//Esta no puede saltar
|
135 |
} catch (DriverIOException e) {
|
136 |
throw new DriverException(e); |
137 |
} |
138 |
|
139 |
return capa;
|
140 |
} |
141 |
|
142 |
public static FLayer createLayer(String layerName, Rectangle2D rect, |
143 |
URL host, String format, String query, String infoQuery, String srs){ |
144 |
|
145 |
FLyrWMS layer = new FLyrWMS();
|
146 |
layer.setHost(host); |
147 |
layer.setFullExtent(rect); |
148 |
layer.setFormat(format); |
149 |
layer.setLayerQuery(query); |
150 |
layer.setInfoLayerQuery(infoQuery); |
151 |
layer.setSRS(srs); |
152 |
layer.setName(layerName); |
153 |
|
154 |
return layer;
|
155 |
} |
156 |
|
157 |
/**
|
158 |
* DOCUMENT ME!
|
159 |
*
|
160 |
* @param layerName DOCUMENT ME!
|
161 |
* @param d DOCUMENT ME!
|
162 |
* @param f DOCUMENT ME!
|
163 |
* @param proj DOCUMENT ME!
|
164 |
*
|
165 |
* @return DOCUMENT ME!
|
166 |
*/
|
167 |
public static FLyrRaster createLayer(String layerName, RasterDriver d, |
168 |
File f, IProjection proj) {
|
169 |
RasterAdapter adapter = new RasterFileAdapter(f);
|
170 |
adapter.setDriver(d); |
171 |
|
172 |
FLyrRaster capa = new FLyrRaster();
|
173 |
capa.setName(layerName); |
174 |
|
175 |
//TODO Meter esto dentro de la comprobaci?n de si hay memoria
|
176 |
if (false) { |
177 |
} else {
|
178 |
capa.setSource(adapter); |
179 |
capa.setProjection(proj); |
180 |
capa.load(); |
181 |
} |
182 |
|
183 |
return capa;
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* Crea un RandomVectorialWFS con el driver que se le pasa como par?metro y
|
188 |
* guard?ndose la URL del servidor que se pasa como par?metro
|
189 |
*
|
190 |
* @param driver DOCUMENT ME!
|
191 |
* @param host DOCUMENT ME!
|
192 |
* @param proj DOCUMENT ME!
|
193 |
*
|
194 |
* @return DOCUMENT ME!
|
195 |
*
|
196 |
* @throws UnsupportedOperationException DOCUMENT ME!
|
197 |
*/
|
198 |
public static FLayer createLayer(WFSDriver driver, URL host, |
199 |
IProjection proj) { |
200 |
throw new UnsupportedOperationException(); |
201 |
} |
202 |
|
203 |
/**
|
204 |
* Crea un RandomVectorialWFS con el driver que se le pasa como par?metro y
|
205 |
* guard?ndose la URL del servidor que se pasa como par?metro
|
206 |
*
|
207 |
* @param driver DOCUMENT ME!
|
208 |
* @param host DOCUMENT ME!
|
209 |
* @param port DOCUMENT ME!
|
210 |
* @param user DOCUMENT ME!
|
211 |
* @param password DOCUMENT ME!
|
212 |
* @param dbName DOCUMENT ME!
|
213 |
* @param tableName DOCUMENT ME!
|
214 |
* @param proj DOCUMENT ME!
|
215 |
*
|
216 |
* @return DOCUMENT ME!
|
217 |
*
|
218 |
* @throws UnsupportedOperationException DOCUMENT ME!
|
219 |
*/
|
220 |
public static FLayer createLayer(VectorialDatabaseDriver driver, |
221 |
String host, int port, String user, String password, String dbName, |
222 |
String tableName, IProjection proj) {
|
223 |
throw new UnsupportedOperationException(); |
224 |
} |
225 |
|
226 |
/**
|
227 |
* Obtiene el adaptador de un driver si ya se ha a?adido el origen de datos
|
228 |
* o null si es un origen de datos nuevo
|
229 |
*
|
230 |
* @param source DOCUMENT ME!
|
231 |
*/
|
232 |
private static void getAdapter(Source source) { |
233 |
} |
234 |
|
235 |
/**
|
236 |
* Registra la asociaci?n entre la fuente de datos que se pasa como
|
237 |
* par?metro y el VectorialAdapter que se pasa como par?metro, para
|
238 |
* satisfacer futuras llamadas a getAdapter
|
239 |
*
|
240 |
* @param s DOCUMENT ME!
|
241 |
* @param a DOCUMENT ME!
|
242 |
*/
|
243 |
private static void saveSourceAdapter(Source s, VectorialAdapter a) { |
244 |
} |
245 |
|
246 |
/**
|
247 |
* Crea una FLyrComplexRaster que ataca al driver que se pasa como
|
248 |
* par?metro.
|
249 |
*
|
250 |
* @param driver DOCUMENT ME!
|
251 |
* @param f DOCUMENT ME!
|
252 |
* @param proj DOCUMENT ME!
|
253 |
*
|
254 |
* @throws IllegalArgumentException Si se pasa un driver que no implementa
|
255 |
* GeorreferencedRasterDriver o NotGeorreferencedRasterDriver
|
256 |
*/
|
257 |
public static void createLayer(RasterDriver driver, File f, IProjection proj) |
258 |
throws IllegalArgumentException { |
259 |
} |
260 |
|
261 |
/**
|
262 |
* DOCUMENT ME!
|
263 |
*
|
264 |
* @return DOCUMENT ME!
|
265 |
*/
|
266 |
public static DriverManager getDM() { |
267 |
if (driverManager == null) { |
268 |
initializeDriverManager(); |
269 |
} |
270 |
|
271 |
return driverManager;
|
272 |
} |
273 |
|
274 |
/**
|
275 |
* DOCUMENT ME!
|
276 |
*/
|
277 |
private static void initializeDriverManager() { |
278 |
if (driverManager == null) { |
279 |
driverManager = new DriverManager(); |
280 |
driverManager.loadDrivers(new File(LayerFactory.driversPath)); |
281 |
|
282 |
Throwable[] failures = driverManager.getLoadFailures(); |
283 |
|
284 |
for (int i = 0; i < failures.length; i++) { |
285 |
logger.error(failures[i]); |
286 |
} |
287 |
|
288 |
DataSourceFactory.setDriverManager(driverManager); |
289 |
} |
290 |
} |
291 |
|
292 |
/**
|
293 |
* sets drivers Directory
|
294 |
*
|
295 |
* @param path
|
296 |
*/
|
297 |
public static void setDriversPath(String path) { |
298 |
LayerFactory.driversPath = path; |
299 |
initializeDriverManager(); |
300 |
} |
301 |
} |