jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r156418 - in incubator/jackrabbit/trunk/src: java/org/apache/jackrabbit/core/config/ test/org/apache/jackrabbit/core/config/
Date Mon, 07 Mar 2005 12:26:05 GMT
Author: jukka
Date: Mon Mar  7 04:26:02 2005
New Revision: 156418

URL: http://svn.apache.org/viewcvs?view=rev&rev=156418
Log:
Refactoring step 7 (JCR-53)
 - Added the new FileSystemConfig object
 - Added an init() step to keep the constructors and parsing code simple
 - Moved file handling and workspace creation back to RepositoryConfig
 - Added and improved lots of javadocs
 - Fixed property problems (new Property(p) != (Property) p.clone())
 - Many minor changes

Added:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/FileSystemConfig.java
Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/BeanConfig.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationParser.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/SearchConfig.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/VersioningConfig.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/RepositoryConfigTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/BeanConfig.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/BeanConfig.java?view=diff&r1=156417&r2=156418
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/BeanConfig.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/BeanConfig.java Mon Mar  7 04:26:02 2005
@@ -49,7 +49,7 @@
      */
     protected BeanConfig(String className, Properties properties) {
         this.className = className;
-        this.properties = new Properties(properties);
+        this.properties = (Properties) properties.clone();
     }
 
     /**
@@ -83,24 +83,34 @@
      * Creates a new instance of the configured bean class.
      *
      * @return new bean instance
-     * @throws ClassNotFoundException if the bean class is not found
-     * @throws InstantiationException if the bean could not be instantiated
-     * @throws IllegalAccessException if the bean methods are protected
+     * @throws ConfigurationException on bean configuration errors
      */
-    public Object newInstance()
-            throws ClassNotFoundException, InstantiationException,
-            IllegalAccessException {
-        Object object = Class.forName(className).newInstance();
-        BeanMap map = new BeanMap(object);
-        Iterator iterator = map.keyIterator();
-        while (iterator.hasNext()) {
-            String name = (String) iterator.next();
-            String value = properties.getProperty(name);
-            if (value != null) {
-                map.put(name, properties.getProperty(name));
+    public Object newInstance() throws ConfigurationException {
+        try {
+            Object object = Class.forName(getClassName()).newInstance();
+            BeanMap map = new BeanMap(object);
+            Iterator iterator = map.keyIterator();
+            while (iterator.hasNext()) {
+                String name = (String) iterator.next();
+                String value = properties.getProperty(name);
+                if (value != null) {
+                    map.put(name, properties.getProperty(name));
+                }
             }
+            return object;
+        } catch (ClassNotFoundException e) {
+            throw new ConfigurationException(
+                    "Configured bean implementation class " + getClassName()
+                    + " was not found.", e);
+        } catch (InstantiationException e) {
+            throw new ConfigurationException(
+                    "Configured bean implementation class " + getClassName()
+                    + " can not be instantiated.", e);
+        } catch (IllegalAccessException e) {
+            throw new ConfigurationException(
+                    "Configured bean implementation class " + getClassName()
+                    + " is protected.", e);
         }
-        return object;
     }
 
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationParser.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationParser.java?view=diff&r1=156417&r2=156418
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationParser.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/ConfigurationParser.java Mon Mar  7 04:26:02 2005
@@ -17,270 +17,185 @@
 package org.apache.jackrabbit.core.config;
 
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileReader;
 import java.io.IOException;
-import java.util.HashMap;
 import java.util.Iterator;
-import java.util.Map;
 import java.util.Properties;
 
-import javax.jcr.RepositoryException;
-
-import org.apache.jackrabbit.core.fs.FileSystem;
-import org.apache.jackrabbit.core.fs.FileSystemException;
-import org.apache.log4j.Logger;
 import org.jdom.Document;
 import org.jdom.Element;
 import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
-import org.jdom.output.Format;
-import org.jdom.output.XMLOutputter;
 import org.xml.sax.InputSource;
 
 /**
- * TODO
+ * Configuration parser. This class is used to parse the repository and
+ * workspace configuration files. Each configuration parser instance
+ * contains a set of parser variables that are used for variable replacement
+ * in the configuration file.
+ * <p>
+ * The following code sample outlines the usage of this class:
+ * <pre>
+ *     Properties variables = ...; // parser variables
+ *     ConfigurationParser parser = new ConfigurationParser(variables);
+ *     RepositoryConfig rc = parser.parseRepositoryConfig(...);
+ *     WorkspaceConfig wc = parser.parseWorkspaceConfig(...);
+ * </pre>
  */
 public class ConfigurationParser {
 
-    private static Logger log = Logger.getLogger(ConfigurationParser.class);
+    /** Name of the repository home directory parser variable. */
+    public static final String REPOSITORY_HOME_VARIABLE = "rep.home";
+
+    /** Name of the workspace home directory parser variable. */
+    public static final String WORKSPACE_HOME_VARIABLE = "wsp.home";
+
+    /** Name of the repository name parser variable. */
+    private static final String WORKSPACE_NAME_VARIABLE = "wsp.name";
 
+    /** Name of the security configuration element. */
     private static final String SECURITY_ELEMENT = "Security";
-    private static final String APP_NAME_ATTRIB = "appName";
+
+    /** Name of the access manager configuration element. */
     private static final String ACCESS_MANAGER_ELEMENT = "AccessManager";
 
+    /** Name of the general workspace configuration element. */
     private static final String WORKSPACES_ELEMENT = "Workspaces";
-    private static final String ROOT_PATH_ATTRIB = "rootPath";
-    private static final String DEFAULT_WORKSPACE_ATTRIB = "defaultWorkspace";
 
+    /** Name of the workspace configuration element. */
     private static final String WORKSPACE_ELEMENT = "Workspace";
 
+    /** Name of the versioning configuration element. */
     private static final String VERSIONING_ELEMENT = "Versioning";
 
-    /**
-     * wellknown variables (will be replaced with their respective values
-     * whereever they occur within the configuration)
-     */
-    public static final String REPOSITORY_HOME_VARIABLE = "rep.home";
+    /** Name of the file system configuration element. */
+    private static final String FILE_SYSTEM_ELEMENT = "FileSystem";
 
-    protected static final String FILE_SYSTEM_ELEMENT = "FileSystem";
-    private static final String PERSISTENCE_MANAGER_ELEMENT = "PersistenceManager";
+    /** Name of the persistence manager configuration element. */
+    private static final String PERSISTENCE_MANAGER_ELEMENT =
+        "PersistenceManager";
+
+    /** Name of the search index configuration element. */
     private static final String SEARCH_INDEX_ELEMENT = "SearchIndex";
 
+    /** Name of the bean parameter configuration element. */
+    private static final String PARAM_ELEMENT = "param";
+
+    /** Name of the application name configuration attribute. */
+    private static final String APP_NAME_ATTRIBUTE = "appName";
+
+    /** Name of the root path configuration attribute. */
+    private static final String ROOT_PATH_ATTRIBUTE = "rootPath";
+
+    /** Name of the default workspace configuration attribute. */
+    private static final String DEFAULT_WORKSPACE_ATTRIBUTE =
+        "defaultWorkspace";
+
+    /** Name of the bean implementation class configuration attribute. */
     private static final String CLASS_ATTRIBUTE = "class";
 
-    private static final String PARAM_ELEMENT = "param";
+    /** Name of the bean parameter name configuration attribute. */
     private static final String NAME_ATTRIBUTE = "name";
+
+    /** Name of the bean parameter value configuration attribute. */
     private static final String VALUE_ATTRIBUTE = "value";
 
-    /** attribute name of home dir */
-    private static final String ROOTPATH_ATTRIBUTE = "rootPath";
+    /** Name of the default search index implementation class. */
+    private static final String DEFAULT_QUERY_HANDLER =
+            "org.apache.jackrabbit.core.search.lucene.SearchIndex";
 
     /**
-     * wellknown variables (will be replaced with their respective values
-     * whereever they occur within the configuration)
+     * The configuration parser variables. These name-value pairs
+     * are used to substitute <code>${...}</code> variable references
+     * with context-dependent values in the configuration.
+     *
+     * @see #replaceVariables(String)
      */
-    public static final String WORKSPACE_HOME_VARIABLE = "wsp.home";
-    public static final String WORKSPACE_NAME_VARIABLE = "wsp.name";
-
-    /** FQN of the default query handler implementation */
-    private static final String DEFAULT_QUERY_HANDLER
-            = "org.apache.jackrabbit.core.search.lucene.SearchIndex";
-
-    private Properties variables;
+    private final Properties variables;
 
+    /**
+     * Creates a new configuration parser with the given parser variables.
+     *
+     * @param variables parser variables
+     */
     public ConfigurationParser(Properties variables) {
         this.variables = variables;
     }
 
-    public Document parse(InputSource xml) throws IOException, JDOMException {
-        SAXBuilder builder = new SAXBuilder();
-        builder.setEntityResolver(new ConfigurationEntityResolver());
-        return builder.build(xml);
-    }
-    
-    /**
-     * Creates a new <code>RepositoryFactory</code> instance. The configuration
-     * is read from the specified configuration file.
-     *
-     * @param configFilePath path to the configuration file
-     * @param repHomeDir     repository home directory
-     * @return a new <code>RepositoryConfig</code> instance
-     * @throws RepositoryException If an error occurs
-     */
-    public RepositoryConfig parseRepositoryConfig(
-            String configFilePath, String repHomeDir) throws RepositoryException {
-        try {
-            File config = new File(configFilePath);
-            InputSource is = new InputSource(new FileReader(config));
-            is.setSystemId(config.toURI().toString());
-            return parseRepositoryConfig(is, repHomeDir);
-        } catch (IOException ioe) {
-            String msg = "error while reading config file " + configFilePath;
-            throw new RepositoryException(msg, ioe);
-        }
-    }
-
     /**
-     * private constructor.
+     * Parses repository configuration. Repository configuration uses the
+     * following format:
+     * <pre>
+     *   &lt;Repository&gt;
+     *     &lt;FileSystem ...&gt;
+     *     &lt;Security appName="..."&gt;
+     *       &lt;AccessManager ...&gt;
+     *     &lt;/Security&gt;
+     *     &lt;Workspaces rootPath="..." defaultWorkspace="..."/&gt;
+     *     &lt;Workspace ...&gt;
+     *     &lt;Versioning ...&gt;
+     *   &lt;/Repository&gt;
+     * </pre>
+     * <p>
+     * The <code>FileSystem</code> element is a
+     * {@link #parseBeanConfig(Element,String) bean configuration} element,
+     * that specifies the file system implementation for storing global
+     * repository information. The <code>Security</code> element contains
+     * an <code>AccessManager</code> bean configuration element and the
+     * JAAS name of the repository application. The <code>Workspaces</code>
+     * element contains general workspace parameters, and the
+     * <code>Workspace</code> element is a template for the individual
+     * workspace configuration files. The <code>Versioning</code> element
+     * contains
+     * {@link #parseVersioningConfig(Element) versioning configuration} for
+     * the repository.
+     * <p>
+     * In addition to the configured information, the returned repository
+     * configuration object also contains the repository home directory path
+     * that is given as the ${rep.home} parser variable. Note that the
+     * variable <em>must</em> be available for the configuration document to
+     * be correctly parsed.
+     * <p>
+     * {@link #replaceVariables(String) Variable replacement} is performed
+     * on the security application name attribute, the general workspace
+     * configuration attributes, and on the file system, access manager,
+     * and versioning configuration information.
      *
-     * @param xml
-     * @param repHomeDir
-     * @throws RepositoryException
-     */
-    public RepositoryConfig parseRepositoryConfig(
-            InputSource xml, String repHomeDir)
-            throws RepositoryException {
-        Properties newVariables = new Properties(variables);
-        newVariables.setProperty(REPOSITORY_HOME_VARIABLE, repHomeDir);
-        ConfigurationParser parser = new ConfigurationParser(newVariables);
-        return parser.parseRepositoryConfig(xml);
-    }
-
+     * @param xml repository configuration document
+     * @return repository configuration
+     * @throws ConfigurationException if the configuration is broken
+     * @see #parseBeanConfig(Element, String)
+     * @see #parseVersioningConfig(Element)
+     */
     public RepositoryConfig parseRepositoryConfig(InputSource xml)
-            throws RepositoryException {
-        try {
-            Document config = parse(xml);
-            Element root = config.getRootElement();
-
-            String home = variables.getProperty(REPOSITORY_HOME_VARIABLE);
-
-            // file system
-            BeanConfig fsc = parseBeanConfig(root, FILE_SYSTEM_ELEMENT);
-
-            // security & access manager config
-            Element secEleme = root.getChild(SECURITY_ELEMENT);
-            String appName = secEleme.getAttributeValue(APP_NAME_ATTRIB);
-            BeanConfig amc = parseBeanConfig(secEleme, ACCESS_MANAGER_ELEMENT);
-
-            // workspaces
-            Element wspsElem = root.getChild(WORKSPACES_ELEMENT);
-            String wspConfigRootDir = replaceVariables(wspsElem.getAttributeValue(ROOT_PATH_ATTRIB));
-            String defaultWspName = replaceVariables(wspsElem.getAttributeValue(DEFAULT_WORKSPACE_ATTRIB));
-
-            // load wsp configs
-            Map wspConfigs = new HashMap();
-            File wspRoot = new File(wspConfigRootDir);
-            if (!wspRoot.exists()) {
-                wspRoot.mkdirs();
-            }
-            File[] files = wspRoot.listFiles();
-            if (files == null) {
-                String msg = "invalid repsitory home directory";
-                throw new RepositoryException(msg);
-            }
-            for (int i = 0; i < files.length; i++) {
-                // check if <subfolder>/workspace.xml exists
-                File configFile = new File(files[i], "workspace.xml");
-                if (configFile.isFile()) {
-                    // create workspace config
-                    Properties newVariables = new Properties(variables);
-                    newVariables.setProperty(
-                            WORKSPACE_HOME_VARIABLE, configFile.getParent());
-                    ConfigurationParser parser =
-                        new ConfigurationParser(newVariables);
-
-                    InputSource wsxml =
-                        new InputSource(new FileReader(configFile));
-                    wsxml.setSystemId(configFile.toURI().toString());
-                    WorkspaceConfig wspConfig =
-                        parser.parseWorkspaceConfig(wsxml);
-                    String wspName = wspConfig.getName();
-                    if (wspConfigs.containsKey(wspName)) {
-                        String msg = "duplicate workspace name: " + wspName;
-                        throw new RepositoryException(msg);
-                    }
-                    wspConfigs.put(wspName, wspConfig);
-                }
-            }
-            if (wspConfigs.isEmpty()) {
-                // create initial default workspace
-                wspConfigs.put(defaultWspName, createWorkspaceConfig(
-                        config, wspConfigRootDir, defaultWspName));
-            } else {
-                if (!wspConfigs.containsKey(defaultWspName)) {
-                    String msg = "no configuration found for default workspace: " + defaultWspName;
-                    throw new RepositoryException(msg);
-                }
-            }
+            throws ConfigurationException {
+        Element root = parseXML(xml);
 
-            // load versioning config
-            Element vElement = config.getRootElement().getChild(VERSIONING_ELEMENT);
-            VersioningConfig vc = parseVersioningConfig(vElement);
-
-            return new RepositoryConfig(
-                    config, this, home, appName, wspConfigs,
-                    createFileSystem(fsc), wspConfigRootDir,
-                    defaultWspName, amc, vc);
-        } catch (JDOMException ex) {
-            throw new RepositoryException(ex);
-        } catch (IOException ex) {
-            throw new RepositoryException(ex);
-        }
-    }
+        // Repository home directory
+        String home = variables.getProperty(REPOSITORY_HOME_VARIABLE);
 
-    /**
-     * Creates a new workspace configuration with the specified name.
-     *
-     * @param name workspace name
-     * @return a new <code>WorkspaceConfig</code> object.
-     * @throws RepositoryException if the specified name already exists or
-     *                             if an error occured during the creation.
-     */
-    public WorkspaceConfig createWorkspaceConfig(
-            Document config, String root, String name)
-            throws RepositoryException {
-        // create the workspace folder (i.e. the workspace home directory)
-        File wspFolder = new File(root, name);
-        if (!wspFolder.mkdir()) {
-            String msg = "Failed to create the workspace home directory: " + wspFolder.getPath();
-            throw new RepositoryException(msg);
-        }
-        // clone the workspace definition template
-        Element wspCongigElem =
-            (Element) config.getRootElement().getChild("Workspace").clone();
-        wspCongigElem.setAttribute("name", name);
-
-        // create workspace.xml file
-/*
-        DocType docType = new DocType(WORKSPACE_ELEMENT, null, WorkspaceConfig.PUBLIC_ID);
-        Document doc = new Document(wspCongigElem, docType);
-*/
-        Document doc = new Document(wspCongigElem);
-        XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
-        File configFile = new File(wspFolder, "workspace.xml");
-        FileOutputStream fos = null;
-        try {
-            fos = new FileOutputStream(configFile);
-            out.output(doc, fos);
-        } catch (IOException ioe) {
-            String msg = "Failed to create workspace configuration file: " + configFile.getPath();
-            throw new RepositoryException(msg, ioe);
-        } finally {
-            if (fos != null) {
-                try {
-                    fos.close();
-                } catch (IOException e) {
-                    // ignore
-                }
-            }
-        }
+        // File system implementation
+        FileSystemConfig fsc =
+            new FileSystemConfig(parseBeanConfig(root, FILE_SYSTEM_ELEMENT));
 
-        try {
-            // create workspace config object
-            Properties newVariables = new Properties(variables);
-            newVariables.setProperty(
-                    WORKSPACE_HOME_VARIABLE, configFile.getParent());
-            ConfigurationParser parser = new ConfigurationParser(newVariables);
-
-            InputSource xml = new InputSource(new FileReader(configFile));
-            xml.setSystemId(configFile.toURI().toString());
-
-            return parser.parseWorkspaceConfig(xml);
-        } catch (FileNotFoundException e) {
-            throw new ConfigurationException("TODO", e);
-        }
+        // Security configuration and access manager implementation
+        Element security = getElement(root, SECURITY_ELEMENT);
+        String appName = getAttribute(security, APP_NAME_ATTRIBUTE);
+        AccessManagerConfig amc = new AccessManagerConfig(
+                parseBeanConfig(security, ACCESS_MANAGER_ELEMENT));
+
+        // General workspace configuration
+        Element workspaces = getElement(root, WORKSPACES_ELEMENT);
+        String workspaceDirectory = replaceVariables(
+                getAttribute(workspaces, ROOT_PATH_ATTRIBUTE));
+        String defaultWorkspace = replaceVariables(
+                getAttribute(workspaces, DEFAULT_WORKSPACE_ATTRIBUTE));
+
+        // Versioning configuration
+        VersioningConfig vc = parseVersioningConfig(root);
+
+        return new RepositoryConfig(
+                root, this, home, appName, fsc, workspaceDirectory,
+                defaultWorkspace, amc, vc);
     }
 
     /**
@@ -291,7 +206,7 @@
      *     &lt;FileSystem ...&gt;
      *     &lt;PersistenceManager ...&gt;
      *     &lt;SearchIndex ...&gt;
-     *   &lt;/Search&gt;
+     *   &lt;/Workspace&gt;
      * </pre>
      * <p>
      * All the child elements (<code>FileSystem</code>,
@@ -303,7 +218,9 @@
      * <p>
      * In addition to the configured information, the returned workspace
      * configuration object also contains the workspace home directory path
-     * that is given as the ${wsp.home} parser variable.
+     * that is given as the ${wsp.home} parser variable. Note that the
+     * variable <em>must</em> be available for the configuration document to
+     * be correctly parsed.
      * <p>
      * Variable replacement is performed on the optional workspace name
      * attribute. If the name is not given, then the name of the workspace
@@ -323,49 +240,32 @@
      */
     public WorkspaceConfig parseWorkspaceConfig(InputSource xml)
             throws ConfigurationException {
-        try {
-            Document document = parse(xml);
-            Element element = document.getRootElement();
+        Element root = parseXML(xml);
 
-            // Workspace home directory
-            String home = variables.getProperty(WORKSPACE_HOME_VARIABLE);
+        // Workspace home directory
+        String home = variables.getProperty(WORKSPACE_HOME_VARIABLE);
 
-            // Workspace name
-            String name = element.getAttributeValue(NAME_ATTRIBUTE);
-            if (name != null) {
-                name = replaceVariables(name);
-            } else {
-                name = new File(home).getName();
-            }
+        // Workspace name
+        String name =
+            getAttribute(root, NAME_ATTRIBUTE, new File(home).getName());
+
+        // Create a temporary parser that contains the ${wsp.name} variable
+        Properties tmpVariables = (Properties) variables.clone();
+        tmpVariables.put(WORKSPACE_NAME_VARIABLE, name);
+        ConfigurationParser tmpParser = new ConfigurationParser(tmpVariables);
 
-            // Create a temporary parser that contains the ${wsp.name} variable
-            Properties newVariables = new Properties(variables);
-            newVariables.put(WORKSPACE_NAME_VARIABLE, name);
-            ConfigurationParser parser = new ConfigurationParser(newVariables);
+        // File system implementation
+        FileSystemConfig fsc = new FileSystemConfig(
+                tmpParser.parseBeanConfig(root, FILE_SYSTEM_ELEMENT));
 
-            // File system implementation
-            BeanConfig fsc =
-                parser.parseBeanConfig(element, FILE_SYSTEM_ELEMENT);
+        // Persistence manager implementation
+        PersistenceManagerConfig pmc = new PersistenceManagerConfig(
+            tmpParser.parseBeanConfig(root, PERSISTENCE_MANAGER_ELEMENT));
 
-            // Persistence manager implementation
-            BeanConfig pmc =
-                parser.parseBeanConfig(element, PERSISTENCE_MANAGER_ELEMENT);
-
-            // Search implementation (optional)
-            SearchConfig sc = null;
-            Element search = element.getChild(SEARCH_INDEX_ELEMENT);
-            if (search != null) {
-                sc = parser.parseSearchConfig(search);
-            }
+        // Search implementation (optional)
+        SearchConfig sc = tmpParser.parseSearchConfig(root);
 
-            return new WorkspaceConfig(home, name, createFileSystem(fsc), pmc, sc);
-        } catch (JDOMException e) {
-            throw new ConfigurationException(
-                    "Workspace configuration syntax error.", e);
-        } catch (IOException e) {
-            throw new ConfigurationException(
-                    "Workspace configuration could not be read.", e);
-        }
+        return new WorkspaceConfig(home, name, fsc, pmc, sc);
     }
 
     /**
@@ -383,26 +283,34 @@
      * elements are {@link #parseBeanConfig(Element,String) bean configuration}
      * elements. If the search implementation class is not given, then
      * a default implementation is used.
+     * <p>
+     * The search index is an optional feature of workspace configuration.
+     * If the search configuration element is not found, then this method
+     * returns <code>null</code>.
      *
-     * @param element search configuration element
-     * @return search configuration
+     * @param parent parent of the <code>SearchIndex</code> element
+     * @return search configuration, or <code>null</code>
      * @throws ConfigurationException if the configuration is broken
      */
-    private SearchConfig parseSearchConfig(Element element)
+    private SearchConfig parseSearchConfig(Element parent)
             throws ConfigurationException {
-        // Search implementation class
-        String className = element.getAttributeValue(CLASS_ATTRIBUTE);
-        if (className == null) {
-            className = DEFAULT_QUERY_HANDLER;
-        }
+        Element element = parent.getChild(SEARCH_INDEX_ELEMENT);
+        if (element != null) {
+            // Search implementation class
+            String className =
+                getAttribute(element, CLASS_ATTRIBUTE, DEFAULT_QUERY_HANDLER);
 
-        // Search parameters
-        Properties parameters = parseParameters(element);
+            // Search parameters
+            Properties parameters = parseParameters(element);
 
-        // File system implementation
-        BeanConfig fsc = parseBeanConfig(element, FILE_SYSTEM_ELEMENT);
+            // File system implementation
+            FileSystemConfig fsc = new FileSystemConfig(
+                    parseBeanConfig(element, FILE_SYSTEM_ELEMENT));
 
-        return new SearchConfig(className, parameters, createFileSystem(fsc));
+            return new SearchConfig(className, parameters, fsc);
+        } else {
+            return null;
+        }
     }
 
     /**
@@ -421,58 +329,27 @@
      * {@link #replaceVariables(String) variable replacement} is performed
      * also on the versioning root path attribute.
      *
-     * @param element versioning configuration element
+     * @param parent parent of the <code>Versioning</code> element
      * @return versioning configuration
      * @throws ConfigurationException if the configuration is broken
      */
-    private VersioningConfig parseVersioningConfig(Element element)
+    private VersioningConfig parseVersioningConfig(Element parent)
             throws ConfigurationException {
+        Element element = getElement(parent, VERSIONING_ELEMENT);
+
         // Versioning home directory
-        String home = element.getAttributeValue(ROOTPATH_ATTRIBUTE);
-        if (home == null) {
-            throw new ConfigurationException("Versioning root path not set.");
-        }
+        String home =
+            replaceVariables(getAttribute(element, ROOT_PATH_ATTRIBUTE));
 
         // File system implementation
-        BeanConfig fsc = parseBeanConfig(element, FILE_SYSTEM_ELEMENT);
+        FileSystemConfig fsc = new FileSystemConfig(
+                parseBeanConfig(element, FILE_SYSTEM_ELEMENT));
 
         // Persistence manager implementation
-        BeanConfig pmc = parseBeanConfig(element, PERSISTENCE_MANAGER_ELEMENT);
-
-        return new VersioningConfig(
-                replaceVariables(home), createFileSystem(fsc), pmc);
-    }
+        PersistenceManagerConfig pmc = new PersistenceManagerConfig(
+                parseBeanConfig(element, PERSISTENCE_MANAGER_ELEMENT));
 
-    /**
-     * Instantiates and initializes the file system implementation class
-     * configured by the given bean configuration object.
-     *
-     * @param config file system configuration
-     * @return initialized file system implementation
-     * @throws ConfigurationException if the file system could not be created
-     */
-    private FileSystem createFileSystem(BeanConfig config)
-            throws ConfigurationException {
-        try {
-            FileSystem filesystem = (FileSystem) config.newInstance();
-            filesystem.init();
-            return filesystem;
-        } catch (ClassNotFoundException e) {
-            throw new ConfigurationException(
-                    "File system implementation class not found.", e);
-        } catch (InstantiationException e) {
-            throw new ConfigurationException(
-                    "File system implementation can not be instantiated.", e);
-        } catch (IllegalAccessException e) {
-            throw new ConfigurationException(
-                    "File system implementation class is protected.", e);
-        } catch (ClassCastException e) {
-            throw new ConfigurationException(
-                    "Invalid file system implementation class.", e);
-        } catch (FileSystemException e) {
-            throw new ConfigurationException(
-                    "File system initialization failure.", e);
-        }
+        return new VersioningConfig(home, fsc, pmc);
     }
 
     /**
@@ -498,18 +375,10 @@
     private BeanConfig parseBeanConfig(Element parent, String name)
             throws ConfigurationException {
         // Bean configuration element
-        Element element = parent.getChild(name);
-        if (element == null) {
-            throw new ConfigurationException(
-                    "Configuration element not found: " + name);
-        }
+        Element element = getElement(parent, name);
 
         // Bean implementation class
-        String className = element.getAttributeValue(CLASS_ATTRIBUTE);
-        if (className == null) {
-            throw new ConfigurationException(
-                    "Class attribute not set: " + name);
-        }
+        String className = getAttribute(element, CLASS_ATTRIBUTE);
 
         // Bean properties
         Properties properties = parseParameters(element);
@@ -571,26 +440,110 @@
         // +--+-+--------+-+-----------------+
         // |  |p|-->     |q|-->              |
         // +--+-+--------+-+-----------------+
-        int p = 0, q = value.indexOf("${");              // Find first ${
+        int p = 0, q = value.indexOf("${");                // Find first ${
         while (q != -1) {
-            result.append(value.substring(p, q));                  // Text before ${
+            result.append(value.substring(p, q));          // Text before ${
             p = q;
-            q = value.indexOf("}", q + 2);               // Find }
+            q = value.indexOf("}", q + 2);                 // Find }
             if (q != -1) {
                 String variable = value.substring(p + 2, q);
                 String replacement = variables.getProperty(variable);
                 if (replacement == null) {
                     throw new ConfigurationException(
-                            "Variable replacement not found: " + variable);
+                            "Replacement not found for ${" + variable + "}.");
                 }
                 result.append(replacement);
                 p = q + 1;
-                q = value.indexOf("${", p);              // Find next ${
+                q = value.indexOf("${", p);                // Find next ${
             }
         }
-        result.append(value.substring(p, value.length()));         // Trailing text
+        result.append(value.substring(p, value.length())); // Trailing text
 
         return result.toString();
+    }
+
+    /**
+     * Parses the given XML document and returns the DOM root element.
+     * A custom entity resolver is used to make the included configuration
+     * file DTD available using the specified public identifiers.
+     *
+     * @see ConfigurationEntityResolver
+     * @param xml xml document
+     * @return root element
+     * @throws ConfigurationException if the configuration document could
+     *                                not be read or parsed
+     */
+    private Element parseXML(InputSource xml) throws ConfigurationException {
+        try {
+            SAXBuilder builder = new SAXBuilder();
+            builder.setEntityResolver(new ConfigurationEntityResolver());
+            Document document = builder.build(xml);
+            return document.getRootElement();
+        } catch (JDOMException e) {
+            throw new ConfigurationException(
+                    "Configuration file syntax error.", e);
+        } catch (IOException e) {
+            throw new ConfigurationException(
+                    "Configuration file could not be read.", e);
+        }
+    }
+
+    /**
+     * Returns the named child of the given parent element.
+     *
+     * @param parent parent element
+     * @param name name of the child element
+     * @return named child element
+     * @throws ConfigurationException if the child element is not found
+     */
+    private Element getElement(Element parent, String name)
+            throws ConfigurationException {
+        Element element = parent.getChild(name);
+        if (element != null) {
+            return element;
+        } else {
+            throw new ConfigurationException(
+                    "Configuration element " + name + " not found in "
+                    + parent.getName() + ".");
+        }
+    }
+
+    /**
+     * Returns the value of the named attribute of the given element.
+     *
+     * @param element element
+     * @param name attribute name
+     * @return attribute value
+     * @throws ConfigurationException if the attribute is not found
+     */
+    private String getAttribute(Element element, String name)
+            throws ConfigurationException {
+        String value = element.getAttributeValue(name);
+        if (value != null) {
+            return value;
+        } else {
+            throw new ConfigurationException(
+                    "Configuration attribute " + name + " not found in "
+                    + element.getName() + ".");
+        }
+    }
+
+    /**
+     * Returns the value of the named attribute of the given element.
+     * If the attribute is not found, then the given default value is returned.
+     *
+     * @param element element
+     * @param name attribute name
+     * @param def default value
+     * @return attribute value, or the default value
+     */
+    private String getAttribute(Element element, String name, String def) {
+        String value = element.getAttributeValue(name);
+        if (value != null) {
+            return value;
+        } else {
+            return def;
+        }
     }
 
 }

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/FileSystemConfig.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/FileSystemConfig.java?view=auto&rev=156418
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/FileSystemConfig.java (added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/FileSystemConfig.java Mon Mar  7 04:26:02 2005
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.config;
+
+import org.apache.jackrabbit.core.fs.FileSystem;
+import org.apache.jackrabbit.core.fs.FileSystemException;
+
+/**
+ * File system configuration. This bean configuration class
+ * is used to create a configured file system objects. The file system
+ * is instantiated by the {@link #init() init()} method, and accessible
+ * using the {@link #getFileSystem() getFileSystem()} method.
+ */
+public class FileSystemConfig extends BeanConfig {
+
+    /** The initialized file system implementation. */
+    private FileSystem fs;
+
+    /**
+     * Creates a file system configuration object.
+     *
+     * @param config file system implementation class configuration
+     */
+    public FileSystemConfig(BeanConfig config) {
+        super(config);
+        fs = null;
+    }
+
+    /**
+     * Instantiates and initializes the configured file system
+     * implementation class.
+     *
+     * @throws ConfigurationException on file system initialization errors
+     * @throws IllegalStateException if the file system has already been
+     *                               initialized
+     */
+    public void init() throws ConfigurationException, IllegalStateException {
+        if (fs == null) {
+            try {
+                fs = (FileSystem) newInstance();
+                fs.init();
+            } catch (ClassCastException e) {
+                throw new ConfigurationException(
+                        "Invalid file system implementation class "
+                        + getClassName() + ".", e);
+            } catch (FileSystemException e) {
+                throw new ConfigurationException(
+                        "File system initialization failure.", e);
+            }
+        } else {
+            throw new IllegalStateException(
+            "File system has already been initialized.");
+        }
+    }
+
+    /**
+     * Returns the configured file system. The {@link #init() init()} method
+     * must have been called before this method can be invoked.
+     *
+     * @return configured file system
+     * @throws IllegalStateException if the file system has not been initialized
+     */
+    public FileSystem getFileSystem() throws IllegalStateException {
+        if (fs != null) {
+            return fs;
+        } else {
+            throw new IllegalStateException(
+                    "File system has not been initialized.");
+        }
+    }
+
+}

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java?view=diff&r1=156417&r2=156418
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java Mon Mar  7 04:26:02 2005
@@ -16,40 +16,74 @@
  */
 package org.apache.jackrabbit.core.config;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 
-import javax.jcr.RepositoryException;
-
-import org.xml.sax.InputSource;
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+import org.xml.sax.InputSource;
 
 /**
  * A <code>RepositoryConfig</code> ...
  */
 public class RepositoryConfig {
 
+    /** Name of the workspace configuration file. */
+    private static final String WORKSPACE_XML = "workspace.xml";
+
+    /**
+     * Creates a new <code>RepositoryFactory</code> instance. The configuration
+     * is read from the specified configuration file.
+     *
+     * @param file path to the configuration file
+     * @param home repository home directory
+     * @return a new <code>RepositoryConfig</code> instance
+     * @throws ConfigurationException if an error occurs
+     */
     public static RepositoryConfig create(String file, String home)
-            throws RepositoryException {
-        ConfigurationParser parser = new ConfigurationParser(new Properties());
-        return parser.parseRepositoryConfig(file, home);
+            throws ConfigurationException {
+        try {
+            File config = new File(file);
+
+            InputSource xml = new InputSource(new FileReader(config));
+            xml.setSystemId(config.toURI().toString());
+
+            return create(xml, home);
+        } catch (FileNotFoundException e) {
+            throw new ConfigurationException("TODO", e);
+        }
     }
 
-    public static RepositoryConfig create(InputSource is, String home)
-            throws RepositoryException {
-        ConfigurationParser parser = new ConfigurationParser(new Properties());
-        return parser.parseRepositoryConfig(is, home);
+    public static RepositoryConfig create(InputSource xml, String home)
+            throws ConfigurationException {
+        Properties variables = new Properties();
+        variables.setProperty(
+                ConfigurationParser.REPOSITORY_HOME_VARIABLE, home);
+        ConfigurationParser parser = new ConfigurationParser(variables);
+
+        RepositoryConfig config = parser.parseRepositoryConfig(xml);
+        config.init();
+
+        return config;
     }
 
-    private Document config;
+    private Element config;
     private ConfigurationParser parser;
 
     /**
      * map of workspace names and workspace configurations
      */
-    private final Map wspConfigs;
+    private Map wspConfigs;
 
     /**
      * repository home directory
@@ -59,10 +93,10 @@
     /**
      * virtual file system where the repository stores global state
      */
-    private FileSystem repFS;
+    private FileSystemConfig fsc;
 
     /**
-     * the name of the JAAS configuration app-entry for this repository 
+     * the name of the JAAS configuration app-entry for this repository
      */
     private String appName;
 
@@ -81,7 +115,7 @@
     /**
      * configuration for the access manager
      */
-    private BeanConfig amConfig;
+    private AccessManagerConfig amConfig;
 
     /**
      * the versioning config
@@ -89,42 +123,138 @@
     private VersioningConfig vConfig;
 
     public RepositoryConfig(
-            Document config, ConfigurationParser parser,
-            String home, String name, Map wspConfigs,
-            FileSystem fs, String root, String defaultWspName,
-            BeanConfig amc, VersioningConfig vc) {
+            Element config, ConfigurationParser parser,
+            String home, String name, FileSystemConfig fsc,
+            String root, String defaultWspName, AccessManagerConfig amc,
+            VersioningConfig vc) {
         this.config = config;
         this.parser = parser;
         this.repHomeDir = home;
         this.appName = name;
-        this.wspConfigs = wspConfigs;
-        this.repFS = fs;
+        this.wspConfigs = new HashMap();
+        this.fsc = fsc;
         this.wspConfigRootDir = root;
         this.defaultWspName = defaultWspName;
         this.amConfig = amc;
         this.vConfig = vc;
     }
 
+    private void init() throws ConfigurationException {
+        fsc.init();
+        vConfig.init();
+
+        File root = new File(wspConfigRootDir);
+        if (!root.exists()) {
+            root.mkdirs();
+        }
+
+        File[] files = root.listFiles();
+        if (files == null) {
+            throw new ConfigurationException(
+                    "Invalid workspace root directory: " + wspConfigRootDir);
+        }
+
+        for (int i = 0; i < files.length; i++) {
+            WorkspaceConfig config = loadWorkspaceConfig(files[i]);
+            if (config != null) {
+                config.init();
+                addWorkspaceConfig(config);
+            }
+        }
+    }
+
+    private WorkspaceConfig loadWorkspaceConfig(File directory)
+            throws ConfigurationException {
+        try {
+            File file = new File(directory, WORKSPACE_XML);
+            InputSource xml = new InputSource(new FileReader(file));
+            xml.setSystemId(file.toURI().toString());
+
+            Properties variables = new Properties();
+            variables.setProperty(
+                    ConfigurationParser.WORKSPACE_HOME_VARIABLE,
+                    directory.getPath());
+            ConfigurationParser parser = new ConfigurationParser(variables);
+
+            WorkspaceConfig config = parser.parseWorkspaceConfig(xml);
+            return config;
+        } catch (FileNotFoundException e) {
+            return null;
+        }
+    }
+
+    private void addWorkspaceConfig(WorkspaceConfig config)
+            throws ConfigurationException {
+        String name = config.getName();
+        if (!wspConfigs.containsKey(name)) {
+            wspConfigs.put(name, config);
+        } else {
+            throw new ConfigurationException(
+                    "Duplicate workspace configuration: " + name);
+        }
+    }
+
     /**
      * Creates a new workspace configuration with the specified name.
      *
      * @param name workspace name
      * @return a new <code>WorkspaceConfig</code> object.
-     * @throws RepositoryException if the specified name already exists or
+     * @throws ConfigurationException if the specified name already exists or
      *                             if an error occured during the creation.
      */
     public synchronized WorkspaceConfig createWorkspaceConfig(String name)
-            throws RepositoryException {
-        if (wspConfigs.containsKey(name)) {
-            String msg = "A workspace with the specified name alreay exists";
-            throw new RepositoryException(msg);
-        }
-        WorkspaceConfig wspConfig =
-            parser.createWorkspaceConfig(config, wspConfigRootDir, name);
-        wspConfigs.put(name, wspConfig);
-        return wspConfig;
-    }
+            throws ConfigurationException {
+        // create the workspace folder (i.e. the workspace home directory)
+        File wspFolder = new File(wspConfigRootDir, name);
+        if (!wspFolder.mkdir()) {
+            String msg = "Failed to create the workspace home directory: " + wspFolder.getPath();
+            throw new ConfigurationException(msg);
+        }
+        // clone the workspace definition template
+        Element wspCongigElem = (Element) config.getChild("Workspace").clone();
+        wspCongigElem.setAttribute("name", name);
+
+        // create workspace.xml file
+/*
+        DocType docType = new DocType(WORKSPACE_ELEMENT, null, WorkspaceConfig.PUBLIC_ID);
+        Document doc = new Document(wspCongigElem, docType);
+*/
+        Document doc = new Document(wspCongigElem);
+        XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
+        File configFile = new File(wspFolder, WORKSPACE_XML);
+        FileOutputStream fos = null;
+        try {
+            fos = new FileOutputStream(configFile);
+            out.output(doc, fos);
+        } catch (IOException ioe) {
+            String msg = "Failed to create workspace configuration file: " + configFile.getPath();
+            throw new ConfigurationException(msg, ioe);
+        } finally {
+            if (fos != null) {
+                try {
+                    fos.close();
+                } catch (IOException e) {
+                    // ignore
+                }
+            }
+        }
 
+        try {
+            // create workspace config object
+            Properties newVariables = new Properties();
+            newVariables.setProperty(
+                    ConfigurationParser.WORKSPACE_HOME_VARIABLE,
+                    configFile.getParent());
+            ConfigurationParser parser = new ConfigurationParser(newVariables);
+
+            InputSource xml = new InputSource(new FileReader(configFile));
+            xml.setSystemId(configFile.toURI().toString());
+
+            return parser.parseWorkspaceConfig(xml);
+        } catch (FileNotFoundException e) {
+            throw new ConfigurationException("TODO", e);
+        }
+    }
     /**
      * Returns the home directory of the repository.
      *
@@ -140,7 +270,7 @@
      * @return the virtual file system where the repository stores global state
      */
     public FileSystem getFileSystem() {
-        return repFS;
+        return fsc.getFileSystem();
     }
 
     /**
@@ -207,7 +337,7 @@
      * @return an <code>AccessManagerConfig</code> object
      */
     public AccessManagerConfig getAccessManagerConfig() {
-        return new AccessManagerConfig(amConfig);
+        return amConfig;
     }
 
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/SearchConfig.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/SearchConfig.java?view=diff&r1=156417&r2=156418
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/SearchConfig.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/SearchConfig.java Mon Mar  7 04:26:02 2005
@@ -21,35 +21,60 @@
 import org.apache.jackrabbit.core.fs.FileSystem;
 
 /**
- * Implements the search configuration.
+ * Search index configuration. This bean configuration class
+ * is used to create configured search index objects.
+ * <p>
+ * In addition to generic bean configuration information, this
+ * class also contains a configured file system implementation
+ * used by the search index.
+ *
+ * @see WorkspaceConfig#getSearchConfig()
  */
 public class SearchConfig extends BeanConfig {
 
-    /** The <code>FileSystem</code> for the search index. */
-    private final FileSystem fs;
+    /**
+     * The search index file system configuration.
+     */
+    private final FileSystemConfig fsc;
 
+    /**
+     * Creates a search index configuration object.
+     *
+     * @param className search index implementation class
+     * @param properties search index properties
+     * @param fsc search index file system configuration
+     */
     public SearchConfig(
-            String className, Properties properties, FileSystem fs) {
+            String className, Properties properties, FileSystemConfig fsc) {
         super(className, properties);
-        this.fs = fs;
+        this.fsc = fsc;
     }
 
     /**
-     * Returns <code>FileSystem</code> for search index persistence.
-     * @return <code>FileSystem</code> for search index persistence.
+     * Initializes the search index file system.
+     *
+     * @throws ConfigurationException on file system configuration errors
      */
-    public FileSystem getFileSystem() {
-        return fs;
+    public void init() throws ConfigurationException {
+        fsc.init();
     }
 
     /**
-     * Returns the name of the class implementing the <code>QueryHandler</code>
-     * interface.
-     * @return the name of the class implementing the <code>QueryHandler</code>
-     *   interface.
+     * Returns the search implementation class name.
+     *
+     * @return search implementation class name
      */
     public String getHandlerClassName() {
         return getClassName();
+    }
+
+    /**
+     * Returns the search index file system.
+     *
+     * @return search index file system
+     */
+    public FileSystem getFileSystem() {
+        return fsc.getFileSystem();
     }
 
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/VersioningConfig.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/VersioningConfig.java?view=diff&r1=156417&r2=156418
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/VersioningConfig.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/VersioningConfig.java Mon Mar  7 04:26:02 2005
@@ -21,45 +21,80 @@
 import org.apache.jackrabbit.core.fs.FileSystem;
 
 /**
- * This Class implements the configuration object for the versioning.
+ * Versioning configuration. This configuration class is used to
+ * create configured versioning objects.
+ * <p>
+ * The contained configuration information are: the home directory,
+ * the file system implementation, and the persistence manager
+ * implementation.
+ *
+ * @see RepositoryConfig#getVersioningConfig()
  */
 public class VersioningConfig {
 
-    /** the homedir for the versioning */
+    /**
+     * Versioning home directory.
+     */
     private final String home;
 
-    /** The <code>FileSystem</code> for the versioing. */
-    private final FileSystem fs;
+    /**
+     * Versioning file system configuration.
+     */
+    private final FileSystemConfig fsc;
 
-    /** The <code>PersistenceManagerConfig</code> for the versioning */
-    private final BeanConfig pmc;
+    /**
+     * Versioning persistence manager configuration.
+     */
+    private final PersistenceManagerConfig pmc;
 
-    public VersioningConfig(String home, FileSystem fs, BeanConfig pmc) {
+    /**
+     * Creates a versioning configuration object.
+     *
+     * @param home home directory
+     * @param fsc file system configuration
+     * @param pmc persistence manager configuration
+     */
+    public VersioningConfig(
+            String home, FileSystemConfig fsc, PersistenceManagerConfig pmc) {
         this.home = home;
-        this.fs = fs;
+        this.fsc = fsc;
         this.pmc = pmc;
     }
 
+    /**
+     * Initializes the versioning file system.
+     *
+     * @throws ConfigurationException on file system configuration errors
+     */
+    public void init() throws ConfigurationException {
+        fsc.init();
+    }
+
+    /**
+     * Returns the versioning home directory.
+     *
+     * @return versioning home directory
+     */
     public File getHomeDir() {
         return new File(home);
     }
 
     /**
-     * Returns the virtual file system where the workspace stores global state.
+     * Returns the versioning file system implementation.
      *
-     * @return the virtual file system where the workspace stores global state
+     * @return file system implementation
      */
     public FileSystem getFileSystem() {
-        return fs;
+        return fsc.getFileSystem();
     }
 
     /**
-     * Returns the configuration of the persistence manager.
+     * Returns the versioning persistence manager configuration.
      *
-     * @return the <code>PersistenceManagerConfig</code> for this workspace
+     * @return persistence manager configuration
      */
     public PersistenceManagerConfig getPersistenceManagerConfig() {
-        return new PersistenceManagerConfig(pmc);
+        return pmc;
     }
 
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java?view=diff&r1=156417&r2=156418
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java Mon Mar  7 04:26:02 2005
@@ -19,50 +19,77 @@
 import org.apache.jackrabbit.core.fs.FileSystem;
 
 /**
- * A <code>WorkspaceConfig</code> ...
+ * Workspace configuration. This configuration class is used to
+ * create configured workspace objects.
+ * <p>
+ * The contained configuration information are: the home directory and name
+ * of the workspace, and the file system, the persistence manager, and the
+ * search index configuration. The search index is an optional part of the
+ * configuration.
  */
 public class WorkspaceConfig {
 
     /**
-     * workspace home directory
+     * Workspace home directory.
      */
-    private String wspHomeDir;
+    private final String home;
 
     /**
-     * virtual file system where the workspace stores meta data etc.
+     * Workspace name.
      */
-    private FileSystem wspFS;
+    private final String name;
 
     /**
-     * workspace name
+     * Workspace file system configuration.
      */
-    private String wspName;
+    private FileSystemConfig fsc;
 
     /**
-     * configuration for the persistence manager
+     * Workspace persistence manager configuration.
      */
-    private BeanConfig pmc;
+    private PersistenceManagerConfig pmc;
 
     /**
-     * configuration for the search manager
+     * Workspace search index configuration.
      */
-    private SearchConfig searchConfig;
+    private SearchConfig sc;
 
-    public WorkspaceConfig(String home, String name, FileSystem fs, BeanConfig pmc, SearchConfig sc) {
-        this.wspHomeDir = home;
-        this.wspName = name;
-        this.wspFS = fs;
+    /**
+     * Creates a workspace configuration object.
+     *
+     * @param home home directory
+     * @param name workspace name
+     * @param fsc file system configuration
+     * @param pmc persistence manager configuration
+     * @param sc search index configuration
+     */
+    public WorkspaceConfig(
+            String home, String name, FileSystemConfig fsc,
+            PersistenceManagerConfig pmc, SearchConfig sc) {
+        this.home = home;
+        this.name = name;
+        this.fsc = fsc;
         this.pmc = pmc;
-        this.searchConfig = sc;
+        this.sc = sc;
+    }
+
+    /**
+     * Initializes the workspace file system and search index implementations.
+     *
+     * @throws ConfigurationException on initialization errors
+     */
+    public void init() throws ConfigurationException {
+        fsc.init();
+        sc.init();
     }
 
     /**
-     * Returns the home directory of the workspace.
+     * Returns the workspace home directory.
      *
-     * @return the home directory of the workspace
+     * @return workspace home directory
      */
     public String getHomeDir() {
-        return wspHomeDir;
+        return home;
     }
 
     /**
@@ -71,35 +98,35 @@
      * @return the workspace name
      */
     public String getName() {
-        return wspName;
+        return name;
     }
 
     /**
-     * Returns the virtual file system where the workspace stores global state.
+     * Returns the workspace file system implementation.
      *
-     * @return the virtual file system where the workspace stores global state
+     * @return file system implementation
      */
     public FileSystem getFileSystem() {
-        return wspFS;
+        return fsc.getFileSystem();
     }
 
     /**
-     * Returns the configuration of the persistence manager.
+     * Returns the workspace persistence manager configuration.
      *
-     * @return the <code>PersistenceManagerConfig</code> for this workspace
+     * @return persistence manager configuration
      */
     public PersistenceManagerConfig getPersistenceManagerConfig() {
-        return new PersistenceManagerConfig(pmc);
+        return pmc;
     }
 
     /**
-     * Returns the configuration of the search manager.
-     * Returns <code>null</code> if no search manager is configured.
+     * Returns the workspace search index configuration. Returns
+     * <code>null</code> if a search index has not been configured.
      *
-     * @return the <code>SearchConfig</code> for this workspace
+     * @return search index configuration, or <code>null</code>
      */
     public SearchConfig getSearchConfig() {
-        return searchConfig;
+        return sc;
     }
 
 }

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/RepositoryConfigTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/RepositoryConfigTest.java?view=diff&r1=156417&r2=156418
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/RepositoryConfigTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/RepositoryConfigTest.java Mon Mar  7 04:26:02 2005
@@ -29,12 +29,6 @@
  */
 public class RepositoryConfigTest extends TestCase {
 
-    private ConfigurationParser parser;
-
-    protected void setUp() {
-        parser = new ConfigurationParser(new Properties());
-    }
-
     /**
      * Test that a standard repository configuration file is
      * correctly parsed.
@@ -45,7 +39,7 @@
         InputStream xml = getClass().getClassLoader().getResourceAsStream(
                 "org/apache/jackrabbit/core/config/repository.xml");
         RepositoryConfig config =
-            parser.parseRepositoryConfig(new InputSource(xml), "target");
+            RepositoryConfig.create(new InputSource(xml), "target");
 
         assertEquals("target", config.getHomeDir());
         assertEquals("default", config.getDefaultWorkspaceName());

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java?view=diff&r1=156417&r2=156418
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/WorkspaceConfigTest.java Mon Mar  7 04:26:02 2005
@@ -47,6 +47,7 @@
                 "org/apache/jackrabbit/core/config/workspace.xml");
         WorkspaceConfig config =
             parser.parseWorkspaceConfig(new InputSource(xml));
+        config.init();
 
         assertEquals("target", config.getHomeDir());
         assertEquals("default", config.getName());



Mime
View raw message