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 |
package com.iver.cit.gvsig; |
---|---|
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.AppGvSigLibrary; |
14 |
import org.gvsig.compat.CompatLibrary; |
15 |
import org.gvsig.compat.se.SECompatLibrary; |
16 |
import org.gvsig.fmap.dal.DALFileLibrary; |
17 |
import org.gvsig.fmap.dal.DALLibrary; |
18 |
import org.gvsig.fmap.dal.DALLocator; |
19 |
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 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
23 |
import org.gvsig.fmap.dal.resource.exception.DisposeResorceManagerException; |
24 |
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 |
import org.gvsig.fmap.geom.GeometryLibrary; |
28 |
import org.gvsig.fmap.geom.impl.DefaultGeometryLibrary; |
29 |
import org.gvsig.fmap.geom.operation.MapContextGeomOperationsLibrary; |
30 |
import org.gvsig.fmap.mapcontext.MapContextLibrary; |
31 |
import org.gvsig.tools.ToolsLibrary; |
32 |
import org.gvsig.tools.ToolsLocator; |
33 |
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluator; |
34 |
import org.gvsig.tools.evaluator.sqljep.SQLJEPLibrary; |
35 |
import org.gvsig.tools.observer.Observer; |
36 |
import org.gvsig.tools.persistence.xmlentity.XMLEntityManager; |
37 |
import org.slf4j.Logger; |
38 |
import org.slf4j.LoggerFactory; |
39 |
|
40 |
import com.iver.andami.Launcher; |
41 |
import com.iver.andami.PluginServices; |
42 |
import com.iver.andami.plugins.Extension; |
43 |
|
44 |
public class InitializeApplicationExtension extends Extension { |
45 |
private static final Logger logger = LoggerFactory |
46 |
.getLogger(InitializeApplicationExtension.class); |
47 |
private Observer dbPasswordResorceObserver; |
48 |
|
49 |
|
50 |
private AppGvSigLibrary appGvSigLibrary;
|
51 |
|
52 |
private DALFileLibrary dalFileLibrary;
|
53 |
|
54 |
private DXFLibrary dxf;
|
55 |
|
56 |
private DBFLibrary dbf;
|
57 |
|
58 |
private SHPLibrary shp;
|
59 |
|
60 |
private MapContextLibrary mapContextLibrary;
|
61 |
private MapContextGeomOperationsLibrary mapContextGeomOperationLibrary;
|
62 |
|
63 |
|
64 |
private JTSIndexLibrary jtsIndex;
|
65 |
private JSIIndexLibrary jsiIndex;
|
66 |
private Gt2IndexLibrary gt2Index;
|
67 |
private ToolsLibrary toolLibrary;
|
68 |
private DALLibrary dalLibrary;
|
69 |
private GeometryLibrary geometryLibrary;
|
70 |
private SQLJEPLibrary sQLJEPLibrary;
|
71 |
private DefaultGeometryLibrary defaultGeometryLibrary;
|
72 |
private CompatLibrary compatLibrary;
|
73 |
private ProjectionLibrary projectionLibrary;
|
74 |
private CresquesCtsLibrary cresquesCtsLibrary;
|
75 |
|
76 |
|
77 |
|
78 |
public void initialize() { |
79 |
|
80 |
// Basic libraries
|
81 |
toolLibrary = new ToolsLibrary();
|
82 |
toolLibrary.initialize(); |
83 |
|
84 |
// Register persistence manager
|
85 |
ToolsLocator.registerDefaultPersistenceManager(XMLEntityManager.class); |
86 |
|
87 |
projectionLibrary = new ProjectionLibrary();
|
88 |
projectionLibrary.initialize(); |
89 |
|
90 |
cresquesCtsLibrary = new CresquesCtsLibrary();
|
91 |
cresquesCtsLibrary.initialize(); |
92 |
|
93 |
// geometry api
|
94 |
geometryLibrary = new GeometryLibrary();
|
95 |
geometryLibrary.initialize(); |
96 |
|
97 |
// geometry implementation
|
98 |
defaultGeometryLibrary = new DefaultGeometryLibrary();
|
99 |
defaultGeometryLibrary.initialize(); |
100 |
|
101 |
// Data Access Library
|
102 |
dalLibrary = new DALLibrary();
|
103 |
dalLibrary.initialize(); |
104 |
|
105 |
// SQLJEP expression parser for DAL
|
106 |
sQLJEPLibrary = new SQLJEPLibrary();
|
107 |
sQLJEPLibrary.initialize(); |
108 |
|
109 |
|
110 |
// Register default expression parser
|
111 |
DALLocator.getDataManager().registerDefaultEvaluator( |
112 |
SQLJEPEvaluator.class); |
113 |
|
114 |
// DAL file store support library
|
115 |
dalFileLibrary = new DALFileLibrary();
|
116 |
dalFileLibrary.initialize(); |
117 |
|
118 |
// DAL DXF provider
|
119 |
dxf = new DXFLibrary();
|
120 |
dxf.initialize(); |
121 |
|
122 |
// DAL DBF provider
|
123 |
dbf = new DBFLibrary();
|
124 |
dbf.initialize(); |
125 |
|
126 |
// DAL SHP provider
|
127 |
shp = new SHPLibrary();
|
128 |
shp.initialize(); |
129 |
|
130 |
|
131 |
// DAL geom Index JTS provider
|
132 |
jtsIndex = new JTSIndexLibrary();
|
133 |
jtsIndex.initialize(); |
134 |
|
135 |
// DAL geom Index JSI provider
|
136 |
jsiIndex = new JSIIndexLibrary();
|
137 |
jsiIndex.initialize(); |
138 |
|
139 |
// DAL geom Index GT2 provider
|
140 |
gt2Index = new Gt2IndexLibrary();
|
141 |
gt2Index.initialize(); |
142 |
|
143 |
// MapContext library
|
144 |
mapContextLibrary = new MapContextLibrary();
|
145 |
mapContextLibrary.initialize(); |
146 |
|
147 |
// MapContext Geomerty operations library
|
148 |
mapContextGeomOperationLibrary = new MapContextGeomOperationsLibrary();
|
149 |
mapContextGeomOperationLibrary.initialize(); |
150 |
|
151 |
// appGvSIG library
|
152 |
appGvSigLibrary = new AppGvSigLibrary();
|
153 |
appGvSigLibrary.initialize(); |
154 |
|
155 |
// libCompat library
|
156 |
// Register default expression parser
|
157 |
compatLibrary = new CompatLibrary();
|
158 |
compatLibrary.initialize(); |
159 |
SECompatLibrary compatLibraryImpl=new SECompatLibrary();
|
160 |
compatLibraryImpl.initialize(); |
161 |
|
162 |
addToLogInfo(); |
163 |
registerIcons(); |
164 |
|
165 |
} |
166 |
public void postInitialize(){ |
167 |
|
168 |
toolLibrary.postInitialize(); |
169 |
|
170 |
projectionLibrary.postInitialize(); |
171 |
cresquesCtsLibrary.postInitialize(); |
172 |
|
173 |
geometryLibrary.postInitialize(); |
174 |
defaultGeometryLibrary.postInitialize(); |
175 |
|
176 |
dalLibrary.postInitialize(); |
177 |
|
178 |
sQLJEPLibrary.postInitialize(); |
179 |
|
180 |
dalFileLibrary.postInitialize(); |
181 |
|
182 |
dxf.postInitialize(); |
183 |
dbf.postInitialize(); |
184 |
shp.postInitialize(); |
185 |
|
186 |
jtsIndex.postInitialize(); |
187 |
jsiIndex.postInitialize(); |
188 |
gt2Index.postInitialize(); |
189 |
|
190 |
mapContextLibrary.postInitialize(); |
191 |
mapContextGeomOperationLibrary.postInitialize(); |
192 |
|
193 |
appGvSigLibrary.postInitialize(); |
194 |
|
195 |
compatLibrary.postInitialize(); |
196 |
|
197 |
registerObservers(); |
198 |
|
199 |
DALLocator.getResourceManager().startResourceCollector( |
200 |
3 * (60 * 1000), // minutes --> miliseconds |
201 |
null);
|
202 |
|
203 |
} |
204 |
private void registerObservers() { |
205 |
// FIXME
|
206 |
// ResourceManager resMan = DALLocator.getResourceManager();//.getResource(PostgresqlStore.DATASTORE_NAME);
|
207 |
// dbPasswordResorceObserver = new DBResourceManager();
|
208 |
// resMan.addObserver(dbPasswordResorceObserver);
|
209 |
} |
210 |
|
211 |
//Registro en esta extension los iconos que no se donde registrarlos.
|
212 |
private void registerIcons(){ |
213 |
|
214 |
PluginServices.getIconTheme().registerDefault( |
215 |
"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 |
"mapa-icono",
|
227 |
this.getClass().getClassLoader().getResource("images/mapas.png") |
228 |
); |
229 |
|
230 |
PluginServices.getIconTheme().registerDefault( |
231 |
"layout-insert-view",
|
232 |
this.getClass().getClassLoader().getResource("images/MapaVista.png") |
233 |
); |
234 |
|
235 |
PluginServices.getIconTheme().registerDefault( |
236 |
"vista-icono",
|
237 |
this.getClass().getClassLoader().getResource("images/Vista.png") |
238 |
); |
239 |
|
240 |
PluginServices.getIconTheme().registerDefault( |
241 |
"hand-icono",
|
242 |
this.getClass().getClassLoader().getResource("images/Hand.png") |
243 |
); |
244 |
|
245 |
PluginServices.getIconTheme().registerDefault( |
246 |
"add-layer-icono",
|
247 |
this.getClass().getClassLoader().getResource("images/add-layer.png") |
248 |
); |
249 |
|
250 |
PluginServices.getIconTheme().registerDefault( |
251 |
"delete-icono",
|
252 |
this.getClass().getClassLoader().getResource("images/delete.png") |
253 |
); |
254 |
|
255 |
PluginServices.getIconTheme().registerDefault( |
256 |
"arrow-up-icono",
|
257 |
this.getClass().getClassLoader().getResource("images/up-arrow.png") |
258 |
); |
259 |
|
260 |
PluginServices.getIconTheme().registerDefault( |
261 |
"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 |
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 |
|
282 |
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 |
|
289 |
public String getStringInfo() { |
290 |
StringWriter writer = new StringWriter(); |
291 |
String andamiPath;
|
292 |
String extensionsPath;
|
293 |
// String jaiVersion;
|
294 |
|
295 |
Properties props = System.getProperties(); |
296 |
|
297 |
try {
|
298 |
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 |
} |
306 |
try {
|
307 |
try {
|
308 |
extensionsPath = (new File(Launcher.getAndamiConfig().getPluginsDirectory())).getCanonicalPath(); |
309 |
} catch (IOException e) { |
310 |
extensionsPath = (new File(Launcher.getAndamiConfig().getPluginsDirectory())).getAbsolutePath(); |
311 |
} |
312 |
} catch (Exception e1) { |
313 |
extensionsPath = "???";
|
314 |
} |
315 |
|
316 |
|
317 |
|
318 |
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 |
String osName = props.getProperty("os.name"); |
324 |
writer.write("OS name: " + osName + "\n"); |
325 |
writer.write(" arch:" + props.get("os.arch") + "\n"); |
326 |
writer.write(" version:"+ props.get("os.version") + "\n"); |
327 |
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 |
while ( (line = reader.readLine()) != null) { |
335 |
writer.write(" "+line+"\n"); |
336 |
} |
337 |
} |
338 |
catch (Exception ex) { |
339 |
|
340 |
} |
341 |
} |
342 |
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 |
|
348 |
public void terminate() { |
349 |
// 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 |
|
358 |
super.terminate();
|
359 |
// try {
|
360 |
// LayerFactory.getDataSourceFactory().finalizeThis();
|
361 |
// } catch (Exception e) {
|
362 |
// //e.printStackTrace();
|
363 |
// }
|
364 |
|
365 |
} |
366 |
} |