svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / InitializeApplicationExtension.java @ 26949
History | View | Annotate | Download (7.82 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.apache.log4j.Logger; |
12 |
import org.gvsig.AppGvSigLibrary; |
13 |
import org.gvsig.fmap.dal.DALFileLibrary; |
14 |
import org.gvsig.fmap.dal.DALLibrary; |
15 |
import org.gvsig.fmap.dal.DALLocator; |
16 |
import org.gvsig.fmap.dal.index.spatial.gt2.Gt2IndexLibrary; |
17 |
import org.gvsig.fmap.dal.index.spatial.jsi.JSIIndexLibrary; |
18 |
import org.gvsig.fmap.dal.index.spatial.jts.JTSIndexLibrary; |
19 |
import org.gvsig.fmap.dal.store.dbf.DBFLibrary; |
20 |
import org.gvsig.fmap.dal.store.dxf.DXFLibrary; |
21 |
import org.gvsig.fmap.dal.store.shp.SHPLibrary; |
22 |
import org.gvsig.fmap.geom.GeometryLibrary; |
23 |
import org.gvsig.fmap.mapcontext.MapContextLibrary; |
24 |
import org.gvsig.tools.ToolsLibrary; |
25 |
import org.gvsig.tools.ToolsLocator; |
26 |
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluator; |
27 |
import org.gvsig.tools.evaluator.sqljep.SQLJEPLibrary; |
28 |
import org.gvsig.tools.observer.Observer; |
29 |
import org.gvsig.tools.persistence.xmlentity.XMLEntityManager; |
30 |
|
31 |
import com.iver.andami.Launcher; |
32 |
import com.iver.andami.PluginServices; |
33 |
import com.iver.andami.plugins.Extension; |
34 |
|
35 |
public class InitializeApplicationExtension extends Extension { |
36 |
private static Logger logger = Logger.getLogger("gvSIG"); |
37 |
private Observer dbPasswordResorceObserver; |
38 |
|
39 |
|
40 |
private AppGvSigLibrary appGvSigLibrary;
|
41 |
|
42 |
private DALFileLibrary dalFileLibrary;
|
43 |
|
44 |
private DXFLibrary dxf;
|
45 |
|
46 |
private DBFLibrary dbf;
|
47 |
|
48 |
private SHPLibrary shp;
|
49 |
|
50 |
private MapContextLibrary mapContextLibrary;
|
51 |
|
52 |
|
53 |
private JTSIndexLibrary jtsIndex;
|
54 |
private JSIIndexLibrary jsiIndex;
|
55 |
private Gt2IndexLibrary gt2Index;
|
56 |
|
57 |
|
58 |
|
59 |
public void initialize() { |
60 |
|
61 |
ToolsLibrary toolLibrary = new ToolsLibrary();
|
62 |
|
63 |
toolLibrary.initialize(); |
64 |
toolLibrary.postInitialize(); |
65 |
|
66 |
ToolsLocator |
67 |
.registerDefaultPersistenceManager(XMLEntityManager.class); |
68 |
|
69 |
DALLibrary dalLibrary = new DALLibrary();
|
70 |
dalLibrary.initialize(); |
71 |
dalLibrary.postInitialize(); |
72 |
|
73 |
|
74 |
GeometryLibrary lib = new GeometryLibrary();
|
75 |
lib.initialize(); |
76 |
lib.postInitialize(); |
77 |
|
78 |
SQLJEPLibrary sQLJEPLibrary = new SQLJEPLibrary();
|
79 |
sQLJEPLibrary.initialize(); |
80 |
sQLJEPLibrary.postInitialize(); |
81 |
|
82 |
|
83 |
DALLocator.getDataManager().registerDefaultEvaluator( |
84 |
SQLJEPEvaluator.class); |
85 |
|
86 |
appGvSigLibrary = new AppGvSigLibrary();
|
87 |
appGvSigLibrary.initialize(); |
88 |
|
89 |
dalFileLibrary = new DALFileLibrary();
|
90 |
dalFileLibrary.initialize(); |
91 |
|
92 |
dxf = new DXFLibrary();
|
93 |
dxf.initialize(); |
94 |
|
95 |
dbf = new DBFLibrary();
|
96 |
dbf.initialize(); |
97 |
|
98 |
shp = new SHPLibrary();
|
99 |
shp.initialize(); |
100 |
|
101 |
|
102 |
|
103 |
|
104 |
jtsIndex = new JTSIndexLibrary();
|
105 |
jtsIndex.initialize(); |
106 |
|
107 |
jsiIndex = new JSIIndexLibrary();
|
108 |
jsiIndex.initialize(); |
109 |
|
110 |
gt2Index = new Gt2IndexLibrary();
|
111 |
gt2Index.initialize(); |
112 |
|
113 |
mapContextLibrary = new MapContextLibrary();
|
114 |
mapContextLibrary.initialize(); |
115 |
|
116 |
addToLogInfo(); |
117 |
registerIcons(); |
118 |
|
119 |
} |
120 |
public void postInitialize(){ |
121 |
|
122 |
appGvSigLibrary.postInitialize(); |
123 |
|
124 |
dalFileLibrary.postInitialize(); |
125 |
|
126 |
dxf.postInitialize(); |
127 |
dbf.postInitialize(); |
128 |
shp.postInitialize(); |
129 |
|
130 |
jtsIndex.postInitialize(); |
131 |
|
132 |
jsiIndex.postInitialize(); |
133 |
|
134 |
gt2Index.postInitialize(); |
135 |
|
136 |
mapContextLibrary.postInitialize(); |
137 |
|
138 |
registerObservers(); |
139 |
} |
140 |
private void registerObservers() { |
141 |
// FIXME
|
142 |
// ResourceManager resMan = DALLocator.getResourceManager();//.getResource(PostgresqlStore.DATASTORE_NAME);
|
143 |
// dbPasswordResorceObserver = new DBResourceManager();
|
144 |
// resMan.addObserver(dbPasswordResorceObserver);
|
145 |
} |
146 |
|
147 |
//Registro en esta extension los iconos que no se donde registrarlos.
|
148 |
private void registerIcons(){ |
149 |
|
150 |
PluginServices.getIconTheme().registerDefault( |
151 |
"view-add-event-layer",
|
152 |
this.getClass().getClassLoader().getResource("images/addeventtheme.png") |
153 |
); |
154 |
PluginServices.getIconTheme().registerDefault( |
155 |
"gvsig-logo-icon",
|
156 |
this.getClass().getClassLoader().getResource("images/icon_gvsig.png") |
157 |
); |
158 |
|
159 |
|
160 |
|
161 |
PluginServices.getIconTheme().registerDefault( |
162 |
"mapa-icono",
|
163 |
this.getClass().getClassLoader().getResource("images/mapas.png") |
164 |
); |
165 |
|
166 |
PluginServices.getIconTheme().registerDefault( |
167 |
"layout-insert-view",
|
168 |
this.getClass().getClassLoader().getResource("images/MapaVista.png") |
169 |
); |
170 |
|
171 |
PluginServices.getIconTheme().registerDefault( |
172 |
"vista-icono",
|
173 |
this.getClass().getClassLoader().getResource("images/Vista.png") |
174 |
); |
175 |
|
176 |
PluginServices.getIconTheme().registerDefault( |
177 |
"hand-icono",
|
178 |
this.getClass().getClassLoader().getResource("images/Hand.png") |
179 |
); |
180 |
|
181 |
PluginServices.getIconTheme().registerDefault( |
182 |
"add-layer-icono",
|
183 |
this.getClass().getClassLoader().getResource("images/add-layer.png") |
184 |
); |
185 |
|
186 |
PluginServices.getIconTheme().registerDefault( |
187 |
"delete-icono",
|
188 |
this.getClass().getClassLoader().getResource("images/delete.png") |
189 |
); |
190 |
|
191 |
PluginServices.getIconTheme().registerDefault( |
192 |
"arrow-up-icono",
|
193 |
this.getClass().getClassLoader().getResource("images/up-arrow.png") |
194 |
); |
195 |
|
196 |
PluginServices.getIconTheme().registerDefault( |
197 |
"arrow-down-icono",
|
198 |
this.getClass().getClassLoader().getResource("images/down-arrow.png") |
199 |
); |
200 |
// PluginServices.getIconTheme().register(
|
201 |
// "arrow-down-icono",
|
202 |
// PrintPropertiesPage.class.getClassLoader().getResource("images/prepare-page.png")
|
203 |
// );
|
204 |
} |
205 |
|
206 |
public void execute(String actionCommand) { |
207 |
|
208 |
} |
209 |
|
210 |
public boolean isEnabled() { |
211 |
return false; |
212 |
} |
213 |
|
214 |
public boolean isVisible() { |
215 |
return false; |
216 |
} |
217 |
|
218 |
private void addToLogInfo() { |
219 |
String info[] = this.getStringInfo().split("\n"); |
220 |
for (int i=0;i< info.length;i++) { |
221 |
logger.info(info[i]); |
222 |
} |
223 |
} |
224 |
|
225 |
public String getStringInfo() { |
226 |
StringWriter writer = new StringWriter(); |
227 |
String andamiPath;
|
228 |
String extensionsPath;
|
229 |
// String jaiVersion;
|
230 |
|
231 |
Properties props = System.getProperties(); |
232 |
|
233 |
try {
|
234 |
try {
|
235 |
andamiPath = (new File(Launcher.class.getResource(".").getFile() + File.separator + ".." + File.separator + ".." + File.separator +"..")).getCanonicalPath(); |
236 |
} catch (IOException e) { |
237 |
andamiPath = (new File(Launcher.class.getResource(".").getFile() + File.separator + ".." + File.separator + ".." + File.separator +"..")).getAbsolutePath(); |
238 |
} |
239 |
} catch (Exception e1) { |
240 |
andamiPath = (String)props.get("user.dir"); |
241 |
} |
242 |
try {
|
243 |
try {
|
244 |
extensionsPath = (new File(Launcher.getAndamiConfig().getPluginsDirectory())).getCanonicalPath(); |
245 |
} catch (IOException e) { |
246 |
extensionsPath = (new File(Launcher.getAndamiConfig().getPluginsDirectory())).getAbsolutePath(); |
247 |
} |
248 |
} catch (Exception e1) { |
249 |
extensionsPath = "???";
|
250 |
} |
251 |
|
252 |
|
253 |
|
254 |
writer.write("gvSIG version: " + Version.longFormat() + "\n"); |
255 |
writer.write(" gvSIG app exec path: " + andamiPath + "\n"); |
256 |
writer.write(" gvSIG user app home: " + Launcher.getAppHomeDir() + "\n"); |
257 |
writer.write(" gvSIG extension path: " + extensionsPath + "\n"); |
258 |
writer.write(" gvSIG locale language: " + Launcher.getAndamiConfig().getLocaleLanguage() + "\n"); |
259 |
String osName = props.getProperty("os.name"); |
260 |
writer.write("OS name: " + osName + "\n"); |
261 |
writer.write(" arch:" + props.get("os.arch") + "\n"); |
262 |
writer.write(" version:"+ props.get("os.version") + "\n"); |
263 |
if (osName.startsWith("Linux")) { |
264 |
try {
|
265 |
String[] command = {"lsb_release", "-a"}; |
266 |
Process p = Runtime.getRuntime().exec(command); |
267 |
InputStream is = p.getInputStream();
|
268 |
BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
269 |
String line;
|
270 |
while ( (line = reader.readLine()) != null) { |
271 |
writer.write(" "+line+"\n"); |
272 |
} |
273 |
} |
274 |
catch (Exception ex) { |
275 |
|
276 |
} |
277 |
} |
278 |
|
279 |
writer.write("JAVA vendor: " + props.get("java.vendor") + "\n"); |
280 |
writer.write(" version:" +props.get("java.version")+ "\n"); |
281 |
writer.write(" home: " + props.get("java.home") + "\n"); |
282 |
return writer.toString();
|
283 |
} |
284 |
|
285 |
public void terminate() { |
286 |
|
287 |
super.terminate();
|
288 |
// try {
|
289 |
// LayerFactory.getDataSourceFactory().finalizeThis();
|
290 |
// } catch (Exception e) {
|
291 |
// //e.printStackTrace();
|
292 |
// }
|
293 |
|
294 |
} |
295 |
} |