String role = listenerDescriptor.getRole();
String roleHint = listenerDescriptor.getRoleHint();
try
{
MutablePlexusContainer container = context.getContainer();
ComponentDiscoveryListener listener;
if ( container.getParentContainer() != null )
{
try
{
listener = (ComponentDiscoveryListener) container.getParentContainer().lookup(
role,
roleHint );
}
catch ( ComponentLookupException e )
{
listener = (ComponentDiscoveryListener) container.lookup( role, roleHint );
}
}
else
{
listener = (ComponentDiscoveryListener) container.lookup( role, roleHint );
}
container.getComponentDiscovererManager().registerComponentDiscoveryListener( listener );
}
catch ( ComponentLookupException e )
{
throw new ContainerInitializationException( "Error looking up component discovery listener.", e );
}