01: package org.osbl.plugin;
02:
03: import org.apache.commons.logging.LogFactory;
04:
05: import java.util.*;
06:
07: public class PluginManager {
08: private static org.apache.commons.logging.Log LOG = LogFactory
09: .getLog(PluginManager.class);
10:
11: String name;
12:
13: Map<String, Plugin> plugins = new HashMap<String, Plugin>();
14: Map<String, Extension> extensions = new HashMap<String, Extension>();
15: Map<String, List<Extension>> extensionsByType = new HashMap<String, List<Extension>>();
16:
17: public String getName() {
18: return name;
19: }
20:
21: public void setName(String name) {
22: this .name = name;
23: }
24:
25: public void registerPlugin(Plugin plugin) {
26: plugins.put(plugin.getName(), plugin);
27: }
28:
29: public void registerExtension(Extension extension) {
30: LOG.info(name + ": Register Extension: " + extension.getName());
31: extensions.put(extension.getName(), extension);
32:
33: List<Extension> list = extensionsByType
34: .get(extension.getType());
35: if (list == null) {
36: list = new ArrayList<Extension>();
37: extensionsByType.put(extension.getType(), list);
38: }
39: list.add(extension);
40: }
41:
42: public List<Extension> getExtensions(ExtensionPoint extensionPoint) {
43: List<Extension> list = extensionsByType.get(extensionPoint
44: .getType());
45: if (list == null) {
46: LOG.debug(name + ": No extensions for " + extensionPoint);
47: return Collections.EMPTY_LIST;
48: }
49: for (Extension extension : list) {
50: if (!(extensionPoint.getFace().isAssignableFrom(extension
51: .getImplementation())))
52: throw new ClassCastException(
53: name
54: + ": extension implementation '"
55: + extension.getImplementation()
56: + "' does not match interface of extension point '"
57: + extensionPoint.getFace() + "'");
58: }
59: return list;
60: }
61: }
|