Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / InitializeApplicationExtension.java @ 29956

History | View | Annotate | Download (11.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.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.tools.ToolsLibrary;
40
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluator;
41
import org.gvsig.tools.evaluator.sqljep.SQLJEPLibrary;
42
import org.gvsig.tools.observer.Observer;
43
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
45

    
46

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

    
52

    
53
        private AppGvSigLibrary appGvSigLibrary;
54

    
55
        private DALFileLibrary dalFileLibrary;
56

    
57
        private DXFLibrary dxf;
58

    
59
        private DXFLegendLibrary dxfLegend;
60

    
61
        private DGNLibrary dgn;
62

    
63
        private DGNLegendLibrary dgnLegend;
64

    
65
        private DBFLibrary dbf;
66

    
67
        private SHPLibrary shp;
68

    
69
        private MapContextLibrary mapContextLibrary;
70
        private MapContextGeomOperationsLibrary mapContextGeomOperationLibrary;
71

    
72

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

    
85

    
86

    
87
        public void initialize() {
88

    
89
                // Basic libraries
90
                toolLibrary = new ToolsLibrary();
91
                toolLibrary.initialize();
92

    
93
                // Register persistence manager
94
                // FIXME
95
                // ToolsLocator.registerDefaultPersistenceManager(XMLEntityManager.class);
96

    
97
                projectionLibrary = new ProjectionLibrary();
98
                projectionLibrary.initialize();
99

    
100
                cresquesCtsLibrary = new CresquesCtsLibrary();
101
                cresquesCtsLibrary.initialize();
102

    
103
                // geometry api
104
                geometryLibrary = new GeometryLibrary();
105
                geometryLibrary.initialize();
106

    
107
                // geometry implementation
108
                defaultGeometryLibrary = new DefaultGeometryLibrary();
109
                defaultGeometryLibrary.initialize();
110

    
111
                // Data Access Library
112
                dalLibrary = new DALLibrary();
113
                dalLibrary.initialize();
114

    
115
                // SQLJEP expression parser for DAL
116
                sQLJEPLibrary = new SQLJEPLibrary();
117
                sQLJEPLibrary.initialize();
118

    
119

    
120
                // Register default expression parser
121
                DALLocator.getDataManager().registerDefaultEvaluator(
122
                                SQLJEPEvaluator.class);
123

    
124
                // DAL file store support library
125
                dalFileLibrary = new DALFileLibrary();
126
                dalFileLibrary.initialize();
127

    
128
                // DAL DXF provider
129
                dxf = new DXFLibrary();
130
                dxf.initialize();
131
                dxfLegend = new DXFLegendLibrary();
132
                dxfLegend.initialize();
133

    
134
                // DAL DGN provider
135
                dgn = new DGNLibrary();
136
                dgn.initialize();
137
                dgnLegend = new DGNLegendLibrary();
138
                dgnLegend.initialize();
139

    
140
                // DAL DBF provider
141
                dbf = new DBFLibrary();
142
                dbf.initialize();
143

    
144
                // DAL SHP provider
145
                shp = new SHPLibrary();
146
                shp.initialize();
147

    
148

    
149
                // DAL geom Index JTS provider
150
                jtsIndex = new JTSIndexLibrary();
151
                jtsIndex.initialize();
152

    
153
                // DAL geom Index JSI provider
154
                jsiIndex = new JSIIndexLibrary();
155
                jsiIndex.initialize();
156

    
157
                // DAL geom Index GT2 provider
158
                gt2Index = new Gt2IndexLibrary();
159
                gt2Index.initialize();
160

    
161
                // MapContext library
162
                mapContextLibrary = new MapContextLibrary();
163
                mapContextLibrary.initialize();
164

    
165
                // MapContext Geomerty operations library
166
                mapContextGeomOperationLibrary = new MapContextGeomOperationsLibrary();
167
                mapContextGeomOperationLibrary.initialize();
168

    
169
                // appGvSIG library
170
                appGvSigLibrary = new AppGvSigLibrary();
171
                appGvSigLibrary.initialize();
172

    
173
                // libCompat library
174
                // Register default expression parser
175
                compatLibrary = new CompatLibrary();
176
                compatLibrary.initialize();
177
                SECompatLibrary compatLibraryImpl=new SECompatLibrary();
178
                compatLibraryImpl.initialize();
179

    
180
                AppGvSigLocator.getAppGvSigManager().registerAddTableWizard("File",
181
                                "File Table", FilesystemExplorerTableWizardPanel.class);
182
                addToLogInfo();
183
                registerIcons();
184

    
185
        }
186
        public void postInitialize(){
187

    
188
                toolLibrary.postInitialize();
189

    
190
                projectionLibrary.postInitialize();
191
                cresquesCtsLibrary.postInitialize();
192

    
193
                geometryLibrary.postInitialize();
194
                defaultGeometryLibrary.postInitialize();
195

    
196
                dalLibrary.postInitialize();
197

    
198
                sQLJEPLibrary.postInitialize();
199

    
200
                dalFileLibrary.postInitialize();
201

    
202
                dxf.postInitialize();
203
                dxfLegend.postInitialize();
204

    
205
                dgn.postInitialize();
206
                dgnLegend.postInitialize();
207

    
208
                dbf.postInitialize();
209
                shp.postInitialize();
210

    
211
                jtsIndex.postInitialize();
212
                jsiIndex.postInitialize();
213
                gt2Index.postInitialize();
214

    
215
                mapContextLibrary.postInitialize();
216
                mapContextGeomOperationLibrary.postInitialize();
217

    
218
                appGvSigLibrary.postInitialize();
219

    
220
                compatLibrary.postInitialize();
221

    
222
                registerObservers();
223

    
224
                DALLocator.getResourceManager().startResourceCollector(
225
                                3 * (60 * 1000), // minutes --> miliseconds
226
                                null);
227

    
228
        }
229
        private void registerObservers() {
230
//                FIXME
231
//                ResourceManager resMan = DALLocator.getResourceManager();//.getResource(PostgresqlStore.DATASTORE_NAME);
232
//                dbPasswordResorceObserver = new DBResourceManager();
233
//                resMan.addObserver(dbPasswordResorceObserver);
234
        }
235

    
236
        //Registro en esta extension los iconos que no se donde registrarlos.
237
        private void registerIcons(){
238

    
239
                PluginServices.getIconTheme().registerDefault(
240
                                "view-add-event-layer",
241
                                this.getClass().getClassLoader().getResource("images/addeventtheme.png")
242
                        );
243
                PluginServices.getIconTheme().registerDefault(
244
                                "gvsig-logo-icon",
245
                                this.getClass().getClassLoader().getResource("images/icon_gvsig.png")
246
                        );
247

    
248

    
249

    
250
                PluginServices.getIconTheme().registerDefault(
251
                                "mapa-icono",
252
                                this.getClass().getClassLoader().getResource("images/mapas.png")
253
                        );
254

    
255
                PluginServices.getIconTheme().registerDefault(
256
                                "layout-insert-view",
257
                                this.getClass().getClassLoader().getResource("images/MapaVista.png")
258
                        );
259

    
260
                PluginServices.getIconTheme().registerDefault(
261
                                "vista-icono",
262
                                this.getClass().getClassLoader().getResource("images/Vista.png")
263
                        );
264

    
265
                PluginServices.getIconTheme().registerDefault(
266
                                "hand-icono",
267
                                this.getClass().getClassLoader().getResource("images/Hand.png")
268
                        );
269

    
270
                PluginServices.getIconTheme().registerDefault(
271
                                "add-layer-icono",
272
                                this.getClass().getClassLoader().getResource("images/add-layer.png")
273
                        );
274

    
275
                PluginServices.getIconTheme().registerDefault(
276
                                "delete-icono",
277
                                this.getClass().getClassLoader().getResource("images/delete.png")
278
                        );
279

    
280
                PluginServices.getIconTheme().registerDefault(
281
                                "arrow-up-icono",
282
                                this.getClass().getClassLoader().getResource("images/up-arrow.png")
283
                        );
284

    
285
                PluginServices.getIconTheme().registerDefault(
286
                                "arrow-down-icono",
287
                                this.getClass().getClassLoader().getResource("images/down-arrow.png")
288
                        );
289
//                PluginServices.getIconTheme().register(
290
//                                "arrow-down-icono",
291
//                                PrintPropertiesPage.class.getClassLoader().getResource("images/prepare-page.png")
292
//                        );
293
        }
294

    
295
        public void execute(String actionCommand) {
296

    
297
        }
298

    
299
        public boolean isEnabled() {
300
                return false;
301
        }
302

    
303
        public boolean isVisible() {
304
                return false;
305
        }
306

    
307
        private void addToLogInfo() {
308
                String info[] = this.getStringInfo().split("\n");
309
                for (int i=0;i< info.length;i++) {
310
                        logger.info(info[i]);
311
                }
312
        }
313

    
314
        public String getStringInfo() {
315
                StringWriter writer = new StringWriter();
316
                String andamiPath;
317
                String extensionsPath;
318
                //                String jaiVersion;
319

    
320
                Properties props = System.getProperties();
321

    
322
                try {
323
                        try {
324
                                andamiPath = (new File(Launcher.class.getResource(".").getFile() + File.separator + ".." + File.separator + ".." + File.separator +"..")).getCanonicalPath();
325
                        } catch (IOException e) {
326
                                andamiPath = (new File(Launcher.class.getResource(".").getFile() + File.separator + ".." + File.separator + ".." + File.separator +"..")).getAbsolutePath();
327
                        }
328
                } catch (Exception e1) {
329
                        andamiPath = (String)props.get("user.dir");
330
                }
331
                try {
332
                        try {
333
                                extensionsPath = (new File(Launcher.getAndamiConfig().getPluginsDirectory())).getCanonicalPath();
334
                        } catch (IOException e) {
335
                                extensionsPath = (new File(Launcher.getAndamiConfig().getPluginsDirectory())).getAbsolutePath();
336
                        }
337
                } catch (Exception e1) {
338
                        extensionsPath = "???";
339
                }
340

    
341

    
342

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

    
365
                        }
366
                }
367
                writer.write("JAVA vendor: " + props.get("java.vendor") + "\n");
368
                writer.write("    version:" +props.get("java.version")+ "\n");
369
                writer.write("    home: " + props.get("java.home") + "\n");
370
                return writer.toString();
371
        }
372

    
373
        public void terminate() {
374
                // XXX: Need a TerminateApplicationExtension ???
375
                ResourceManager resMan = DALLocator.getResourceManager();
376
                resMan.stopResourceCollector();
377
                try {
378
                        resMan.dispose();
379
                } catch (DisposeResorceManagerException e) {
380
                        logger.error("Exceptions at dispose Resource Manager", e);
381
                }
382

    
383
                super.terminate();
384
//                try {
385
//                        LayerFactory.getDataSourceFactory().finalizeThis();
386
//                } catch (Exception e) {
387
//                        //e.printStackTrace();
388
//                }
389

    
390
        }
391
}