DataSource ds = null;
try {
ds = (DataSource) new InitialContext().lookup(name);
}
catch (NamingException e) {
throw new DataSourceDiscoveryFailedException(e);
}
if (ds == null) {
throw new DataSourceDiscoveryFailedException("Unable to find data source by JNDI name: " + name);
}
return ds;
}