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