private Repository createRepositoryStack(RepositoryImplConfig config)
throws RepositoryConfigException
{
RepositoryFactory factory = RepositoryRegistry.getInstance().get(config.getType());
if (factory == null) {
throw new RepositoryConfigException("Unsupported repository type: " + config.getType());
}
Repository repository = factory.getRepository(config);
if (config instanceof DelegatingRepositoryImplConfig) {
RepositoryImplConfig delegateConfig = ((DelegatingRepositoryImplConfig)config).getDelegate();
Repository delegate = createRepositoryStack(delegateConfig);
try {
((DelegatingRepository)repository).setDelegate(delegate);
}
catch (ClassCastException e) {
throw new RepositoryConfigException(
"Delegate specified for repository that is not a DelegatingRepository: "
+ delegate.getClass());
}
}