code.onehippo.org is currently readonly. We are migrating to code.bloomreach.com, please continue working there on Monday 14/12. See: https://docs.bloomreach.com/display/engineering/GitLab

Commit a70298c4 authored by Ate Douma's avatar Ate Douma

REPO-1881: [Backport 11.2] load HippoEnterpriseRepository instead of...

REPO-1881: [Backport 11.2] load HippoEnterpriseRepository instead of LocalHippoRepository, if available

  (cherry picked from commit b07f4308)
  (cherry picked from commit 6c3b3782)
  (cherry picked from commit 79148a61)
parent b05161a4
/*
* Copyright 2009-2013 Hippo B.V. (http://www.onehippo.com)
* Copyright 2009-2017 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -17,7 +17,6 @@ package org.hippoecm.repository;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
......@@ -31,6 +30,18 @@ public class HippoRepositoryFactory {
private static String defaultLocation = null; // FIXME: should become: "java:comp/env/jcr/repository";
private static HippoRepository defaultRepository = null;
private static Class localRepositoryClass = null;
private static Class getLocalHippoRepositoryClass() throws ClassNotFoundException {
if (localRepositoryClass == null) {
try {
localRepositoryClass = Class.forName("com.onehippo.repository.HippoEnterpriseRepository");
} catch (ClassNotFoundException e) {
localRepositoryClass = Class.forName("org.hippoecm.repository.LocalHippoRepository");
}
}
return localRepositoryClass;
}
private HippoRepositoryFactory() {
}
......@@ -71,8 +82,7 @@ public class HippoRepositoryFactory {
}
try {
Class cls = Class.forName("org.hippoecm.repository.LocalHippoRepository");
defaultRepository = (HippoRepository) cls.getMethod("create", new Class[] { String.class } ).invoke(null, (String)null);
defaultRepository = (HippoRepository) getLocalHippoRepositoryClass().getMethod("create", new Class[] { String.class } ).invoke(null, (String)null);
} catch(NoSuchMethodException ex) {
throw new RepositoryException(ex);
} catch(InvocationTargetException ex) {
......@@ -128,54 +138,13 @@ public class HippoRepositoryFactory {
}
}
if(location.startsWith("bootstrap:")) {
try {
location = location.substring("bootstrap:".length());
return (HippoRepository) Class.forName("org.hippoecm.repository.BootstrapHippoRepository").getMethod("create", new Class[] { String.class }).invoke(null, new Object[] { location });
} catch(ClassNotFoundException ex) {
throw new RepositoryException(ex);
} catch(NoSuchMethodException ex) {
throw new RepositoryException(ex);
} catch(IllegalAccessException ex) {
throw new RepositoryException(ex);
} catch(InvocationTargetException ex) {
if (ex.getCause() instanceof RepositoryException) {
throw (RepositoryException) ex.getCause();
} else if (ex.getCause() instanceof IllegalArgumentException) {
throw new RepositoryException("Invalid data: " + ex.getCause());
} else {
throw new RepositoryException("unchecked exception: " + ex.getMessage());
}
}
}
if(location.startsWith("vm:")) {
return VMHippoRepository.create(location);
}
if(location.startsWith("proxy:")) {
try {
return (HippoRepository) Class.forName("org.hippoecm.repository.proxyrepository.ProxyHippoRepository").getMethod("create", new Class[] { String.class }).invoke(null, new Object[] { location });
} catch(ClassNotFoundException ex) {
throw new RepositoryException(ex);
} catch(NoSuchMethodException ex) {
throw new RepositoryException(ex);
} catch(IllegalAccessException ex) {
throw new RepositoryException(ex);
} catch(InvocationTargetException ex) {
if (ex.getCause() instanceof RepositoryException) {
throw (RepositoryException) ex.getCause();
} else if (ex.getCause() instanceof IllegalArgumentException) {
throw new RepositoryException("Invalid data: " + ex.getCause());
} else {
throw new RepositoryException("unchecked exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
}
}
}
// embedded/local with location
try {
repository = (HippoRepository) Class.forName("org.hippoecm.repository.LocalHippoRepository").getMethod("create", new Class[] { String.class }).invoke(null, new Object[] { location });
repository = (HippoRepository) getLocalHippoRepositoryClass().getMethod("create", new Class[] { String.class }).invoke(null, new Object[] { location });
} catch(ClassNotFoundException ex) {
throw new RepositoryException(ex);
} catch(NoSuchMethodException ex) {
......@@ -183,22 +152,30 @@ public class HippoRepositoryFactory {
} catch(IllegalAccessException ex) {
throw new RepositoryException(ex);
} catch(InvocationTargetException ex) {
if (ex.getCause() instanceof RepositoryException) {
throw (RepositoryException) ex.getCause();
} else if (ex.getCause() instanceof IllegalArgumentException) {
throw new RepositoryException("Invalid data: " + ex.getCause(), ex);
final Throwable cause = unwindInvocationTargetException(ex);
if (cause instanceof RepositoryException) {
throw (RepositoryException) cause;
} else if (cause instanceof IllegalArgumentException) {
throw new RepositoryException("Invalid data: " + cause, cause);
} else {
throw new RepositoryException("unchecked exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
throw new RepositoryException("unchecked exception: " + cause.getClass().getName() + ": " + cause.getMessage(), cause);
}
}
return repository;
}
private static Throwable unwindInvocationTargetException(final InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause != null && cause instanceof InvocationTargetException) {
return unwindInvocationTargetException((InvocationTargetException)cause);
}
return cause == null ? e : cause;
}
static void unregister(HippoRepository repository) {
if (repository == defaultRepository) {
defaultRepository = null;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment