1 package org.codehaus.plexus.container.initialization;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import org.codehaus.plexus.component.discovery.ComponentDiscovererManager;
20 import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
21
22
23
24
25 public class InitializeComponentDiscovererManagerPhase extends AbstractCoreComponentInitializationPhase {
26 public void initializeCoreComponent(ContainerInitializationContext context)
27 throws ContainerInitializationException {
28 ComponentDiscovererManager componentDiscovererManager =
29 context.getContainerConfiguration().getComponentDiscovererManager();
30
31 context.getContainer().setComponentDiscovererManager(componentDiscovererManager);
32
33 for (ComponentDiscoveryListener listener :
34 componentDiscovererManager.getComponentDiscoveryListeners().keySet()) {
35 try {
36
37
38 context.getContainer()
39 .addComponent(listener, listener.getClass().getName());
40
41 context.getContainer().getComponentDiscovererManager().removeComponentDiscoveryListener(listener);
42
43 ComponentDiscoveryListener cdl = context.getContainer().lookup(listener.getClass());
44
45 context.getContainer().getComponentDiscovererManager().registerComponentDiscoveryListener(cdl);
46 } catch (Exception e) {
47 throw new ContainerInitializationException("Error initializing component discovery listener.", e);
48 }
49 }
50 }
51 }