Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / InitializeApplicationExtension.java @ 30011

History | View | Annotate | Download (11.3 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.index.spatial.gt2.Gt2IndexLibrary;
24
import org.gvsig.fmap.dal.index.spatial.jsi.JSIIndexLibrary;
25
import org.gvsig.fmap.dal.index.spatial.jts.JTSIndexLibrary;
26
import org.gvsig.fmap.dal.resource.ResourceManager;
27
import org.gvsig.fmap.dal.resource.exception.DisposeResorceManagerException;
28
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerTableWizardPanel;
29
import org.gvsig.fmap.dal.store.dbf.DBFLibrary;
30
import org.gvsig.fmap.dal.store.dgn.DGNLibrary;
31
import org.gvsig.fmap.dal.store.dgn.legend.DGNLegendLibrary;
32
import org.gvsig.fmap.dal.store.dxf.DXFLibrary;
33
import org.gvsig.fmap.dal.store.dxf.legend.DXFLegendLibrary;
34
import org.gvsig.fmap.dal.store.shp.SHPLibrary;
35
import org.gvsig.fmap.geom.GeometryLibrary;
36
import org.gvsig.fmap.geom.impl.DefaultGeometryLibrary;
37
import org.gvsig.fmap.geom.operation.MapContextGeomOperationsLibrary;
38
import org.gvsig.fmap.mapcontext.MapContextLibrary;
39
import org.gvsig.fmap.mapcontext.impl.MapContextImplLibrary;
40
import org.gvsig.tools.ToolsLibrary;
41
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluator;
42
import org.gvsig.tools.evaluator.sqljep.SQLJEPLibrary;
43
import org.gvsig.tools.observer.Observer;
44
import org.slf4j.Logger;
45
import org.slf4j.LoggerFactory;
46

    
47

    
48
public class InitializeApplicationExtension extends Extension {
49
    private static final Logger logger = LoggerFactory
50
            .getLogger(InitializeApplicationExtension.class);
51
        private Observer dbPasswordResorceObserver;
52

    
53

    
54
        private AppGvSigLibrary appGvSigLibrary;
55

    
56
        private DALFileLibrary dalFileLibrary;
57

    
58
        private DXFLibrary dxf;
59

    
60
        private DXFLegendLibrary dxfLegend;
61

    
62
        private DGNLibrary dgn;
63

    
64
        private DGNLegendLibrary dgnLegend;
65

    
66
        private DBFLibrary dbf;
67

    
68
        private SHPLibrary shp;
69

    
70
        private MapContextLibrary mapContextLibrary;
71
        private MapContextImplLibrary mapContextImplLibrary;
72
        
73
        private MapContextGeomOperationsLibrary mapContextGeomOperationLibrary;
74

    
75

    
76
        private JTSIndexLibrary jtsIndex;
77
        private JSIIndexLibrary jsiIndex;
78
        private Gt2IndexLibrary gt2Index;
79
        private ToolsLibrary toolLibrary;
80
        private DALLibrary dalLibrary;
81
        private GeometryLibrary geometryLibrary;
82
        private SQLJEPLibrary sQLJEPLibrary;
83
        private DefaultGeometryLibrary defaultGeometryLibrary;
84
        private CompatLibrary compatLibrary;
85
        private ProjectionLibrary projectionLibrary;
86
        private CresquesCtsLibrary cresquesCtsLibrary;
87

    
88

    
89

    
90
        public void initialize() {
91

    
92
                // Basic libraries
93
                toolLibrary = new ToolsLibrary();
94
                toolLibrary.initialize();
95

    
96
                // Register persistence manager
97
                // FIXME
98
                // ToolsLocator.registerDefaultPersistenceManager(XMLEntityManager.class);
99

    
100
                projectionLibrary = new ProjectionLibrary();
101
                projectionLibrary.initialize();
102

    
103
                cresquesCtsLibrary = new CresquesCtsLibrary();
104
                cresquesCtsLibrary.initialize();
105

    
106
                // geometry api
107
                geometryLibrary = new GeometryLibrary();
108
                geometryLibrary.initialize();
109

    
110
                // geometry implementation
111
                defaultGeometryLibrary = new DefaultGeometryLibrary();
112
                defaultGeometryLibrary.initialize();
113

    
114
                // Data Access Library
115
                dalLibrary = new DALLibrary();
116
                dalLibrary.initialize();
117

    
118
                // SQLJEP expression parser for DAL
119
                sQLJEPLibrary = new SQLJEPLibrary();
120
                sQLJEPLibrary.initialize();
121

    
122

    
123
                // Register default expression parser
124
                DALLocator.getDataManager().registerDefaultEvaluator(
125
                                SQLJEPEvaluator.class);
126

    
127
                // DAL file store support library
128
                dalFileLibrary = new DALFileLibrary();
129
                dalFileLibrary.initialize();
130

    
131
                // DAL DXF provider
132
                dxf = new DXFLibrary();
133
                dxf.initialize();
134
                dxfLegend = new DXFLegendLibrary();
135
                dxfLegend.initialize();
136

    
137
                // DAL DGN provider
138
                dgn = new DGNLibrary();
139
                dgn.initialize();
140
                dgnLegend = new DGNLegendLibrary();
141
                dgnLegend.initialize();
142

    
143
                // DAL DBF provider
144
                dbf = new DBFLibrary();
145
                dbf.initialize();
146

    
147
                // DAL SHP provider
148
                shp = new SHPLibrary();
149
                shp.initialize();
150

    
151

    
152
                // DAL geom Index JTS provider
153
                jtsIndex = new JTSIndexLibrary();
154
                jtsIndex.initialize();
155

    
156
                // DAL geom Index JSI provider
157
                jsiIndex = new JSIIndexLibrary();
158
                jsiIndex.initialize();
159

    
160
                // DAL geom Index GT2 provider
161
                gt2Index = new Gt2IndexLibrary();
162
                gt2Index.initialize();
163

    
164
                // MapContext library
165
                mapContextLibrary = new MapContextLibrary();
166
                mapContextLibrary.initialize();
167
                
168
                mapContextImplLibrary = new MapContextImplLibrary();
169
                mapContextImplLibrary.initialize();
170

    
171
                // MapContext Geomerty operations library
172
                mapContextGeomOperationLibrary = new MapContextGeomOperationsLibrary();
173
                mapContextGeomOperationLibrary.initialize();
174

    
175
                // appGvSIG library
176
                appGvSigLibrary = new AppGvSigLibrary();
177
                appGvSigLibrary.initialize();
178

    
179
                // libCompat library
180
                // Register default expression parser
181
                compatLibrary = new CompatLibrary();
182
                compatLibrary.initialize();
183
                SECompatLibrary compatLibraryImpl=new SECompatLibrary();
184
                compatLibraryImpl.initialize();
185

    
186
                AppGvSigLocator.getAppGvSigManager().registerAddTableWizard("File",
187
                                "File Table", FilesystemExplorerTableWizardPanel.class);
188
                addToLogInfo();
189
                registerIcons();
190

    
191
        }
192
        public void postInitialize(){
193

    
194
                toolLibrary.postInitialize();
195

    
196
                projectionLibrary.postInitialize();
197
                cresquesCtsLibrary.postInitialize();
198

    
199
                geometryLibrary.postInitialize();
200
                defaultGeometryLibrary.postInitialize();
201

    
202
                dalLibrary.postInitialize();
203

    
204
                sQLJEPLibrary.postInitialize();
205

    
206
                dalFileLibrary.postInitialize();
207

    
208
                dxf.postInitialize();
209
                dxfLegend.postInitialize();
210

    
211
                dgn.postInitialize();
212
                dgnLegend.postInitialize();
213

    
214
                dbf.postInitialize();
215
                shp.postInitialize();
216

    
217
                jtsIndex.postInitialize();
218
                jsiIndex.postInitialize();
219
                gt2Index.postInitialize();
220

    
221
                mapContextLibrary.postInitialize();
222
                mapContextImplLibrary.postInitialize();
223
                mapContextGeomOperationLibrary.postInitialize();
224

    
225
                appGvSigLibrary.postInitialize();
226

    
227
                compatLibrary.postInitialize();
228

    
229
                registerObservers();
230

    
231
                DALLocator.getResourceManager().startResourceCollector(
232
                                3 * (60 * 1000), // minutes --> miliseconds
233
                                null);
234

    
235
        }
236
        private void registerObservers() {
237
//                FIXME
238
//                ResourceManager resMan = DALLocator.getResourceManager();//.getResource(PostgresqlStore.DATASTORE_NAME);
239
//                dbPasswordResorceObserver = new DBResourceManager();
240
//                resMan.addObserver(dbPasswordResorceObserver);
241
        }
242

    
243
        //Registro en esta extension los iconos que no se donde registrarlos.
244
        private void registerIcons(){
245

    
246
                PluginServices.getIconTheme().registerDefault(
247
                                "view-add-event-layer",
248
                                this.getClass().getClassLoader().getResource("images/addeventtheme.png")
249
                        );
250
                PluginServices.getIconTheme().registerDefault(
251
                                "gvsig-logo-icon",
252
                                this.getClass().getClassLoader().getResource("images/icon_gvsig.png")
253
                        );
254

    
255

    
256

    
257
                PluginServices.getIconTheme().registerDefault(
258
                                "mapa-icono",
259
                                this.getClass().getClassLoader().getResource("images/mapas.png")
260
                        );
261

    
262
                PluginServices.getIconTheme().registerDefault(
263
                                "layout-insert-view",
264
                                this.getClass().getClassLoader().getResource("images/MapaVista.png")
265
                        );
266

    
267
                PluginServices.getIconTheme().registerDefault(
268
                                "vista-icono",
269
                                this.getClass().getClassLoader().getResource("images/Vista.png")
270
                        );
271

    
272
                PluginServices.getIconTheme().registerDefault(
273
                                "hand-icono",
274
                                this.getClass().getClassLoader().getResource("images/Hand.png")
275
                        );
276

    
277
                PluginServices.getIconTheme().registerDefault(
278
                                "add-layer-icono",
279
                                this.getClass().getClassLoader().getResource("images/add-layer.png")
280
                        );
281

    
282
                PluginServices.getIconTheme().registerDefault(
283
                                "delete-icono",
284
                                this.getClass().getClassLoader().getResource("images/delete.png")
285
                        );
286

    
287
                PluginServices.getIconTheme().registerDefault(
288
                                "arrow-up-icono",
289
                                this.getClass().getClassLoader().getResource("images/up-arrow.png")
290
                        );
291

    
292
                PluginServices.getIconTheme().registerDefault(
293
                                "arrow-down-icono",
294
                                this.getClass().getClassLoader().getResource("images/down-arrow.png")
295
                        );
296
//                PluginServices.getIconTheme().register(
297
//                                "arrow-down-icono",
298
//                                PrintPropertiesPage.class.getClassLoader().getResource("images/prepare-page.png")
299
//                        );
300
        }
301

    
302
        public void execute(String actionCommand) {
303

    
304
        }
305

    
306
        public boolean isEnabled() {
307
                return false;
308
        }
309

    
310
        public boolean isVisible() {
311
                return false;
312
        }
313

    
314
        private void addToLogInfo() {
315
                String info[] = this.getStringInfo().split("\n");
316
                for (int i=0;i< info.length;i++) {
317
                        logger.info(info[i]);
318
                }
319
        }
320

    
321
        public String getStringInfo() {
322
                StringWriter writer = new StringWriter();
323
                String andamiPath;
324
                String extensionsPath;
325
                //                String jaiVersion;
326

    
327
                Properties props = System.getProperties();
328

    
329
                try {
330
                        try {
331
                                andamiPath = (new File(Launcher.class.getResource(".").getFile() + File.separator + ".." + File.separator + ".." + File.separator +"..")).getCanonicalPath();
332
                        } catch (IOException e) {
333
                                andamiPath = (new File(Launcher.class.getResource(".").getFile() + File.separator + ".." + File.separator + ".." + File.separator +"..")).getAbsolutePath();
334
                        }
335
                } catch (Exception e1) {
336
                        andamiPath = (String)props.get("user.dir");
337
                }
338
                try {
339
                        try {
340
                                extensionsPath = (new File(Launcher.getAndamiConfig().getPluginsDirectory())).getCanonicalPath();
341
                        } catch (IOException e) {
342
                                extensionsPath = (new File(Launcher.getAndamiConfig().getPluginsDirectory())).getAbsolutePath();
343
                        }
344
                } catch (Exception e1) {
345
                        extensionsPath = "???";
346
                }
347

    
348

    
349

    
350
                writer.write("gvSIG version: " + Version.longFormat() + "\n");
351
                writer.write("    gvSIG app exec path: " + andamiPath + "\n");
352
                writer.write("    gvSIG user app home: " + Launcher.getAppHomeDir() + "\n");
353
                writer.write("    gvSIG extension path: " + extensionsPath + "\n");
354
                writer.write("    gvSIG locale language: " + Launcher.getAndamiConfig().getLocaleLanguage() + "\n");
355
                String osName = props.getProperty("os.name");
356
                writer.write("OS name: " + osName + "\n");
357
                writer.write("    arch:" + props.get("os.arch") + "\n");
358
                writer.write("    version:"+ props.get("os.version") + "\n");
359
                if (osName.startsWith("Linux")) {
360
                        try {
361
                                String[] command = {"lsb_release", "-a"};
362
                                Process p = Runtime.getRuntime().exec(command);
363
                                InputStream is = p.getInputStream();
364
                                BufferedReader reader = new BufferedReader(new InputStreamReader(is));
365
                                String line;
366
                                while ( (line = reader.readLine()) != null) {
367
                                        writer.write("    "+line+"\n");
368
                                }
369
                        }
370
                        catch (Exception ex) {
371

    
372
                        }
373
                }
374
                writer.write("JAVA vendor: " + props.get("java.vendor") + "\n");
375
                writer.write("    version:" +props.get("java.version")+ "\n");
376
                writer.write("    home: " + props.get("java.home") + "\n");
377
                return writer.toString();
378
        }
379

    
380
        public void terminate() {
381
                // XXX: Need a TerminateApplicationExtension ???
382
                ResourceManager resMan = DALLocator.getResourceManager();
383
                resMan.stopResourceCollector();
384
                try {
385
                        resMan.dispose();
386
                } catch (DisposeResorceManagerException e) {
387
                        logger.error("Exceptions at dispose Resource Manager", e);
388
                }
389

    
390
                super.terminate();
391
//                try {
392
//                        LayerFactory.getDataSourceFactory().finalizeThis();
393
//                } catch (Exception e) {
394
//                        //e.printStackTrace();
395
//                }
396

    
397
        }
398
}