{
repConf = (Configuration)hint;
}
catch( final ClassCastException cce )
{
throw new ComponentException( "Hint is of the wrong type. " +
"Must be a Configuration", cce );
}
URL destination = null;
try
{
destination = new URL( repConf.getAttribute( "destinationURL" ) );
}
catch( final ConfigurationException ce )
{
throw new ComponentException( "Malformed configuration has no " +
"destinationURL attribute", ce );
}
catch( final MalformedURLException mue )
{
throw new ComponentException( "destination is malformed. " +
"Must be a valid URL", mue );
}
try
{
final String type = repConf.getAttribute( "type" );
final String repID = destination + type;
Repository reply = (Repository)m_repositories.get( repID );
final String model = (String)repConf.getAttribute( "model" );
if( null != reply )
{
if( m_models.get( repID ).equals( model ) )
{
return reply;
}
else
{
final String message = "There is already another repository with the " +
"same destination and type but with different model";
throw new ComponentException( message );
}
}
else
{
final String protocol = destination.getProtocol();
final String repClass = (String)m_classes.get( protocol + type + model );
getLogger().debug( "Need instance of " + repClass + " to handle: " +
protocol + type + model );
try
{
reply = (Repository)Class.forName( repClass ).newInstance();
setupLogger( reply, "repository" );
ContainerUtil.contextualize(reply, m_context);
ContainerUtil.compose(reply, m_componentManager);
ContainerUtil.service(reply, m_serviceManager);
ContainerUtil.configure(reply, repConf);
ContainerUtil.initialize(reply);
m_repositories.put( repID, reply );
m_models.put( repID, model );
getLogger().info( "New instance of " + repClass + " created for " +
destination );
return reply;
}
catch( final Exception e )
{
final String message = "Cannot find or init repository: " + e.getMessage();
getLogger().warn( message, e );
throw new ComponentException( message, e );
}
}
}
catch( final ConfigurationException ce )
{
throw new ComponentException( "Malformed configuration", ce );
}
}