// Build the url to access the properties of the implementation artifact
// which is default mechanism dependent.
//
Attributes attributes = loadAttributes( m_cache, m_hosts, implementation );
FactoryDescriptor descriptor = new FactoryDescriptor( attributes );
String factory = descriptor.getFactory();
if( null == factory )
{
final String error =
"Required property 'avalon.artifact.factory' not present in artifact: "
+ implementation + " under the active cache: [" + m_cache + "] using the "
+ "attribute sequence: " + attributes;
throw new IllegalArgumentException( error );
}
//
// Grab all of the dependents in one hit because this is
// the implementation so we can ignore api/spi spread.
//
Artifact[] dependencies = descriptor.getDependencies();
int n = dependencies.length;
URL[] urls = new URL[ n + 1];
for( int i=0; i<n; i++ )
{
urls[i] = LoaderUtils.getResource(
dependencies[i], m_hosts, m_cache, true );
}
urls[ n ] = LoaderUtils.getResource(
implementation, m_hosts, m_cache, true );
//
// create the classloader
//
ClassLoader classloader = new URLClassLoader( urls, parent );
Class clazz = loadFactoryClass( classloader, factory );
//
// load the actual repository implementation
//
try
{
m_delegate = createDelegate( classloader, factory, this );
}
catch( Throwable e )
{
final String error =
"Unable to establish a factory for the supplied artifact:";
StringBuffer buffer = new StringBuffer( error );
buffer.append( "\n artifact: " + implementation );
buffer.append( "\n build: " + descriptor.getBuild() );
buffer.append( "\n factory: " + descriptor.getFactory() );
buffer.append( "\n source: "
+ clazz.getProtectionDomain().getCodeSource().getLocation() );
buffer.append( "\n cache: " + m_cache );
throw new RepositoryException( buffer.toString(), e );
}