Statistics
| Revision:

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

History | View | Annotate | Download (11.2 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.ToolsLocator;
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.gvsig.tools.persistence.xmlentity.XMLEntityManager;
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

    
48

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

    
54

    
55
        private AppGvSigLibrary appGvSigLibrary;
56

    
57
        private DALFileLibrary dalFileLibrary;
58

    
59
        private DXFLibrary dxf;
60

    
61
        private DXFLegendLibrary dxfLegend;
62

    
63
        private DGNLibrary dgn;
64

    
65
        private DGNLegendLibrary dgnLegend;
66

    
67
        private DBFLibrary dbf;
68

    
69
        private SHPLibrary shp;
70

    
71
        private MapContextLibrary mapContextLibrary;
72
        private MapContextGeomOperationsLibrary mapContextGeomOperationLibrary;
73

    
74

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

    
87

    
88

    
89
        public void initialize() {
90

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

    
95
                // Register persistence manager
96
                ToolsLocator.registerDefaultPersistenceManager(XMLEntityManager.class);
97

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

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

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

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

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

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

    
120

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

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

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

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

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

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

    
149

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

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

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

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

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

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

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

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

    
186
        }
187
        public void postInitialize(){
188

    
189
                toolLibrary.postInitialize();
190

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

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

    
197
                dalLibrary.postInitialize();
198

    
199
                sQLJEPLibrary.postInitialize();
200

    
201
                dalFileLibrary.postInitialize();
202

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

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

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

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

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

    
219
                appGvSigLibrary.postInitialize();
220

    
221
                compatLibrary.postInitialize();
222

    
223
                registerObservers();
224

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

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

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

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

    
249

    
250

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

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

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

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

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

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

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

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

    
296
        public void execute(String actionCommand) {
297

    
298
        }
299

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

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

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

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

    
321
                Properties props = System.getProperties();
322

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

    
342

    
343

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

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

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

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

    
391
        }
392
}