svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / InitializeApplicationExtension.java @ 41347
History | View | Annotate | Download (7.93 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.extension; |
25 |
|
26 |
import java.io.BufferedReader; |
27 |
import java.io.InputStream; |
28 |
import java.io.InputStreamReader; |
29 |
import java.io.StringWriter; |
30 |
import java.util.Properties; |
31 |
|
32 |
import org.gvsig.andami.IconThemeHelper; |
33 |
import org.gvsig.andami.PluginsLocator; |
34 |
import org.gvsig.andami.PluginsManager; |
35 |
import org.gvsig.andami.plugins.Extension; |
36 |
import org.gvsig.app.ApplicationLocator; |
37 |
import org.gvsig.app.ApplicationManager; |
38 |
import org.gvsig.app.gui.preferencespage.AppSymbolPreferences; |
39 |
import org.gvsig.app.project.documents.view.toolListeners.InfoListener; |
40 |
import org.gvsig.app.tools.swing.serv.field.crs.JCRSDynFieldComponentFactory; |
41 |
import org.gvsig.app.util.BaseOpenErrorHandler; |
42 |
import org.gvsig.fmap.dal.DALLocator; |
43 |
import org.gvsig.fmap.dal.OpenErrorHandler; |
44 |
import org.gvsig.fmap.dal.resource.ResourceManager; |
45 |
import org.gvsig.fmap.dal.resource.exception.DisposeResorceManagerException; |
46 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
47 |
import org.gvsig.installer.lib.api.InstallerLocator; |
48 |
import org.gvsig.installer.lib.api.InstallerManager; |
49 |
import org.gvsig.installer.lib.api.PackageInfo; |
50 |
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluator; |
51 |
import org.gvsig.tools.service.spi.ServiceManager; |
52 |
import org.gvsig.tools.swing.spi.ToolsSwingServiceLocator; |
53 |
import org.slf4j.Logger; |
54 |
import org.slf4j.LoggerFactory; |
55 |
|
56 |
public class InitializeApplicationExtension extends Extension { |
57 |
private static final Logger logger = LoggerFactory |
58 |
.getLogger(InitializeApplicationExtension.class); |
59 |
// private Observer dbPasswordResorceObserver;
|
60 |
|
61 |
private OpenErrorHandler openErrorHandler = null; |
62 |
|
63 |
public void initialize() { |
64 |
|
65 |
// Next line moved to ApplicationLibrary
|
66 |
// MapContextLocator.getSymbolManager().setSymbolPreferences(new AppSymbolPreferences());
|
67 |
|
68 |
// Register default expression parser
|
69 |
DALLocator.getDataManager().registerDefaultEvaluator( |
70 |
SQLJEPEvaluator.class); |
71 |
|
72 |
InfoListener.initializeExtensionPoint(); |
73 |
// addToLogInfo();
|
74 |
registerIcons(); |
75 |
|
76 |
} |
77 |
|
78 |
public void postInitialize(){ |
79 |
// Validate there is any implementation registered.
|
80 |
ServiceManager dsManager = ToolsSwingServiceLocator.getServiceManager(); |
81 |
|
82 |
openErrorHandler = new BaseOpenErrorHandler();
|
83 |
ApplicationLocator.getManager().getDataManager().setOpenErrorHandler(openErrorHandler); |
84 |
|
85 |
//CRS Definition
|
86 |
dsManager.addServiceFactory(new JCRSDynFieldComponentFactory());
|
87 |
|
88 |
// registerObservers();
|
89 |
|
90 |
DALLocator.getResourceManager().startResourceCollector( |
91 |
3 * (60 * 1000), // minutes --> miliseconds |
92 |
null);
|
93 |
} |
94 |
|
95 |
// private void registerObservers() {
|
96 |
//// FIXME
|
97 |
//// ResourceManager resMan = DALLocator.getResourceManager();//.getResource(PostgresqlStore.DATASTORE_NAME);
|
98 |
//// dbPasswordResorceObserver = new DBResourceManager();
|
99 |
//// resMan.addObserver(dbPasswordResorceObserver);
|
100 |
// }
|
101 |
|
102 |
private void registerIcons(){ |
103 |
IconThemeHelper.registerIcon("action", "edit-clear", this); |
104 |
IconThemeHelper.registerIcon("action", "edit-copy", this); |
105 |
IconThemeHelper.registerIcon("action", "edit-cut", this); |
106 |
IconThemeHelper.registerIcon("action", "edit-delete", this); |
107 |
IconThemeHelper.registerIcon("action", "edit-find", this); |
108 |
IconThemeHelper.registerIcon("action", "edit-find-replace", this); |
109 |
IconThemeHelper.registerIcon("action", "edit-paste", this); |
110 |
IconThemeHelper.registerIcon("action", "edit-redo", this); |
111 |
IconThemeHelper.registerIcon("action", "edit-select-all", this); |
112 |
IconThemeHelper.registerIcon("action", "edit-undo", this); |
113 |
IconThemeHelper.registerIcon("action", "edit-undo-redo-actions", this); |
114 |
IconThemeHelper.registerIcon("action", "document-print", this); |
115 |
|
116 |
IconThemeHelper.registerIcon("toolbar-go", "go-next", this); |
117 |
IconThemeHelper.registerIcon("toolbar-go", "go-previous", this); |
118 |
IconThemeHelper.registerIcon("toolbar-go", "go-next-fast", this); |
119 |
IconThemeHelper.registerIcon("toolbar-go", "go-previous-fast", this); |
120 |
IconThemeHelper.registerIcon("toolbar-go", "go-first", this); |
121 |
IconThemeHelper.registerIcon("toolbar-go", "go-last", this); |
122 |
|
123 |
} |
124 |
|
125 |
public void execute(String actionCommand) { |
126 |
|
127 |
} |
128 |
|
129 |
public boolean isEnabled() { |
130 |
return false; |
131 |
} |
132 |
|
133 |
public boolean isVisible() { |
134 |
return false; |
135 |
} |
136 |
|
137 |
private void addToLogInfo() { |
138 |
String info[] = this.getStringInfo().split("\n"); |
139 |
for (int i=0;i< info.length;i++) { |
140 |
logger.info(info[i]); |
141 |
} |
142 |
} |
143 |
|
144 |
public String getStringInfo() { |
145 |
ApplicationManager application = ApplicationLocator.getManager(); |
146 |
PluginsManager pluginmgr = PluginsLocator.getManager(); |
147 |
InstallerManager installmgr = InstallerLocator.getInstallerManager(); |
148 |
|
149 |
StringWriter writer = new StringWriter(); |
150 |
|
151 |
Properties props = System.getProperties(); |
152 |
|
153 |
// OS information
|
154 |
String osName = props.getProperty("os.name"); |
155 |
writer.write("OS\n");
|
156 |
writer.write(" name : " + osName + "\n"); |
157 |
writer.write(" arch : " + props.get("os.arch") + "\n"); |
158 |
writer.write(" version: " + props.get("os.version") + "\n"); |
159 |
if (osName.startsWith("Linux")) { |
160 |
try {
|
161 |
String[] command = {"lsb_release", "-a"}; |
162 |
Process p = Runtime.getRuntime().exec(command); |
163 |
InputStream is = p.getInputStream();
|
164 |
BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
165 |
String line;
|
166 |
while ( (line = reader.readLine()) != null) { |
167 |
writer.write(" "+line+"\n"); |
168 |
} |
169 |
} catch (Exception ex) { |
170 |
writer.write("Can't get detailled os information (lsb_release -a).");
|
171 |
} |
172 |
} |
173 |
|
174 |
// JRE information
|
175 |
writer.write("JRE\n");
|
176 |
writer.write(" vendor : " + props.get("java.vendor") + "\n"); |
177 |
writer.write(" version: " +props.get("java.version")+ "\n"); |
178 |
writer.write(" home : " + props.get("java.home") + "\n"); |
179 |
|
180 |
|
181 |
writer.write("gvSIG\n");
|
182 |
writer.write(" version : " + application.getVersion().getLongFormat() + "\n"); |
183 |
writer.write(" locale language : " + application.getLocaleLanguage()+ "\n"); |
184 |
writer.write(" application forlder : " + pluginmgr.getApplicationFolder()+ "\n"); |
185 |
writer.write(" install forlder : " + pluginmgr.getInstallFolder()+ "\n"); |
186 |
writer.write(" application home forlder: " + pluginmgr.getApplicationHomeFolder()+ "\n"); |
187 |
writer.write(" plugins forlder : " + pluginmgr.getPluginsFolder()+ "\n"); |
188 |
|
189 |
try {
|
190 |
PackageInfo[] pkgs = installmgr.getInstalledPackages(pluginmgr.getPluginsFolder());
|
191 |
writer.write("Installed packages\n");
|
192 |
for( int i=0; i<pkgs.length; i++) { |
193 |
writer.write(" ");
|
194 |
writer.write(pkgs[i].toStringCompact()); |
195 |
writer.write("\n");
|
196 |
} |
197 |
} catch(Throwable e) { |
198 |
writer.write("Can't get installed package information.");
|
199 |
} |
200 |
return writer.toString();
|
201 |
} |
202 |
|
203 |
public void terminate() { |
204 |
// XXX: Need a TerminateApplicationExtension ???
|
205 |
ResourceManager resMan = DALLocator.getResourceManager(); |
206 |
resMan.stopResourceCollector(); |
207 |
try {
|
208 |
resMan.dispose(); |
209 |
} catch (DisposeResorceManagerException e) {
|
210 |
logger.error("Exceptions at dispose Resource Manager", e);
|
211 |
} |
212 |
|
213 |
super.terminate();
|
214 |
// try {
|
215 |
// LayerFactory.getDataSourceFactory().finalizeThis();
|
216 |
// } catch (Exception e) {
|
217 |
// //e.printStackTrace();
|
218 |
// }
|
219 |
|
220 |
} |
221 |
} |