1 package net.sourceforge.blogentis.plugins;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import java.util.Iterator;
26 import java.util.LinkedList;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30
31 /***
32 * A simple IExtensionPoint base class implementation. It uses a LinkedList as
33 * an underlying extension store. Only the extension modification methods are
34 * synchronized.
35 *
36 * @author abas
37 */
38 public abstract class AbstractExtensionPoint
39 implements IExtensionPoint {
40 private final Log log = LogFactory.getLog(this.getClass());
41 protected LinkedList extensions = new LinkedList();
42 protected IPlugin plugin;
43
44 public AbstractExtensionPoint(IPlugin plugin) {
45 this.plugin = plugin;
46 }
47
48 public synchronized void addExtension(IExtension ext) {
49 if (!getExtensionClass().isInstance(ext)) {
50 throw new ClassCastException(ext.getClass() + " is not a "
51 + getClass());
52 }
53 if (log.isDebugEnabled())
54 log.debug("Adding extension '" + ext.getName() + "'");
55 extensions.addLast(ext);
56 }
57
58 public synchronized void removeExtension(IExtension extension) {
59 extensions.remove(extension);
60 }
61
62 public synchronized void removeExtensions(IPlugin fromPlugin) {
63 for(Iterator i = getExtensions(); i.hasNext();) {
64 IExtension ext = (IExtension)i.next();
65 if (ext.getPlugin().equals(fromPlugin))
66 i.remove();
67 }
68 }
69
70 public Iterator getExtensions() {
71 return extensions.iterator();
72 }
73
74 public IPlugin getPlugin() {
75 return plugin;
76 }
77 }