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