*
* @return a jsr170 repository
* @throws IllegalStateException if the repository is not available in the context.
*/
public static Repository getRepository(ServletContext ctx) {
Repository repository = (Repository) ctx.getAttribute(CTX_ATTR_REPOSITORY);
if (repository != null) {
return repository;
} else {
repository = getRepositoryByRMI(ctx);
}
// try to retrieve via jndi
if (repository == null) {
repository = getRepositoryByJNDI(ctx);
}
// error
if (repository == null) {
log.fatal("The repository is not available. Check config of 'RepositoryAccessServlet'.");
throw new IllegalStateException("The repository is not available.");
} else {
ctx.setAttribute(CTX_ATTR_REPOSITORY, repository);
log.info(repository.getDescriptor(Repository.REP_NAME_DESC) + " v" + repository.getDescriptor(Repository.REP_VERSION_DESC));
return repository;
}
}