You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2010/01/11 18:52:12 UTC
svn commit: r897967 - in /jackrabbit/branches/2.0: ./
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/
jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/
jackrabbit-jcr2dav/src/main/java/org/apache/jackrabbit/jcr2dav/
Author: jukka
Date: Mon Jan 11 17:52:12 2010
New Revision: 897967
URL: http://svn.apache.org/viewvc?rev=897967&view=rev
Log:
2.0: Merged revision 896943-897935 (JCR-2360, JCR-2451, JCR-2459, JCR-2460)
Added:
jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JndiRepositoryFactory.java
- copied unchanged from r897935, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JndiRepositoryFactory.java
Modified:
jackrabbit/branches/2.0/ (props changed)
jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java
jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/GenericRepositoryFactory.java
jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
jackrabbit/branches/2.0/jackrabbit-jcr2dav/src/main/java/org/apache/jackrabbit/jcr2dav/Jcr2davRepositoryFactory.java
Propchange: jackrabbit/branches/2.0/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jan 11 17:52:12 2010
@@ -2,4 +2,4 @@
/jackrabbit/sandbox/JCR-1456:774917-886178
/jackrabbit/sandbox/JCR-2170:812417-816332
/jackrabbit/sandbox/tripod-JCR-2209:795441-795863
-/jackrabbit/trunk:891595,891629,892253,892263,894150-894151,896408,896513,896532,896857,896870,896876,896908,896940,896942,896969,896977,897071
+/jackrabbit/trunk:891595,891629,892253,892263,894150-894151,896408,896513,896532,896857,896870,896876,896908,896940,896942-896943,896969,896977,897071,897836,897842,897858,897935
Modified: jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java?rev=897967&r1=897966&r2=897967&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java (original)
+++ jackrabbit/branches/2.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java Mon Jan 11 17:52:12 2010
@@ -16,6 +16,9 @@
*/
package org.apache.jackrabbit.core;
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.HashSet;
import java.util.Map;
import java.util.HashMap;
@@ -27,6 +30,7 @@
import org.apache.jackrabbit.api.JackrabbitRepository;
import org.apache.jackrabbit.api.JackrabbitRepositoryFactory;
import org.apache.jackrabbit.api.management.RepositoryManager;
+import org.apache.jackrabbit.commons.JcrUtils;
/**
* <code>RepositoryFactoryImpl</code> implements a repository factory that
@@ -57,22 +61,41 @@
*/
private final Set<TransientRepository> ownRepositories = new HashSet<TransientRepository>();
+ @SuppressWarnings("unchecked")
public Repository getRepository(Map parameters) throws RepositoryException {
- JackrabbitRepository repo;
synchronized (REPOSITORY_INSTANCES) {
if (parameters == null) {
- repo = getOrCreateRepository(null, null);
+ return getOrCreateRepository(null, null);
} else if (parameters.containsKey(REPOSITORY_CONF)
&& parameters.containsKey(REPOSITORY_HOME)) {
- String conf = (String) parameters.get(REPOSITORY_CONF);
- String home = (String) parameters.get(REPOSITORY_HOME);
- repo = getOrCreateRepository(conf, home);
+ String conf = parameters.get(REPOSITORY_CONF).toString();
+ String home = parameters.get(REPOSITORY_HOME).toString();
+ return getOrCreateRepository(conf, home);
+ } else if (parameters.containsKey(JcrUtils.REPOSITORY_URI)) {
+ Object parameter = parameters.get(JcrUtils.REPOSITORY_URI);
+ try {
+ URI uri = new URI(parameter.toString().trim());
+ if ("file".equalsIgnoreCase(uri.getScheme())) {
+ File file = new File(uri);
+ String home, conf;
+ if (file.isFile()) {
+ home = file.getParentFile().getPath();
+ conf = file.getPath();
+ } else {
+ home = file.getPath();
+ conf = new File(file, "repository.xml").getPath();
+ }
+ return getOrCreateRepository(conf, home);
+ } else {
+ return null; // not a file: URI
+ }
+ } catch (URISyntaxException e) {
+ return null; // not a valid URI
+ }
} else {
- // unknown or insufficient parameters
- repo = null;
+ return null; // unknown or insufficient parameters
}
}
- return repo;
}
/**
Modified: jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/GenericRepositoryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/GenericRepositoryFactory.java?rev=897967&r1=897966&r2=897967&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/GenericRepositoryFactory.java (original)
+++ jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/GenericRepositoryFactory.java Mon Jan 11 17:52:12 2010
@@ -16,153 +16,17 @@
*/
package org.apache.jackrabbit.commons;
-import java.io.File;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Map;
-
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.RepositoryFactory;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
/**
- * Generic JCR repository factory. This factory knows how to handle
- * parameter maps containing the following keys:
- * <dl>
- * <dt>{@link #JNDI_NAME org.apache.jackrabbit.repository.jndi.name}</dt>
- * <dd>
- * The repository instance is looked up from JNDI.
- * An {@link InitialContext initial JNDI context} is constructed using
- * all the other parameters, and a repository at the given name is
- * looked up from the instantiated context.
- * </dd>
- * <dt>{@link #URI org.apache.jackrabbit.repository.uri}</dt>
- * <dd>
- * Connects to the given repository URI.
- * See {@link JcrUtils#getRepository(String)} for the supported URI types.
- * Note that this class does not directly implement all these connection
- * mechanisms. Instead it maps the given repository URI to known
- * {@link RepositoryFactory} parameters and uses the Java Service
- * Provider mechanism to recursively ask all the available repository
- * factories to handle the resulting connection parameters. All the other
- * parameters except the repository URI from the original invocation are
- * also passed on to these recursive calls.
- * </dd>
- * </dl>
- * Clients should normally only use this class through the Java Service
- * Provider mechanism. See the getRepository utility methods in
- * {@link JcrUtils} for an easy way to do that.
- *
- * @since Apache Jackrabbit 2.0
+ * Renamed to {@link JndiRepositoryFactory}. This class will be removed
+ * in Jackrabbit 2.0. Please use the {@link JcrUtils#REPOSITORY_URI} constant
+ * instead of the {@link #URI} constant in this class.
*/
-@SuppressWarnings("unchecked")
-public class GenericRepositoryFactory implements RepositoryFactory {
-
- /**
- * The repository URI parameter name.
- */
- public static final String URI =
- "org.apache.jackrabbit.repository.uri";
+@Deprecated
+public class GenericRepositoryFactory extends JndiRepositoryFactory {
/**
- * The JNDI name parameter name.
+ * Please use {@link JcrUtils#REPOSITORY_URI} instead.
*/
- public static final String JNDI_NAME =
- "org.apache.jackrabbit.repository.jndi.name";
-
- /**
- * Handles the generic repository parameters mentioned in the
- * description of this class. Returns <code>null</code> if none of
- * the described parameters are given or if the given parameter map is
- * <code>null</code>.
- */
- public Repository getRepository(Map parameters)
- throws RepositoryException {
- if (parameters == null) {
- return null;
- } else if (parameters.containsKey(URI)) {
- return getUriRepository(parameters);
- } else if (parameters.containsKey(JNDI_NAME)) {
- return getJndiRepository(parameters);
- } else {
- return null;
- }
- }
-
- /**
- * Implements the repository URI connection as documented in the
- * description of this class.
- *
- * @param original original repository parameters, including {@link #URI}
- * @return repository instance
- * @throws RepositoryException if the repository can not be accessed,
- * or if the URI is invalid or unknown
- */
- private Repository getUriRepository(Map original)
- throws RepositoryException {
- Map parameters = new HashMap(original);
- String parameter = parameters.remove(URI).toString().trim();
-
- try {
- URI uri = new URI(parameter);
- String scheme = uri.getScheme();
- if ("jndi".equalsIgnoreCase(scheme)) {
- parameters.put(JNDI_NAME, uri.getSchemeSpecificPart());
- } else if ("file".equalsIgnoreCase(scheme)) {
- File file = new File(uri);
- String home, conf;
- if (file.isFile()) {
- home = file.getParentFile().getPath();
- conf = file.getPath();
- } else {
- home = file.getPath();
- conf = new File(file, "repository.xml").getPath();
- }
- parameters.put("org.apache.jackrabbit.repository.home", home);
- parameters.put("org.apache.jackrabbit.repository.conf", conf);
- } else {
- return null;
- }
- } catch (URISyntaxException e) {
- return null;
- }
-
- return JcrUtils.getRepository(parameters);
- }
-
- /**
- * Implements the JNDI lookup as documented in the description of
- * this class.
- *
- * @param parameters repository parameters, including {@link #JNDI_NAME}
- * @return the repository instance from JNDI
- * @throws RepositoryException if the name is not found in JNDI
- * or does not point to a repository instance
- */
- private Repository getJndiRepository(Map parameters)
- throws RepositoryException {
- Hashtable environment = new Hashtable(parameters);
- String name = environment.remove(JNDI_NAME).toString();
-
- try {
- Object value = new InitialContext(environment).lookup(name);
- if (value instanceof Repository) {
- return (Repository) value;
- } else {
- throw new RepositoryException(
- "Invalid repository object " + value
- + " found at " + name + " in JNDI environment "
- + environment);
- }
- } catch (NamingException e) {
- throw new RepositoryException(
- "Failed to look up " + name
- + " from JNDI environment " + environment, e);
- }
- }
+ public static final String URI = JcrUtils.REPOSITORY_URI;
}
Modified: jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java?rev=897967&r1=897966&r2=897967&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java (original)
+++ jackrabbit/branches/2.0/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java Mon Jan 11 17:52:12 2010
@@ -51,6 +51,21 @@
public class JcrUtils {
/**
+ * The repository URI parameter name used by the
+ * {@link #getRepository(String)} method. All {@link RepositoryFactory}
+ * implementations that want to support this repository access convention
+ * should implement processing of this parameter.
+ * <p>
+ * Client applications are recommended to use the
+ * {@link #getRepository(String)} method instead of directly referencing
+ * this constant unless they explicitly want to pass also other
+ * {@link RepositoryFactory} parameters through the
+ * {@link #getRepository(Map)} method.
+ */
+ public static final String REPOSITORY_URI =
+ "org.apache.jackrabbit.repository.uri";
+
+ /**
* Private constructor to prevent instantiation of this class.
*/
private JcrUtils() {
@@ -87,38 +102,74 @@
*/
public static Repository getRepository(Map<String, String> parameters)
throws RepositoryException {
+ String newline = System.getProperty("line.separator");
+
+ // Prepare the potential error message (JCR-2459)
+ StringBuilder log = new StringBuilder("Unable to access a repository");
+ if (parameters != null) {
+ log.append(" with the following settings:");
+ for (Map.Entry<String, String> entry : parameters.entrySet()) {
+ log.append(newline);
+ log.append(" ");
+ log.append(entry.getKey());
+ log.append(": ");
+ log.append(entry.getValue());
+ }
+ } else {
+ log.append(" with the default settings.");
+ }
+
+ // Iterate through the available RepositoryFactories, with logging
+ log.append(newline);
+ log.append("The following RepositoryFactory classes were consulted:");
Iterator<RepositoryFactory> iterator =
ServiceRegistry.lookupProviders(RepositoryFactory.class);
-
while (iterator.hasNext()) {
RepositoryFactory factory = iterator.next();
- Repository repository = factory.getRepository(parameters);
- if (repository != null) {
- return repository;
+ log.append(newline);
+ log.append(" ");
+ log.append(factory.getClass().getName());
+ try {
+ Repository repository = factory.getRepository(parameters);
+ if (repository != null) {
+ // We found the requested repository! Return it
+ // and just ignore the error message being built.
+ return repository;
+ } else {
+ log.append(": declined");
+ }
+ } catch (Exception e) {
+ log.append(": ");
+ log.append(e.getMessage());
}
}
- throw new RepositoryException(
- "No repository factory can handle the given configuration: "
- + parameters);
+ // No matching repository found. Throw an exception with the
+ // detailed information we gathered during the above process.
+ throw new RepositoryException(log.toString());
}
/**
- * Returns the repository identified by the given URI. The following
- * URI types are currently supported:
+ * Returns the repository identified by the given URI. See the
+ * documentation of the repository implementation you want to use for
+ * whether it supports this repository URI convention and for what
+ * the repository URI should look like. For example, Jackrabbit 2.0
+ * supports the following types of repository URIs:
* <dl>
* <dt>http(s)://...</dt>
* <dd>
* A remote repository connection using SPI2DAVex with the given URL.
+ * See the jackrabbit-jcr2dav component for more details.
* </dd>
* <dt>file://...</dt>
* <dd>
* An embedded Jackrabbit repository located in the given directory.
+ * See the jackrabbit-core component for more details.
* </dd>
* <dt>jndi:...</dt>
* <dd>
- * JNDI lookup for the named repository. See the JNDI support
- * described above.
+ * JNDI lookup for the named repository. See the
+ * {@link JndiRepositoryFactory} class for more details.
* </dd>
* </dl>
*
@@ -130,8 +181,8 @@
public static Repository getRepository(String uri)
throws RepositoryException {
Map<String, String> parameters = new HashMap<String, String>();
- parameters.put(GenericRepositoryFactory.URI, uri);
- return new GenericRepositoryFactory().getRepository(parameters);
+ parameters.put(JcrUtils.REPOSITORY_URI, uri);
+ return getRepository(parameters);
}
/**
Modified: jackrabbit/branches/2.0/jackrabbit-jcr2dav/src/main/java/org/apache/jackrabbit/jcr2dav/Jcr2davRepositoryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.0/jackrabbit-jcr2dav/src/main/java/org/apache/jackrabbit/jcr2dav/Jcr2davRepositoryFactory.java?rev=897967&r1=897966&r2=897967&view=diff
==============================================================================
--- jackrabbit/branches/2.0/jackrabbit-jcr2dav/src/main/java/org/apache/jackrabbit/jcr2dav/Jcr2davRepositoryFactory.java (original)
+++ jackrabbit/branches/2.0/jackrabbit-jcr2dav/src/main/java/org/apache/jackrabbit/jcr2dav/Jcr2davRepositoryFactory.java Mon Jan 11 17:52:12 2010
@@ -26,6 +26,7 @@
import javax.jcr.RepositoryFactory;
import org.apache.jackrabbit.commons.GenericRepositoryFactory;
+import org.apache.jackrabbit.commons.JcrUtils;
import org.apache.jackrabbit.jcr2spi.RepositoryImpl;
import org.apache.jackrabbit.jcr2spi.Jcr2spiRepositoryFactory;
import org.apache.jackrabbit.spi.RepositoryServiceFactory;
@@ -64,9 +65,6 @@
private static final String DAVEX_URI =
Spi2davexRepositoryServiceFactory.PARAM_REPOSITORY_URI;
- private static final String GENERIC_URI =
- GenericRepositoryFactory.URI;
-
public Repository getRepository(Map parameters) throws RepositoryException {
if (parameters == null) {
return null;
@@ -76,9 +74,9 @@
} else if (parameters.containsKey(DAVEX_URI)) {
return getRepository(
new Spi2davexRepositoryServiceFactory(), parameters);
- } else if (parameters.containsKey(GENERIC_URI)) {
+ } else if (parameters.containsKey(JcrUtils.REPOSITORY_URI)) {
Map copy = new HashMap(parameters);
- Object parameter = copy.remove(GENERIC_URI);
+ Object parameter = copy.remove(JcrUtils.REPOSITORY_URI);
try {
URI uri = new URI(parameter.toString().trim());
String scheme = uri.getScheme();