svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / InitializeApplicationExtension.java @ 30118
History | View | Annotate | Download (12.1 KB)
1 |
package org.gvsig.app.extension; |
---|---|
2 |
|
3 |
import java.io.BufferedReader; |
4 |
import java.io.File; |
5 |
import java.io.IOException; |
6 |
import java.io.InputStream; |
7 |
import java.io.InputStreamReader; |
8 |
import java.io.StringWriter; |
9 |
import java.util.Properties; |
10 |
|
11 |
import org.cresques.ProjectionLibrary; |
12 |
import org.cresques.impl.CresquesCtsLibrary; |
13 |
import org.gvsig.andami.Launcher; |
14 |
import org.gvsig.andami.PluginServices; |
15 |
import org.gvsig.andami.plugins.Extension; |
16 |
import org.gvsig.app.AppGvSigLibrary; |
17 |
import org.gvsig.app.AppGvSigLocator; |
18 |
import org.gvsig.compat.CompatLibrary; |
19 |
import org.gvsig.compat.se.SECompatLibrary; |
20 |
import org.gvsig.fmap.dal.DALFileLibrary; |
21 |
import org.gvsig.fmap.dal.DALLibrary; |
22 |
import org.gvsig.fmap.dal.DALLocator; |
23 |
import org.gvsig.fmap.dal.impl.DALDefaultImplLibrary; |
24 |
import org.gvsig.fmap.dal.index.spatial.gt2.Gt2IndexLibrary; |
25 |
import org.gvsig.fmap.dal.index.spatial.jsi.JSIIndexLibrary; |
26 |
import org.gvsig.fmap.dal.index.spatial.jts.JTSIndexLibrary; |
27 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
28 |
import org.gvsig.fmap.dal.resource.exception.DisposeResorceManagerException; |
29 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerTableWizardPanel; |
30 |
import org.gvsig.fmap.dal.store.dbf.DBFLibrary; |
31 |
import org.gvsig.fmap.dal.store.dgn.DGNLibrary; |
32 |
import org.gvsig.fmap.dal.store.dgn.legend.DGNLegendLibrary; |
33 |
import org.gvsig.fmap.dal.store.dxf.DXFLibrary; |
34 |
import org.gvsig.fmap.dal.store.dxf.legend.DXFLegendLibrary; |
35 |
import org.gvsig.fmap.dal.store.shp.SHPLibrary; |
36 |
import org.gvsig.fmap.geom.GeometryLibrary; |
37 |
import org.gvsig.fmap.geom.impl.DefaultGeometryLibrary; |
38 |
import org.gvsig.fmap.geom.operation.MapContextGeomOperationsLibrary; |
39 |
import org.gvsig.fmap.mapcontext.MapContextLibrary; |
40 |
import org.gvsig.fmap.mapcontext.impl.MapContextImplLibrary; |
41 |
import org.gvsig.symbology.SimbologyLibrary; |
42 |
import org.gvsig.symbology.impl.SimbologyDefaultImplLibrary; |
43 |
import org.gvsig.tools.ToolsLibrary; |
44 |
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluator; |
45 |
import org.gvsig.tools.evaluator.sqljep.SQLJEPLibrary; |
46 |
import org.gvsig.tools.observer.Observer; |
47 |
import org.slf4j.Logger; |
48 |
import org.slf4j.LoggerFactory; |
49 |
|
50 |
|
51 |
public class InitializeApplicationExtension extends Extension { |
52 |
private static final Logger logger = LoggerFactory |
53 |
.getLogger(InitializeApplicationExtension.class); |
54 |
private Observer dbPasswordResorceObserver; |
55 |
|
56 |
|
57 |
private AppGvSigLibrary appGvSigLibrary;
|
58 |
|
59 |
private DALFileLibrary dalFileLibrary;
|
60 |
|
61 |
private DXFLibrary dxf;
|
62 |
|
63 |
private DXFLegendLibrary dxfLegend;
|
64 |
|
65 |
private DGNLibrary dgn;
|
66 |
|
67 |
private DGNLegendLibrary dgnLegend;
|
68 |
|
69 |
private DBFLibrary dbf;
|
70 |
|
71 |
private SHPLibrary shp;
|
72 |
|
73 |
private MapContextLibrary mapContextLibrary;
|
74 |
private MapContextImplLibrary mapContextImplLibrary;
|
75 |
|
76 |
private MapContextGeomOperationsLibrary mapContextGeomOperationLibrary;
|
77 |
|
78 |
private SimbologyLibrary simbologyLibrary;
|
79 |
|
80 |
private SimbologyDefaultImplLibrary simbologyDefaultImplLibrary;
|
81 |
|
82 |
private JTSIndexLibrary jtsIndex;
|
83 |
private JSIIndexLibrary jsiIndex;
|
84 |
private Gt2IndexLibrary gt2Index;
|
85 |
private ToolsLibrary toolLibrary;
|
86 |
private DALLibrary dalLibrary;
|
87 |
private GeometryLibrary geometryLibrary;
|
88 |
private SQLJEPLibrary sQLJEPLibrary;
|
89 |
private DefaultGeometryLibrary defaultGeometryLibrary;
|
90 |
private CompatLibrary compatLibrary;
|
91 |
private ProjectionLibrary projectionLibrary;
|
92 |
private CresquesCtsLibrary cresquesCtsLibrary;
|
93 |
private DALDefaultImplLibrary dalDefaultImplLibrary;
|
94 |
|
95 |
|
96 |
|
97 |
public void initialize() { |
98 |
|
99 |
// Basic libraries
|
100 |
toolLibrary = new ToolsLibrary();
|
101 |
toolLibrary.initialize(); |
102 |
|
103 |
// Register persistence manager
|
104 |
// FIXME
|
105 |
// ToolsLocator.registerDefaultPersistenceManager(XMLEntityManager.class);
|
106 |
|
107 |
projectionLibrary = new ProjectionLibrary();
|
108 |
projectionLibrary.initialize(); |
109 |
|
110 |
cresquesCtsLibrary = new CresquesCtsLibrary();
|
111 |
cresquesCtsLibrary.initialize(); |
112 |
|
113 |
// geometry api
|
114 |
geometryLibrary = new GeometryLibrary();
|
115 |
geometryLibrary.initialize(); |
116 |
|
117 |
// geometry implementation
|
118 |
defaultGeometryLibrary = new DefaultGeometryLibrary();
|
119 |
defaultGeometryLibrary.initialize(); |
120 |
|
121 |
// Data Access Library
|
122 |
dalLibrary = new DALLibrary();
|
123 |
dalLibrary.initialize(); |
124 |
|
125 |
// Default Implementation of Data Access Library
|
126 |
dalDefaultImplLibrary = new DALDefaultImplLibrary();
|
127 |
dalDefaultImplLibrary.initialize(); |
128 |
|
129 |
|
130 |
// SQLJEP expression parser for DAL
|
131 |
sQLJEPLibrary = new SQLJEPLibrary();
|
132 |
sQLJEPLibrary.initialize(); |
133 |
|
134 |
|
135 |
// Register default expression parser
|
136 |
DALLocator.getDataManager().registerDefaultEvaluator( |
137 |
SQLJEPEvaluator.class); |
138 |
|
139 |
// DAL file store support library
|
140 |
dalFileLibrary = new DALFileLibrary();
|
141 |
dalFileLibrary.initialize(); |
142 |
|
143 |
// DAL DXF provider
|
144 |
dxf = new DXFLibrary();
|
145 |
dxf.initialize(); |
146 |
dxfLegend = new DXFLegendLibrary();
|
147 |
dxfLegend.initialize(); |
148 |
|
149 |
// DAL DGN provider
|
150 |
dgn = new DGNLibrary();
|
151 |
dgn.initialize(); |
152 |
dgnLegend = new DGNLegendLibrary();
|
153 |
dgnLegend.initialize(); |
154 |
|
155 |
// DAL DBF provider
|
156 |
dbf = new DBFLibrary();
|
157 |
dbf.initialize(); |
158 |
|
159 |
// DAL SHP provider
|
160 |
shp = new SHPLibrary();
|
161 |
shp.initialize(); |
162 |
|
163 |
|
164 |
// DAL geom Index JTS provider
|
165 |
jtsIndex = new JTSIndexLibrary();
|
166 |
jtsIndex.initialize(); |
167 |
|
168 |
// DAL geom Index JSI provider
|
169 |
jsiIndex = new JSIIndexLibrary();
|
170 |
jsiIndex.initialize(); |
171 |
|
172 |
// DAL geom Index GT2 provider
|
173 |
gt2Index = new Gt2IndexLibrary();
|
174 |
gt2Index.initialize(); |
175 |
|
176 |
// MapContext library
|
177 |
mapContextLibrary = new MapContextLibrary();
|
178 |
mapContextLibrary.initialize(); |
179 |
|
180 |
mapContextImplLibrary = new MapContextImplLibrary();
|
181 |
mapContextImplLibrary.initialize(); |
182 |
|
183 |
// Simbology
|
184 |
simbologyLibrary = new SimbologyLibrary();
|
185 |
simbologyLibrary.initialize(); |
186 |
|
187 |
simbologyDefaultImplLibrary = new SimbologyDefaultImplLibrary();
|
188 |
simbologyDefaultImplLibrary.initialize(); |
189 |
|
190 |
// MapContext Geomerty operations library
|
191 |
mapContextGeomOperationLibrary = new MapContextGeomOperationsLibrary();
|
192 |
mapContextGeomOperationLibrary.initialize(); |
193 |
|
194 |
// appGvSIG library
|
195 |
appGvSigLibrary = new AppGvSigLibrary();
|
196 |
appGvSigLibrary.initialize(); |
197 |
|
198 |
// libCompat library
|
199 |
// Register default expression parser
|
200 |
compatLibrary = new CompatLibrary();
|
201 |
compatLibrary.initialize(); |
202 |
SECompatLibrary compatLibraryImpl=new SECompatLibrary();
|
203 |
compatLibraryImpl.initialize(); |
204 |
|
205 |
AppGvSigLocator.getAppGvSigManager().registerAddTableWizard("File",
|
206 |
"File Table", FilesystemExplorerTableWizardPanel.class);
|
207 |
addToLogInfo(); |
208 |
registerIcons(); |
209 |
|
210 |
} |
211 |
public void postInitialize(){ |
212 |
|
213 |
toolLibrary.postInitialize(); |
214 |
|
215 |
projectionLibrary.postInitialize(); |
216 |
cresquesCtsLibrary.postInitialize(); |
217 |
|
218 |
geometryLibrary.postInitialize(); |
219 |
defaultGeometryLibrary.postInitialize(); |
220 |
|
221 |
dalLibrary.postInitialize(); |
222 |
dalDefaultImplLibrary.postInitialize(); |
223 |
|
224 |
sQLJEPLibrary.postInitialize(); |
225 |
|
226 |
dalFileLibrary.postInitialize(); |
227 |
|
228 |
dxf.postInitialize(); |
229 |
dxfLegend.postInitialize(); |
230 |
|
231 |
dgn.postInitialize(); |
232 |
dgnLegend.postInitialize(); |
233 |
|
234 |
dbf.postInitialize(); |
235 |
shp.postInitialize(); |
236 |
|
237 |
jtsIndex.postInitialize(); |
238 |
jsiIndex.postInitialize(); |
239 |
gt2Index.postInitialize(); |
240 |
|
241 |
mapContextLibrary.postInitialize(); |
242 |
mapContextImplLibrary.postInitialize(); |
243 |
mapContextGeomOperationLibrary.postInitialize(); |
244 |
|
245 |
simbologyLibrary.postInitialize(); |
246 |
simbologyDefaultImplLibrary.postInitialize(); |
247 |
|
248 |
appGvSigLibrary.postInitialize(); |
249 |
|
250 |
compatLibrary.postInitialize(); |
251 |
|
252 |
registerObservers(); |
253 |
|
254 |
DALLocator.getResourceManager().startResourceCollector( |
255 |
3 * (60 * 1000), // minutes --> miliseconds |
256 |
null);
|
257 |
|
258 |
} |
259 |
private void registerObservers() { |
260 |
// FIXME
|
261 |
// ResourceManager resMan = DALLocator.getResourceManager();//.getResource(PostgresqlStore.DATASTORE_NAME);
|
262 |
// dbPasswordResorceObserver = new DBResourceManager();
|
263 |
// resMan.addObserver(dbPasswordResorceObserver);
|
264 |
} |
265 |
|
266 |
//Registro en esta extension los iconos que no se donde registrarlos.
|
267 |
private void registerIcons(){ |
268 |
|
269 |
PluginServices.getIconTheme().registerDefault( |
270 |
"view-add-event-layer",
|
271 |
this.getClass().getClassLoader().getResource("images/addeventtheme.png") |
272 |
); |
273 |
PluginServices.getIconTheme().registerDefault( |
274 |
"gvsig-logo-icon",
|
275 |
this.getClass().getClassLoader().getResource("images/icon_gvsig.png") |
276 |
); |
277 |
|
278 |
|
279 |
|
280 |
PluginServices.getIconTheme().registerDefault( |
281 |
"mapa-icono",
|
282 |
this.getClass().getClassLoader().getResource("images/mapas.png") |
283 |
); |
284 |
|
285 |
PluginServices.getIconTheme().registerDefault( |
286 |
"layout-insert-view",
|
287 |
this.getClass().getClassLoader().getResource("images/MapaVista.png") |
288 |
); |
289 |
|
290 |
PluginServices.getIconTheme().registerDefault( |
291 |
"vista-icono",
|
292 |
this.getClass().getClassLoader().getResource("images/Vista.png") |
293 |
); |
294 |
|
295 |
PluginServices.getIconTheme().registerDefault( |
296 |
"hand-icono",
|
297 |
this.getClass().getClassLoader().getResource("images/Hand.png") |
298 |
); |
299 |
|
300 |
PluginServices.getIconTheme().registerDefault( |
301 |
"add-layer-icono",
|
302 |
this.getClass().getClassLoader().getResource("images/add-layer.png") |
303 |
); |
304 |
|
305 |
PluginServices.getIconTheme().registerDefault( |
306 |
"delete-icono",
|
307 |
this.getClass().getClassLoader().getResource("images/delete.png") |
308 |
); |
309 |
|
310 |
PluginServices.getIconTheme().registerDefault( |
311 |
"arrow-up-icono",
|
312 |
this.getClass().getClassLoader().getResource("images/up-arrow.png") |
313 |
); |
314 |
|
315 |
PluginServices.getIconTheme().registerDefault( |
316 |
"arrow-down-icono",
|
317 |
this.getClass().getClassLoader().getResource("images/down-arrow.png") |
318 |
); |
319 |
// PluginServices.getIconTheme().register(
|
320 |
// "arrow-down-icono",
|
321 |
// PrintPropertiesPage.class.getClassLoader().getResource("images/prepare-page.png")
|
322 |
// );
|
323 |
} |
324 |
|
325 |
public void execute(String actionCommand) { |
326 |
|
327 |
} |
328 |
|
329 |
public boolean isEnabled() { |
330 |
return false; |
331 |
} |
332 |
|
333 |
public boolean isVisible() { |
334 |
return false; |
335 |
} |
336 |
|
337 |
private void addToLogInfo() { |
338 |
String info[] = this.getStringInfo().split("\n"); |
339 |
for (int i=0;i< info.length;i++) { |
340 |
logger.info(info[i]); |
341 |
} |
342 |
} |
343 |
|
344 |
public String getStringInfo() { |
345 |
StringWriter writer = new StringWriter(); |
346 |
String andamiPath;
|
347 |
String extensionsPath;
|
348 |
// String jaiVersion;
|
349 |
|
350 |
Properties props = System.getProperties(); |
351 |
|
352 |
try {
|
353 |
try {
|
354 |
andamiPath = (new File(Launcher.class.getResource(".").getFile() + File.separator + ".." + File.separator + ".." + File.separator +"..")).getCanonicalPath(); |
355 |
} catch (IOException e) { |
356 |
andamiPath = (new File(Launcher.class.getResource(".").getFile() + File.separator + ".." + File.separator + ".." + File.separator +"..")).getAbsolutePath(); |
357 |
} |
358 |
} catch (Exception e1) { |
359 |
andamiPath = (String)props.get("user.dir"); |
360 |
} |
361 |
try {
|
362 |
try {
|
363 |
extensionsPath = (new File(Launcher.getAndamiConfig().getPluginsDirectory())).getCanonicalPath(); |
364 |
} catch (IOException e) { |
365 |
extensionsPath = (new File(Launcher.getAndamiConfig().getPluginsDirectory())).getAbsolutePath(); |
366 |
} |
367 |
} catch (Exception e1) { |
368 |
extensionsPath = "???";
|
369 |
} |
370 |
|
371 |
|
372 |
|
373 |
writer.write("gvSIG version: " + Version.longFormat() + "\n"); |
374 |
writer.write(" gvSIG app exec path: " + andamiPath + "\n"); |
375 |
writer.write(" gvSIG user app home: " + Launcher.getAppHomeDir() + "\n"); |
376 |
writer.write(" gvSIG extension path: " + extensionsPath + "\n"); |
377 |
writer.write(" gvSIG locale language: " + Launcher.getAndamiConfig().getLocaleLanguage() + "\n"); |
378 |
String osName = props.getProperty("os.name"); |
379 |
writer.write("OS name: " + osName + "\n"); |
380 |
writer.write(" arch:" + props.get("os.arch") + "\n"); |
381 |
writer.write(" version:"+ props.get("os.version") + "\n"); |
382 |
if (osName.startsWith("Linux")) { |
383 |
try {
|
384 |
String[] command = {"lsb_release", "-a"}; |
385 |
Process p = Runtime.getRuntime().exec(command); |
386 |
InputStream is = p.getInputStream();
|
387 |
BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
388 |
String line;
|
389 |
while ( (line = reader.readLine()) != null) { |
390 |
writer.write(" "+line+"\n"); |
391 |
} |
392 |
} |
393 |
catch (Exception ex) { |
394 |
|
395 |
} |
396 |
} |
397 |
writer.write("JAVA vendor: " + props.get("java.vendor") + "\n"); |
398 |
writer.write(" version:" +props.get("java.version")+ "\n"); |
399 |
writer.write(" home: " + props.get("java.home") + "\n"); |
400 |
return writer.toString();
|
401 |
} |
402 |
|
403 |
public void terminate() { |
404 |
// XXX: Need a TerminateApplicationExtension ???
|
405 |
ResourceManager resMan = DALLocator.getResourceManager(); |
406 |
resMan.stopResourceCollector(); |
407 |
try {
|
408 |
resMan.dispose(); |
409 |
} catch (DisposeResorceManagerException e) {
|
410 |
logger.error("Exceptions at dispose Resource Manager", e);
|
411 |
} |
412 |
|
413 |
super.terminate();
|
414 |
// try {
|
415 |
// LayerFactory.getDataSourceFactory().finalizeThis();
|
416 |
// } catch (Exception e) {
|
417 |
// //e.printStackTrace();
|
418 |
// }
|
419 |
|
420 |
} |
421 |
} |