svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.framework / org.gvsig.andami / src / main / java / org / gvsig / andami / impl / DefaultPluginsManager.java @ 41072
History | View | Annotate | Download (5.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.andami.impl; |
25 |
|
26 |
import java.io.File; |
27 |
import java.util.ArrayList; |
28 |
import java.util.Enumeration; |
29 |
import java.util.Iterator; |
30 |
import java.util.List; |
31 |
|
32 |
import org.gvsig.andami.Launcher; |
33 |
import org.gvsig.andami.PluginServices; |
34 |
import org.gvsig.andami.PluginsManager; |
35 |
import org.gvsig.andami.config.generate.AndamiConfig; |
36 |
import org.gvsig.andami.config.generate.Plugin; |
37 |
import org.gvsig.andami.plugins.ExclusiveUIExtension; |
38 |
import org.gvsig.andami.plugins.IExtension; |
39 |
import org.gvsig.andami.plugins.PluginClassLoader; |
40 |
import org.gvsig.installer.lib.api.PackageInfo; |
41 |
import org.gvsig.tools.ToolsLocator; |
42 |
import org.gvsig.tools.packageutils.PackageManager; |
43 |
import org.slf4j.Logger; |
44 |
import org.slf4j.LoggerFactory; |
45 |
|
46 |
public class DefaultPluginsManager implements PluginsManager{ |
47 |
|
48 |
private static Logger logger = |
49 |
LoggerFactory.getLogger(DefaultPluginsManager.class); |
50 |
|
51 |
private List<File> pluginsFolders = null; |
52 |
|
53 |
public ExclusiveUIExtension getExclusiveUIExtension() {
|
54 |
return PluginServices.getExclusiveUIExtension();
|
55 |
} |
56 |
|
57 |
public IExtension getExtension(Class<? extends IExtension> extension) { |
58 |
return PluginServices.getExtension(extension);
|
59 |
} |
60 |
|
61 |
@SuppressWarnings("unchecked") |
62 |
public Iterator<IExtension> getExtensions() { |
63 |
return PluginServices.getExtensions();
|
64 |
} |
65 |
|
66 |
/**
|
67 |
* Return the associated pluginServices to the extension class passed as parameter.
|
68 |
*
|
69 |
*/
|
70 |
public PluginServices getPlugin(Class<? extends IExtension> extension) { |
71 |
String pluginName = ((PluginClassLoader)extension.getClassLoader()).getPluginName();
|
72 |
return this.getPlugin(pluginName); |
73 |
} |
74 |
|
75 |
public PluginServices getPlugin(String pluginName) { |
76 |
return Launcher.getPluginServices(pluginName);
|
77 |
} |
78 |
|
79 |
public PackageInfo getPackageInfo(Class<? extends IExtension> extension) { |
80 |
PackageManager pkgmgr = ToolsLocator.getPackageManager(); |
81 |
File pinfo_file = new File(this.getPlugin(extension).getPluginDirectory(), "package.info"); |
82 |
|
83 |
PackageInfo packageInfo = null;
|
84 |
try {
|
85 |
packageInfo = pkgmgr.createPackageInfo(pinfo_file); |
86 |
} catch (Exception e) { |
87 |
logger.info("Error while reading package info file from "
|
88 |
+ pinfo_file.toString(), e); |
89 |
} |
90 |
return packageInfo;
|
91 |
} |
92 |
|
93 |
public PackageInfo getPackageInfo(String pluginName) { |
94 |
PackageManager pkgmgr = ToolsLocator.getPackageManager(); |
95 |
File pinfo_file = new File(this.getPlugin(pluginName) |
96 |
.getPluginDirectory(), "package.info");
|
97 |
|
98 |
PackageInfo packageInfo = null;
|
99 |
try {
|
100 |
packageInfo = pkgmgr.createPackageInfo(pinfo_file); |
101 |
} catch (Exception e) { |
102 |
logger.info("Error while reading package info file from "
|
103 |
+ pinfo_file.toString(), e); |
104 |
} |
105 |
return packageInfo;
|
106 |
} |
107 |
|
108 |
public PackageInfo getPackageInfo() {
|
109 |
PackageManager pkgmgr = ToolsLocator.getPackageManager(); |
110 |
File pinfo_file = new File( |
111 |
this.getApplicationFolder(), "package.info"); |
112 |
PackageInfo packageInfo = null;
|
113 |
try {
|
114 |
packageInfo = pkgmgr.createPackageInfo(pinfo_file); |
115 |
} catch (Exception e) { |
116 |
logger.info("Error while reading package info file from "
|
117 |
+ pinfo_file.toString(), e); |
118 |
} |
119 |
return packageInfo;
|
120 |
} |
121 |
|
122 |
@SuppressWarnings("unchecked") |
123 |
public List<PluginServices> getPlugins() { |
124 |
List<PluginServices> pluginServices = new ArrayList<PluginServices>(); |
125 |
|
126 |
AndamiConfig config = Launcher.getAndamiConfig(); |
127 |
Enumeration<Plugin> plugins = config.enumeratePlugin();
|
128 |
while( plugins.hasMoreElements()) {
|
129 |
Plugin plugin = plugins.nextElement(); |
130 |
pluginServices.add(PluginServices.getPluginServices(plugin.getName())); |
131 |
} |
132 |
return pluginServices;
|
133 |
} |
134 |
|
135 |
public void setExclusiveUIExtension(ExclusiveUIExtension extension) { |
136 |
PluginServices.setExclusiveUIExtension(extension); |
137 |
} |
138 |
|
139 |
public String getText(Object obj, String msg) { |
140 |
return PluginServices.getText(obj, msg);
|
141 |
} |
142 |
|
143 |
public String translate(String msg) { |
144 |
return org.gvsig.i18n.Messages.translate(msg);
|
145 |
} |
146 |
|
147 |
public File getApplicationFolder() { |
148 |
return Launcher.getApplicationFolder();
|
149 |
} |
150 |
|
151 |
/**
|
152 |
* @deprecated use {@link #getPluginsFolders()}
|
153 |
*/
|
154 |
public File getPluginsDirectory() { |
155 |
return getPluginsFolder();
|
156 |
} |
157 |
|
158 |
/**
|
159 |
* @deprecated use {@link #getPluginsFolders()}
|
160 |
*/
|
161 |
public File getPluginsFolder() { |
162 |
List<File> l = this.getPluginsFolders(); |
163 |
if( l==null || l.size()<1 ) { |
164 |
return null; |
165 |
} |
166 |
return l.get(0); |
167 |
} |
168 |
|
169 |
public List<File> getPluginsFolders() { |
170 |
if( this.pluginsFolders!=null ) { |
171 |
return this.pluginsFolders; |
172 |
} |
173 |
String folder = "gvSIG/extensiones"; |
174 |
if( !(Launcher.getAndamiConfig() == null || Launcher.getAndamiConfig().getPluginsDirectory()==null) ) { |
175 |
folder = Launcher.getAndamiConfig().getPluginsDirectory(); |
176 |
} |
177 |
this.pluginsFolders = new ArrayList<File>(); |
178 |
this.pluginsFolders.add(new File(getApplicationFolder(), folder)); |
179 |
return this.pluginsFolders; |
180 |
} |
181 |
|
182 |
public File getInstallFolder() { |
183 |
return new File(getApplicationFolder(), "install"); |
184 |
} |
185 |
|
186 |
public File getApplicationHomeFolder() { |
187 |
return Launcher.getApplicationHomeFolder();
|
188 |
} |
189 |
} |