svn-gvsig-desktop / tags / v2_0_0_Build_2057 / frameworks / _fwAndami / src / org / gvsig / andami / impl / DefaultPluginsManager.java @ 39145
History | View | Annotate | Download (4 KB)
1 |
package org.gvsig.andami.impl; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.FileInputStream; |
5 |
import java.util.ArrayList; |
6 |
import java.util.Enumeration; |
7 |
import java.util.Iterator; |
8 |
import java.util.List; |
9 |
|
10 |
import org.slf4j.Logger; |
11 |
import org.slf4j.LoggerFactory; |
12 |
|
13 |
import org.gvsig.andami.Launcher; |
14 |
import org.gvsig.andami.PluginServices; |
15 |
import org.gvsig.andami.PluginsManager; |
16 |
import org.gvsig.andami.config.generate.AndamiConfig; |
17 |
import org.gvsig.andami.config.generate.Plugin; |
18 |
import org.gvsig.andami.plugins.ExclusiveUIExtension; |
19 |
import org.gvsig.andami.plugins.IExtension; |
20 |
import org.gvsig.andami.plugins.PluginClassLoader; |
21 |
import org.gvsig.installer.lib.api.InstallerLocator; |
22 |
import org.gvsig.installer.lib.api.InstallerManager; |
23 |
import org.gvsig.installer.lib.api.PackageInfo; |
24 |
|
25 |
public class DefaultPluginsManager implements PluginsManager{ |
26 |
|
27 |
private static Logger logger = |
28 |
LoggerFactory.getLogger(DefaultPluginsManager.class); |
29 |
|
30 |
private File pluginsFolder = null; |
31 |
|
32 |
public ExclusiveUIExtension getExclusiveUIExtension() {
|
33 |
return PluginServices.getExclusiveUIExtension();
|
34 |
} |
35 |
|
36 |
public IExtension getExtension(Class<? extends IExtension> extension) { |
37 |
return PluginServices.getExtension(extension);
|
38 |
} |
39 |
|
40 |
@SuppressWarnings("unchecked") |
41 |
public Iterator<IExtension> getExtensions() { |
42 |
return PluginServices.getExtensions();
|
43 |
} |
44 |
|
45 |
/**
|
46 |
* Return the associated pluginServices to the extension class passed as parameter.
|
47 |
*
|
48 |
*/
|
49 |
public PluginServices getPlugin(Class<? extends IExtension> extension) { |
50 |
String pluginName = ((PluginClassLoader)extension.getClassLoader()).getPluginName();
|
51 |
return this.getPlugin(pluginName); |
52 |
} |
53 |
|
54 |
public PluginServices getPlugin(String pluginName) { |
55 |
return Launcher.getPluginServices(pluginName);
|
56 |
} |
57 |
|
58 |
public PackageInfo getPackageInfo(Class<? extends IExtension> extension) { |
59 |
|
60 |
InstallerManager installer = InstallerLocator.getInstallerManager(); |
61 |
File pinfo_file = new File(this.getPlugin(extension).getPluginDirectory(), "package.info"); |
62 |
|
63 |
FileInputStream fis = null; |
64 |
PackageInfo packageInfo = null;
|
65 |
try {
|
66 |
fis = new FileInputStream(pinfo_file); |
67 |
packageInfo = installer.createPackageInfo(fis); |
68 |
|
69 |
} catch (Exception e) { |
70 |
logger.info("Error while reading package info file from " + extension.getName(), e);
|
71 |
} |
72 |
|
73 |
try {
|
74 |
fis.close(); |
75 |
} catch (Exception ioe) { |
76 |
logger.info("Error while closing stream in extension: " + extension.getName(), ioe);
|
77 |
} |
78 |
return packageInfo;
|
79 |
} |
80 |
|
81 |
@SuppressWarnings("unchecked") |
82 |
public List<PluginServices> getPlugins() { |
83 |
List<PluginServices> pluginServices = new ArrayList<PluginServices>(); |
84 |
|
85 |
AndamiConfig config = Launcher.getAndamiConfig(); |
86 |
Enumeration<Plugin> plugins = config.enumeratePlugin();
|
87 |
while( plugins.hasMoreElements()) {
|
88 |
Plugin plugin = plugins.nextElement(); |
89 |
pluginServices.add(PluginServices.getPluginServices(plugin.getName())); |
90 |
} |
91 |
return pluginServices;
|
92 |
} |
93 |
|
94 |
public void setExclusiveUIExtension(ExclusiveUIExtension extension) { |
95 |
PluginServices.setExclusiveUIExtension(extension); |
96 |
} |
97 |
|
98 |
public String getText(Object obj, String msg) { |
99 |
return PluginServices.getText(obj, msg);
|
100 |
} |
101 |
|
102 |
public File getPluginsDirectory() { |
103 |
return getPluginsFolder();
|
104 |
} |
105 |
|
106 |
public File getApplicationFolder() { |
107 |
return Launcher.getApplicationFolder();
|
108 |
} |
109 |
|
110 |
public File getPluginsFolder() { |
111 |
if( this.pluginsFolder!=null ) { |
112 |
return this.pluginsFolder; |
113 |
} |
114 |
String folder = "gvSIG/extensiones"; |
115 |
if( !(Launcher.getAndamiConfig() == null || Launcher.getAndamiConfig().getPluginsDirectory()==null) ) { |
116 |
folder = Launcher.getAndamiConfig().getPluginsDirectory(); |
117 |
} |
118 |
this.pluginsFolder = new File(getApplicationFolder(), folder); |
119 |
return this.pluginsFolder; |
120 |
} |
121 |
|
122 |
public File getInstallFolder() { |
123 |
return new File(getApplicationFolder(), "install"); |
124 |
} |
125 |
|
126 |
public File getApplicationHomeFolder() { |
127 |
return Launcher.getApplicationHomeFolder();
|
128 |
} |
129 |
} |