if( getLogger().isErrorEnabled() )
{
getLogger().error( message );
}
throw new ComponentException( role, message );
}
ComponentHandler handler = (ComponentHandler)m_componentHandlers.get( role );
// Retrieve the instance of the requested component
if( null == handler )
{
if( m_parentManager != null )
{
try
{
return m_parentManager.lookup( role );
}
catch( Exception e )
{
if( getLogger().isWarnEnabled() )
{
final String message =
"ComponentLocator exception from parent CM during lookup.";
getLogger().warn( message, e );
}
// ignore. If the exception is thrown, we try to
// create the component next
}
}
if( null != m_roles )
{
final String className = m_roles.getDefaultClassNameForRole( role );
if( null != className )
{
if( getLogger().isDebugEnabled() )
{
getLogger().debug( "Could not find ComponentHandler, attempting to create "
+ "one for role [" + role + "]" );
}
try
{
final Class componentClass = m_loader.loadClass( className );
final Configuration configuration = new DefaultConfiguration( "", "-" );
handler = getComponentHandler( role,
componentClass,
configuration,
m_context,
m_roles,
m_logkit );
handler.setLogger( getLogkitLogger() );
handler.enableLogging( getLogger() );
handler.initialize();
}
catch( final Exception e )
{
final String message = "Could not find component";
if( getLogger().isDebugEnabled() )
{
getLogger().debug( message + " for role: " + role, e );
}
throw new ComponentException( role, message, e );
}
m_componentHandlers.put( role, handler );
}
}
else
{
getLogger().debug( "Component requested without a RoleManager set.\n"
+ "That means setRoleManager() was not called during initialization." );
}
}
if( null == handler )
{
final String message = "Could not find component";
if( getLogger().isDebugEnabled() )
{
getLogger().debug( message + " for role: " + role );
}
throw new ComponentException( role, message );
}
Component component = null;
try
{
component = handler.get();
}
catch( final IllegalStateException ise )
{
try
{
handler.initialize();
component = handler.get();
}
catch( final ComponentException ce )
{
// Rethrow instead of wrapping a ComponentException with another one
throw ce;
}
catch( final Exception e )
{
final String message = "Could not access the Component";
if( getLogger().isDebugEnabled() )
{
getLogger().debug( message + " for role [" + role + "]", e );
}
throw new ComponentException( role, message, e );
}
}
catch( final Exception e )
{
final String message = "Could not access the Component";
if( getLogger().isDebugEnabled() )
{
getLogger().debug( message + " for role [" + role + "]", e );
}
throw new ComponentException( role, message, e );
}
// Add a mapping between the component and its handler.
// In the case of a ThreadSafeComponentHandler, the same component will be mapped
// multiple times but because each put will overwrite the last, this is not a