ClassRealm realm )
throws ComponentInstantiationException, ComponentLifecycleException
{
String componentFactoryId = componentDescriptor.getComponentFactory();
ComponentFactory componentFactory;
Object component;
try
{
if ( componentFactoryId != null )
{
componentFactory = container.getComponentFactoryManager().findComponentFactory( componentFactoryId );
}
else
{
componentFactory = container.getComponentFactoryManager().getDefaultComponentFactory();
}
ClassRealm componentRealm;
if ( realm == null )
{
componentRealm = container.getComponentRealm( componentDescriptor.getRealmId() );
}
else
{
componentRealm = realm;
}
try
{
component = componentFactory.newInstance( componentDescriptor, componentRealm, container );
}
catch ( AbstractMethodError e )
{
// ----------------------------------------------------------------------------
// For compatibility with old ComponentFactories that use old ClassWorlds
// ----------------------------------------------------------------------------
org.codehaus.classworlds.ClassRealm cr = ClassRealmAdapter.getInstance( componentRealm );
Method method;
try
{
method = componentFactory.getClass().getMethod( "newInstance", new Class[]{
ComponentDescriptor.class, org.codehaus.classworlds.ClassRealm.class, PlexusContainer.class} );
component = method.invoke( componentFactory, new Object[]{componentDescriptor, cr, container} );
}
catch ( Exception mnfe )