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