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 17:51:01 UTC
svn commit: r897935 - in
/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons:
GenericRepositoryFactory.java JcrUtils.java JndiRepositoryFactory.java
Author: jukka
Date: Mon Jan 11 16:51:01 2010
New Revision: 897935
URL: http://svn.apache.org/viewvc?rev=897935&view=rev
Log:
JCR-2460: Rename GenericRepositoryFactory to JndiRepositoryFactory
Added:
jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JndiRepositoryFactory.java
- copied, changed from r897874, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/GenericRepositoryFactory.java
Modified:
jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/GenericRepositoryFactory.java
jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/GenericRepositoryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/GenericRepositoryFactory.java?rev=897935&r1=897934&r2=897935&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/GenericRepositoryFactory.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/GenericRepositoryFactory.java Mon Jan 11 16:51:01 2010
@@ -16,107 +16,17 @@
*/
package org.apache.jackrabbit.commons;
-import java.net.URI;
-import java.net.URISyntaxException;
-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 repository at the given jndi: URI.
- * 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 {
+@Deprecated
+public class GenericRepositoryFactory extends JndiRepositoryFactory {
/**
- * The repository URI parameter name.
+ * Please use {@link JcrUtils#REPOSITORY_URI} instead.
*/
- @Deprecated
public static final String URI = JcrUtils.REPOSITORY_URI;
- /**
- * The JNDI name parameter name.
- */
- 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; // no default JNDI repository
- } else {
- Hashtable environment = new Hashtable(parameters);
- if (environment.containsKey(JNDI_NAME)) {
- String name = environment.remove(JNDI_NAME).toString();
- return getRepository(name, environment);
- } else if (environment.containsKey(JcrUtils.REPOSITORY_URI)) {
- Object parameter = environment.remove(JcrUtils.REPOSITORY_URI);
- try {
- URI uri = new URI(parameter.toString().trim());
- if ("jndi".equalsIgnoreCase(uri.getScheme())) {
- String name = uri.getSchemeSpecificPart();
- return getRepository(name, environment);
- } else {
- return null; // not a jndi: URI
- }
- } catch (URISyntaxException e) {
- return null; // not a valid URI
- }
- } else {
- return null; // unknown parameters
- }
- }
- }
-
- private Repository getRepository(String name, Hashtable environment)
- throws RepositoryException {
- 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);
- }
- }
-
}
Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java?rev=897935&r1=897934&r2=897935&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java Mon Jan 11 16:51:01 2010
@@ -55,6 +55,12 @@
* {@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";
@@ -144,21 +150,26 @@
}
/**
- * 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>
*
Copied: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JndiRepositoryFactory.java (from r897874, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/GenericRepositoryFactory.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JndiRepositoryFactory.java?p2=jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JndiRepositoryFactory.java&p1=jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/GenericRepositoryFactory.java&r1=897874&r2=897935&rev=897935&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/GenericRepositoryFactory.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JndiRepositoryFactory.java Mon Jan 11 16:51:01 2010
@@ -28,23 +28,24 @@
import javax.naming.NamingException;
/**
- * Generic JCR repository factory. This factory knows how to handle
- * parameter maps containing the following keys:
+ * JNDI-based JCR repository factory. This factory looks up {@link Repository}
+ * instances from JNDI directories based on the following parameters:
* <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.
+ * The value of this parameter is used as a JNDI name for looking
+ * up the repository.
* </dd>
- * <dt>{@link #URI org.apache.jackrabbit.repository.uri}</dt>
+ * <dt>{@link JcrUtils#REPOSITORY_URI org.apache.jackrabbit.repository.uri}</dt>
* <dd>
- * Connects to the repository at the given jndi: URI.
- * All the other parameters except the repository URI from the original
- * invocation are also passed on to these recursive calls.
+ * If the URI scheme is "jndi", then the remainder of the URI is used
+ * as a JNDI name for looking up the repository.
* </dd>
* </dl>
+ * <p>
+ * All the other repository parameters are passed as the environment of the
+ * {@link InitialContext initial JNDI context}.
+ * <p>
* 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.
@@ -52,13 +53,7 @@
* @since Apache Jackrabbit 2.0
*/
@SuppressWarnings("unchecked")
-public class GenericRepositoryFactory implements RepositoryFactory {
-
- /**
- * The repository URI parameter name.
- */
- @Deprecated
- public static final String URI = JcrUtils.REPOSITORY_URI;
+public class JndiRepositoryFactory implements RepositoryFactory {
/**
* The JNDI name parameter name.
@@ -66,12 +61,6 @@
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) {