in src/main/java/org/apache/sling/datasource/internal/JNDIDataSourceFactory.java [113:136]
private DataSource lookupDataSource(String jndiName, Map<String, ?> config) throws NamingException {
Properties jndiProps = createJndiEnv(config);
Context context = null;
try {
log.debug("Looking up DataSource [{}] with InitialContext env [{}]", jndiName, jndiProps);
context = new InitialContext(jndiProps);
Object lookup = context.lookup(jndiName);
if (lookup == null) {
throw new NameNotFoundException("JNDI object with [" + jndiName + "] not found");
}
if (!DataSource.class.isInstance(lookup)) {
throw new IllegalStateException("JNDI object of type " + lookup.getClass() +
"is not an instance of javax.sql.DataSource");
}
return (DataSource) lookup;
} finally {
if (context != null) {
context.close();
}
}
}