1 package org.codehaus.plexus.component.discovery;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.util.ArrayList;
20 import java.util.LinkedHashMap;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.Set;
24
25 public class DefaultComponentDiscovererManager implements ComponentDiscovererManager {
26 private final List<ComponentDiscoverer> componentDiscoverers = new ArrayList<ComponentDiscoverer>();
27
28
29 private final Map<ComponentDiscoveryListener, Object> listeners =
30 new LinkedHashMap<ComponentDiscoveryListener, Object>();
31
32 public synchronized void addComponentDiscoverer(ComponentDiscoverer discoverer) {
33 componentDiscoverers.add(discoverer);
34 }
35
36
37 public synchronized List<ComponentDiscoverer> getComponentDiscoverers() {
38 return componentDiscoverers;
39 }
40
41
42
43
44 public synchronized Map<ComponentDiscoveryListener, Object> getComponentDiscoveryListeners() {
45 return listeners;
46 }
47
48 public synchronized void registerComponentDiscoveryListener(ComponentDiscoveryListener listener) {
49 if (!listeners.containsKey(listener)) {
50 listeners.put(listener, new Object());
51 }
52 }
53
54 public synchronized void removeComponentDiscoveryListener(ComponentDiscoveryListener listener) {
55 listeners.remove(listener);
56 }
57
58 public void fireComponentDiscoveryEvent(ComponentDiscoveryEvent event) {
59 Set<ComponentDiscoveryListener> listeners;
60 synchronized (this) {
61 listeners = this.listeners.keySet();
62 }
63
64 for (ComponentDiscoveryListener listener : listeners) {
65 listener.componentDiscovered(event);
66 }
67 }
68 }