Repository nextInChain = repository;
chain.addEntryAtStart(RepositoryDecoratorChain.UNDECORATED_REPOSITORY_KEY, nextInChain);
for (int i = configuredDecorators.size() - 1; i >=0; i--) {
String decoratorName = configuredDecorators.get(i);
RepositoryDecoratorFactory factory = decorators.get(decoratorName);
if (factory == null) {
throw new RuntimeException("No repository decorator registered with the name '" + decoratorName + "'");
}
nextInChain = factory.createInstance(nextInChain);
chain.addEntryAtStart(decoratorName, nextInChain);
}
return chain;
}