jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r923653 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: RepositoryFactoryImpl.java TransientRepository.java config/RepositoryConfig.java config/RepositoryConfigurationParser.java
Date Tue, 16 Mar 2010 09:53:08 GMT
Author: jukka
Date: Tue Mar 16 09:53:08 2010
New Revision: 923653

URL: http://svn.apache.org/viewvc?rev=923653&view=rev
Log:
JCR-2569: Implement jcr-jackrabbit://... repository URIs

Pass repository parameters from RepositoryFactoryImpl to RepositoryConfigurationParser

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryFactoryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.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=923653&r1=923652&r2=923653&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
Tue Mar 16 09:53:08 2010
@@ -17,11 +17,13 @@
 package org.apache.jackrabbit.core;
 
 import java.io.File;
+import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.HashMap;
+import java.util.Properties;
 import java.util.Set;
 
 import javax.jcr.Repository;
@@ -31,6 +33,7 @@ import org.apache.jackrabbit.api.Jackrab
 import org.apache.jackrabbit.api.JackrabbitRepositoryFactory;
 import org.apache.jackrabbit.api.management.RepositoryManager;
 import org.apache.jackrabbit.commons.JcrUtils;
+import org.apache.jackrabbit.core.config.RepositoryConfigurationParser;
 
 /**
  * <code>RepositoryFactoryImpl</code> implements a repository factory that
@@ -65,12 +68,12 @@ public class RepositoryFactoryImpl imple
     public Repository getRepository(Map parameters) throws RepositoryException {
         synchronized (REPOSITORY_INSTANCES) {
             if (parameters == null) {
-                return getOrCreateRepository(null, null);
+                return getOrCreateRepository(null, null, parameters);
             } else if (parameters.containsKey(REPOSITORY_CONF)
                     && parameters.containsKey(REPOSITORY_HOME)) {
                 String conf = parameters.get(REPOSITORY_CONF).toString();
                 String home = parameters.get(REPOSITORY_HOME).toString();
-                return getOrCreateRepository(conf, home);
+                return getOrCreateRepository(conf, home, parameters);
             } else if (parameters.containsKey(JcrUtils.REPOSITORY_URI)) {
                 Object parameter = parameters.get(JcrUtils.REPOSITORY_URI);
                 try {
@@ -85,7 +88,7 @@ public class RepositoryFactoryImpl imple
                             home = file.getPath();
                             conf = new File(file, "repository.xml").getPath();
                         }
-                        return getOrCreateRepository(conf, home);
+                        return getOrCreateRepository(conf, home, parameters);
                     } else {
                         return null; // not a file: URI
                     }
@@ -108,22 +111,49 @@ public class RepositoryFactoryImpl imple
      * @throws RepositoryException if an error occurs while creating the
      *          repository instance.
      */
-    private JackrabbitRepository getOrCreateRepository(String conf,
-                                                       String home)
+    private JackrabbitRepository getOrCreateRepository(
+            String conf, String home, Map<?, ?> parameters)
             throws RepositoryException {
         JackrabbitRepository repo = REPOSITORY_INSTANCES.get(home);
         if (repo == null) {
-            TransientRepository tr;
-            if (home == null) {
-                tr = new TransientRepository();
-                // also remember this instance as the default repository
-                REPOSITORY_INSTANCES.put(null, tr);
-            } else {
-                tr = new TransientRepository(conf, home);
+            // Prepare the repository properties
+            Properties properties = new Properties(System.getProperties());
+            for (Map.Entry<?, ?> entry : parameters.entrySet()) {
+                Object key = entry.getKey();
+                if (key != null) {
+                    Object value = entry.getValue();
+                    if (value != null) {
+                        properties.setProperty(
+                                key.toString(), value.toString());
+                    } else {
+                        properties.remove(key.toString());
+                    }
+                }
+            }
+
+            properties.put(
+                    RepositoryConfigurationParser.REPOSITORY_CONF_VARIABLE,
+                    conf);
+            properties.put(
+                    RepositoryConfigurationParser.REPOSITORY_HOME_VARIABLE,
+                    home);
+
+            try {
+                TransientRepository tr;
+                if (home == null) {
+                    tr = new TransientRepository(properties);
+                    // also remember this instance as the default repository
+                    REPOSITORY_INSTANCES.put(null, tr);
+                } else {
+                    tr = new TransientRepository(properties);
+                }
+                REPOSITORY_INSTANCES.put(tr.getHomeDir(), tr);
+                ownRepositories.add(tr);
+                repo = tr;
+            } catch (IOException e) {
+                throw new RepositoryException(
+                        "Failed to install repository configuration", e);
             }
-            REPOSITORY_INSTANCES.put(tr.getHomeDir(), tr);
-            ownRepositories.add(tr);
-            repo = tr;
         }
         return repo;
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java?rev=923653&r1=923652&r2=923653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java
Tue Mar 16 09:53:08 2010
@@ -241,6 +241,11 @@ public class TransientRepository extends
         }, dir.getAbsolutePath());
     }
 
+    public TransientRepository(Properties properties)
+            throws ConfigurationException, IOException {
+        this(RepositoryConfig.install(properties));
+    }
+
     /**
      * @return the path to the repository home directory.
      */

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java?rev=923653&r1=923652&r2=923653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
Tue Mar 16 09:53:08 2010
@@ -16,7 +16,11 @@
  */
 package org.apache.jackrabbit.core.config;
 
+import static org.apache.jackrabbit.core.config.RepositoryConfigurationParser.REPOSITORY_CONF_VARIABLE;
+import static org.apache.jackrabbit.core.config.RepositoryConfigurationParser.REPOSITORY_HOME_VARIABLE;
+
 import org.apache.commons.io.IOUtils; 
+import org.apache.jackrabbit.core.RepositoryFactoryImpl;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.core.data.DataStoreFactory;
@@ -105,6 +109,45 @@ public class RepositoryConfig
     }
 
     /**
+     * Returns the configuration of a repository with the home directory,
+     * configuration file, and other options as specified in the given
+     * configuration parser variables. 
+     * <p>
+     * The directory is created if it does not exist. If the repository
+     * configuration file does not exist, then it is created using the
+     * default Jackrabbit configuration settings.
+     *
+     * @since Apache Jackrabbit 2.1
+     * @param variables parser variables
+     * @return repository configuration
+     * @throws ConfigurationException on configuration errors
+     */
+    public static RepositoryConfig install(Properties variables)
+            throws IOException, ConfigurationException {
+        Properties copy = new Properties(variables);
+
+        String home = copy.getProperty(REPOSITORY_HOME_VARIABLE);
+        if (home == null) {
+            home = copy.getProperty(
+                    RepositoryFactoryImpl.REPOSITORY_HOME, "jackrabbit");
+            copy.setProperty(REPOSITORY_HOME_VARIABLE, home);
+        }
+        File dir = new File(home);
+
+        String conf = copy.getProperty(REPOSITORY_CONF_VARIABLE);
+        if (conf == null) {
+            conf = copy.getProperty(RepositoryFactoryImpl.REPOSITORY_CONF);
+        }
+        if (conf == null) {
+            conf = new File(dir, REPOSITORY_XML).getPath();
+        }
+        File xml = new File(conf);
+
+        installRepositorySkeleton(xml, dir);
+        return create(new InputSource(xml.toURI().toString()), copy);
+    }
+
+    /**
      * Returns the configuration of a repository with the given configuration
      * file and repository home directory.
      * <p>
@@ -119,6 +162,12 @@ public class RepositoryConfig
      */
     public static RepositoryConfig install(File xml, File dir)
             throws IOException, ConfigurationException {
+        installRepositorySkeleton(xml, dir);
+        return create(xml, dir);
+    }
+
+    private static void installRepositorySkeleton(File xml, File dir)
+            throws IOException {
         if (!dir.exists()) {
             log.info("Creating repository directory {}", dir);
             dir.mkdirs();
@@ -139,8 +188,6 @@ public class RepositoryConfig
                 output.close();
             }
         }
-
-        return create(xml, dir);
     }
 
     /**
@@ -238,25 +285,41 @@ public class RepositoryConfig
     }
 
     /**
-     * Parses the given repository configuration document and returns the
-     * parsed and initialized repository configuration. The given repository
-     * home directory path will be used as the ${rep.home} parser variable.
+     * Convenience method that invokes the
+     * {@link #create(InputSource, Properties)} method with the given
+     * repository home home directory path set as the ${rep.home} parser
+     * variable. Also all system properties are used as parser variables.
+     *
+     * @param xml repository configuration document
+     * @param home repository home directory
+     * @return repository configuration
+     * @throws ConfigurationException on configuration errors
+     */
+    public static RepositoryConfig create(InputSource xml, String home)
+            throws ConfigurationException {
+        Properties variables = new Properties(System.getProperties());
+        variables.setProperty(REPOSITORY_HOME_VARIABLE, home);
+        return create(xml, variables);
+    }
+
+    /**
+     * Parses the given repository configuration document using the given
+     * parser variables. Note that the ${rep.home} variable should be set
+     * by the caller!
      * <p>
      * Note that in addition to parsing the repository configuration, this
      * method also initializes the configuration (creates the configured
      * directories, etc.). The {@link ConfigurationParser} class should be
      * used directly to just parse the configuration.
      *
+     * @since Apache Jackrabbit 2.1
      * @param xml repository configuration document
-     * @param home repository home directory
+     * @param variables parser variables
      * @return repository configuration
      * @throws ConfigurationException on configuration errors
      */
-    public static RepositoryConfig create(InputSource xml, String home)
+    public static RepositoryConfig create(InputSource xml, Properties variables)
             throws ConfigurationException {
-        Properties variables = new Properties(System.getProperties());
-        variables.setProperty(
-                RepositoryConfigurationParser.REPOSITORY_HOME_VARIABLE, home);
         RepositoryConfigurationParser parser =
             new RepositoryConfigurationParser(variables, new ConnectionFactory());
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java?rev=923653&r1=923652&r2=923653&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
Tue Mar 16 09:53:08 2010
@@ -74,6 +74,9 @@ public class RepositoryConfigurationPars
     /** Name of the repository home directory parser variable. */
     public static final String REPOSITORY_HOME_VARIABLE = "rep.home";
 
+    /** Name of the repository configuration file parser variable. */
+    public static final String REPOSITORY_CONF_VARIABLE = "rep.conf";
+
     /** Name of the workspace home directory parser variable. */
     public static final String WORKSPACE_HOME_VARIABLE = "wsp.home";
 



Mime
View raw message