jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r897836 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/GenericRepositoryFactory.java
Date Mon, 11 Jan 2010 11:14:04 GMT
Author: jukka
Date: Mon Jan 11 11:14:03 2010
New Revision: 897836

URL: http://svn.apache.org/viewvc?rev=897836&view=rev
Log:
JCR-2360: JcrUtils.getRepository(...) for simple repository access

Make the jackrabbit-core RepositoryFactoryImpl interpret file: URIs.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/GenericRepositoryFactory.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java?rev=897836&r1=897835&r2=897836&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java
Mon Jan 11 11:14:03 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.GenericRepositoryFactory;
 
 /**
  * <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(GenericRepositoryFactory.URI)) {
+                Object parameter = parameters.get(GenericRepositoryFactory.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/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=897836&r1=897835&r2=897836&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 11:14:03 2010
@@ -16,10 +16,8 @@
  */
 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;
 
@@ -42,15 +40,9 @@
  *   </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.
+ *     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
@@ -83,71 +75,33 @@
     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);
+            return null; // no default JNDI repository
         } 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();
+            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(URI)) {
+                Object parameter = environment.remove(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
                 }
-                parameters.put("org.apache.jackrabbit.repository.home", home);
-                parameters.put("org.apache.jackrabbit.repository.conf", conf);
             } else {
-                return null;
+                return null; // unknown parameters
             }
-        } 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)
+    private Repository getRepository(String name, Hashtable environment)
             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) {



Mime
View raw message