*
* @see org.jboss.dna.graph.connector.RepositorySource#getConnection()
*/
public synchronized RepositoryConnection getConnection() throws RepositorySourceException {
if (getName() == null) {
I18n msg = InfinispanConnectorI18n.propertyIsRequired;
throw new RepositorySourceException(getName(), msg.text("name"));
}
if (this.repository == null) {
Context context = getContext();
if (context == null) {
try {
context = new InitialContext();
} catch (NamingException err) {
throw new RepositorySourceException(name, err);
}
}
// Look for a cache manager in JNDI ...
CacheManager cacheManager = null;
String jndiName = getCacheManagerJndiName();
if (jndiName != null && jndiName.trim().length() != 0) {
Object object = null;
try {
object = context.lookup(jndiName);
if (object != null) cacheManager = (CacheManager)object;
} catch (ClassCastException err) {
I18n msg = InfinispanConnectorI18n.objectFoundInJndiWasNotCacheManager;
String className = object != null ? object.getClass().getName() : "null";
throw new RepositorySourceException(getName(), msg.text(jndiName, this.getName(), className), err);
} catch (Throwable err) {
if (err instanceof RuntimeException) throw (RuntimeException)err;
throw new RepositorySourceException(getName(), err);
}
}