jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r156058 - in incubator/jackrabbit/trunk/src: java/org/apache/jackrabbit/core/config/ test/org/apache/jackrabbit/core/config/
Date Thu, 03 Mar 2005 17:31:46 GMT
Author: jukka
Date: Thu Mar  3 09:31:41 2005
New Revision: 156058

URL: http://svn.apache.org/viewcvs?view=rev&rev=156058
Log:
Refactoring step 3 (JCR-53)
 - Moved workspace.xml parsing to ConfigurationParser
 - Replaced createFileSystem with BeanConfig code
 - Added a TestAll suite for the config package

Added:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/TestAll.java
Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/AbstractConfig.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/AccessManagerConfig.java
    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/PersistenceManagerConfig.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.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/AbstractConfig.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/AbstractConfig.java?view=diff&r1=156057&r2=156058
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/AbstractConfig.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/AbstractConfig.java
Thu Mar  3 09:31:41 2005
@@ -31,9 +31,14 @@
  * <code>AbstractConfig</code> is the superclass of
  * <code>RepositoryConfig</code> and <code>WorkspaceConfig</code>.
  */
-abstract class AbstractConfig implements EntityResolver {
+abstract class AbstractConfig {
     private static Logger log = Logger.getLogger(AbstractConfig.class);
 
+    /**
+     * public id
+     */
+    public static final String PUBLIC_ID = "-//The Apache Software Foundation//DTD Workspace//EN";
+
     public static final String CONFIG_DTD_RESOURCE_PATH =
             "org/apache/jackrabbit/core/config/config.dtd";
 
@@ -44,7 +49,6 @@
     protected static final String NAME_ATTRIB = "name";
     protected static final String VALUE_ATTRIB = "value";
 
-    protected final String configId;
     protected final Document config;
 
     /**
@@ -53,10 +57,20 @@
      * @param is
      */
     protected AbstractConfig(InputSource is) throws RepositoryException {
-        configId = is.getSystemId() == null ? "[???]" : is.getSystemId();
         try {
             SAXBuilder parser = new SAXBuilder();
-            parser.setEntityResolver(this);
+            parser.setEntityResolver(new EntityResolver() {
+                public InputSource resolveEntity(String publicId, String systemId)
+                        throws SAXException, IOException {
+                    if (publicId.equals(PUBLIC_ID)) {
+                        // load dtd resource
+                        return new InputSource(getClass().getClassLoader().getResourceAsStream(CONFIG_DTD_RESOURCE_PATH));
+                    } else {
+                        // use the default behaviour
+                        return null;
+                    }
+                }
+            });
             config = parser.build(is);
         } catch (Exception e) {
             String msg = "error while parsing config file " + is.getSystemId();
@@ -65,10 +79,4 @@
         }
     }
 
-    //-------------------------------------------------------< EntityResolver >
-    /**
-     * @see EntityResolver#resolveEntity(String, String)
-     */
-    public abstract InputSource resolveEntity(String publicId, String systemId)
-            throws SAXException, IOException;
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/AccessManagerConfig.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/AccessManagerConfig.java?view=diff&r1=156057&r2=156058
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/AccessManagerConfig.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/AccessManagerConfig.java
Thu Mar  3 09:31:41 2005
@@ -16,8 +16,6 @@
  */
 package org.apache.jackrabbit.core.config;
 
-import java.util.Properties;
-
 /**
  * A <code>AccessManagerConfig</code> represents the configuration of an
  * <code>AccessManager</code>.
@@ -26,8 +24,8 @@
  */
 public class AccessManagerConfig extends BeanConfig {
 
-    public AccessManagerConfig(String className, Properties properties) {
-        super(className, properties);
+    public AccessManagerConfig(BeanConfig config) {
+        super(config);
     }
 
 }

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=156057&r2=156058
==============================================================================
--- 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
Thu Mar  3 09:31:41 2005
@@ -16,8 +16,14 @@
  */
 package org.apache.jackrabbit.core.config;
 
+import java.util.Iterator;
+import java.util.List;
 import java.util.Properties;
 
+import org.apache.commons.collections.BeanMap;
+import org.apache.jackrabbit.core.fs.FileSystem;
+import org.jdom.Element;
+
 /**
  * Bean configuration class. BeanConfig instances contain the class name
  * and property information required to instantiate a class that conforms
@@ -46,6 +52,10 @@
         this.properties = properties;
     }
 
+    protected BeanConfig(BeanConfig config) {
+        this(config.getClassName(), config.getParameters());
+    }
+
     /**
      * Returns the class name of the configured bean.
      *
@@ -62,6 +72,21 @@
      */
     public Properties getParameters() {
         return properties;
+    }
+
+    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();
+            if (properties.containsKey(name)) {
+                map.put(name, properties.getProperty(name));
+            }
+        }
+        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=156057&r2=156058
==============================================================================
--- 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
Thu Mar  3 09:31:41 2005
@@ -17,23 +17,42 @@
 package org.apache.jackrabbit.core.config;
 
 import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
 import javax.jcr.RepositoryException;
 
-import org.apache.commons.collections.BeanMap;
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.util.Text;
+import org.jdom.Document;
 import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
 
 /**
  * TODO
  */
 public class ConfigurationParser {
 
+    /**
+     * public id
+     */
+    public static final String PUBLIC_ID = "-//The Apache Software Foundation//DTD Workspace//EN";
+
+    public static final String CONFIG_DTD_RESOURCE_PATH =
+            "org/apache/jackrabbit/core/config/config.dtd";
+
+    protected static final String FILE_SYSTEM_ELEMENT = "FileSystem";
+    private static final String PERSISTENCE_MANAGER_ELEMENT = "PersistenceManager";
+    private static final String SEARCH_INDEX_ELEMENT = "SearchIndex";
+
     private static final String CLASS_ATTRIBUTE = "class";
 
     private static final String PARAM_ELEMENT = "param";
@@ -43,47 +62,136 @@
     /** attribute name of home dir */
     private static final String ROOTPATH_ATTRIBUTE = "rootPath";
 
+    /**
+     * wellknown variables (will be replaced with their respective values
+     * whereever they occur within the configuration)
+     */
+    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 Map variables;
+    private Properties variables;
 
-    public ConfigurationParser(Map variables) {
+    public ConfigurationParser(Properties variables) {
         this.variables = variables;
     }
 
     /**
-     * Creates a new <code>PersistenceManagerConfig</code>.
+     * Creates a new <code>WorkspaceConfig</code> instance. The configuration
+     * is read from the specified configuration file.
      *
-     * @param config the config root element for this <code>PersistenceManagerConfig</code>.
+     * @param configFilePath path to the configuration file
+     * @param wspHomeDir     workspace home directory
+     * @return a new <code>WorkspaceConfig</code> instance
+     * @throws RepositoryException If an error occurs
      */
-    public AccessManagerConfig parseAccessManagerConfig(Element config) {
-        // FQN of persistence manager class
-        String className = config.getAttributeValue(CLASS_ATTRIBUTE);
-
-        // read the PersistenceManager properties from the
-        // <param/> elements in the config
-        Properties params = parseParameters(config);
+    public static WorkspaceConfig parseWorkspaceConfig(
+            String configFilePath, String wspHomeDir)
+            throws RepositoryException {
+        try {
+            File config = new File(configFilePath);
+            InputSource is = new InputSource(new FileReader(config));
+            is.setSystemId(config.toURI().toString());
+            return parseWorkspaceConfig(is, wspHomeDir);
+        } catch (IOException ioe) {
+            String msg = "error while reading config file " + configFilePath;
+            throw new RepositoryException(msg, ioe);
+        }
+    }
 
-        return new AccessManagerConfig(className, params);
+    /**
+     * Creates a new <code>WorkspaceConfig</code> instance. The configuration
+     * is read from the specified input source.
+     *
+     * @param is         <code>InputSource</code> where the configuration is
read from
+     * @param wspHomeDir workspace home directory
+     * @return a new <code>WorkspaceConfig</code> instance
+     * @throws RepositoryException If an error occurs
+     */
+    public static WorkspaceConfig parseWorkspaceConfig(
+            InputSource xml, String home)
+            throws RepositoryException {
+        try {
+            SAXBuilder builder = new SAXBuilder();
+            builder.setEntityResolver(new EntityResolver() {
+                public InputSource resolveEntity(String publicId, String systemId)
+                throws SAXException, IOException {
+                    if (publicId.equals(PUBLIC_ID)) {
+                        // load dtd resource
+                        return new InputSource(getClass().getClassLoader().getResourceAsStream(CONFIG_DTD_RESOURCE_PATH));
+                    } else {
+                        // use the default behaviour
+                        return null;
+                    }
+                }
+            });
+            Document config = builder.build(xml);
+
+            Properties variables = new Properties();
+            variables.setProperty(WORKSPACE_HOME_VARIABLE, home);
+            ConfigurationParser parser = new ConfigurationParser(variables);
+            return parser.parseWorkspaceConfig(config);
+        } catch (JDOMException ex) {
+            throw new RepositoryException(ex);
+        } catch (IOException ex) {
+            throw new RepositoryException(ex);
+        }
     }
 
     /**
-     * Creates a new <code>PersistenceManagerConfig</code>.
+     * Initializes this <code>WorkspaceConfig</code> object.
      *
-     * @param config the config root element for this <code>PersistenceManagerConfig</code>.
+     * @param config
+     * @throws RepositoryException
      */
-    public PersistenceManagerConfig parsePersistenceManagerConfig(Element config) {
-        // FQN of persistence manager class
-        String className = config.getAttributeValue(CLASS_ATTRIBUTE);
+    public WorkspaceConfig parseWorkspaceConfig(Document config)
+            throws RepositoryException {
+        try {
+            String wspHomeDir = variables.getProperty(WORKSPACE_HOME_VARIABLE);
 
-        // read the PersistenceManager properties from the
-        // <param/> elements in the config
-        Properties params = parseParameters(config);
+            Element wspElem = config.getRootElement();
+            // name
+            String wspName = wspElem.getAttributeValue(NAME_ATTRIBUTE);
+            if (wspName == null) {
+                // init with wsp home dirname
+                wspName = new File(wspHomeDir).getName();
+            } else {
+                wspName = replaceVariables(wspName);
+            }
 
-        return new PersistenceManagerConfig(className, params);
+            // set name variable
+            Properties newVariables = new Properties(variables);
+            newVariables.put(WORKSPACE_NAME_VARIABLE, wspName);
+            ConfigurationParser parser = new ConfigurationParser(newVariables);
+
+            // file system
+            BeanConfig fsc = parser.parseBeanConfig(wspElem, FILE_SYSTEM_ELEMENT);
+            FileSystem wspFS = (FileSystem) fsc.newInstance();
+
+            // persistence manager config
+            BeanConfig pmc =
+                parser.parseBeanConfig(wspElem, PERSISTENCE_MANAGER_ELEMENT);
+
+            // search config (optional)
+            Element searchElem = wspElem.getChild(SEARCH_INDEX_ELEMENT);
+            SearchConfig sc = null;
+            if (searchElem != null) {
+                sc = parser.parseSearchConfig(searchElem);
+            }
+            
+            return new WorkspaceConfig(wspHomeDir, wspName, wspFS, pmc, sc);
+        } catch (ClassNotFoundException ex) {
+            throw new RepositoryException(ex);
+        } catch (InstantiationException ex) {
+            throw new RepositoryException(ex);
+        } catch (IllegalAccessException ex) {
+            throw new RepositoryException(ex);
+        } catch (ClassCastException ex) {
+            throw new RepositoryException(ex);
+        }
     }
 
     /**
@@ -93,18 +201,28 @@
      *  <code>SearchConfig</code>.
      */
     public SearchConfig parseSearchConfig(Element config) throws RepositoryException {
-        // create FileSystem
-        Element fsElement = config.getChild(AbstractConfig.FILE_SYSTEM_ELEMENT);
-        FileSystem fs = createFileSystem(fsElement);
-
-        // handler class name
-        String handlerClassName = config.getAttributeValue(CLASS_ATTRIBUTE,
-                DEFAULT_QUERY_HANDLER);
-
-        // gather params
-        Properties params = parseParameters(config);
-
-        return new SearchConfig(fs, handlerClassName, params);
+        try {
+            // create FileSystem
+            BeanConfig fsc = parseBeanConfig(config, FILE_SYSTEM_ELEMENT);
+            FileSystem fs = (FileSystem) fsc.newInstance();
+
+            // handler class name
+            String handlerClassName = config.getAttributeValue(CLASS_ATTRIBUTE,
+                    DEFAULT_QUERY_HANDLER);
+
+            // gather params
+            Properties params = parseParameters(config);
+
+            return new SearchConfig(fs, handlerClassName, params);
+        } catch (ClassNotFoundException ex) {
+            throw new RepositoryException(ex);
+        } catch (InstantiationException ex) {
+            throw new RepositoryException(ex);
+        } catch (IllegalAccessException ex) {
+            throw new RepositoryException(ex);
+        } catch (ClassCastException ex) {
+            throw new RepositoryException(ex);
+        }
     }
 
     /**
@@ -115,19 +233,39 @@
      *  <code>SearchConfig</code>.
      */
     public VersioningConfig parseVersioningConfig(Element config) throws RepositoryException
{
-        // home dir
-        File homeDir = new File(replaceVariables(config.getAttributeValue(ROOTPATH_ATTRIBUTE)));
+        try {
+            // home dir
+            File homeDir = new File(replaceVariables(config.getAttributeValue(ROOTPATH_ATTRIBUTE)));
 
-        // create FileSystem
-        Element fsElement = config.getChild(AbstractConfig.FILE_SYSTEM_ELEMENT);
-        FileSystem fs = createFileSystem(fsElement);
-
-        // persistence manager config
-        Element pmElem = config.getChild(WorkspaceConfig.PERSISTENCE_MANAGER_ELEMENT);
-        PersistenceManagerConfig pmConfig =
-            parsePersistenceManagerConfig(pmElem);
+            // create FileSystem
+            BeanConfig fsc = parseBeanConfig(config, FILE_SYSTEM_ELEMENT);
+            FileSystem fs = (FileSystem) fsc.newInstance();
+
+            // persistence manager config
+            BeanConfig pmc = parseBeanConfig(config, PERSISTENCE_MANAGER_ELEMENT);
+
+            return new VersioningConfig(homeDir, fs, pmc);
+        } catch (ClassNotFoundException ex) {
+            throw new RepositoryException(ex);
+        } catch (InstantiationException ex) {
+            throw new RepositoryException(ex);
+        } catch (IllegalAccessException ex) {
+            throw new RepositoryException(ex);
+        } catch (ClassCastException ex) {
+            throw new RepositoryException(ex);
+        }
+    }
 
-        return new VersioningConfig(homeDir, fs, pmConfig);
+    public BeanConfig parseBeanConfig(Element parent, String name)
+            throws RepositoryException {
+        Element element = parent.getChild(name);
+        if (element != null) {
+            String className = element.getAttributeValue(CLASS_ATTRIBUTE);
+            Properties properties = parseParameters(element);
+            return new BeanConfig(className, properties);
+        } else {
+            return null;
+        }
     }
 
     public Properties parseParameters(Element element) {
@@ -143,43 +281,6 @@
         }
 
         return parameters;
-    }
-
-    /**
-     * Creates a {@link org.apache.jackrabbit.core.fs.FileSystem} instance
-     * based on the config <code>fsConfig</code>.
-     *
-     * @param fsConfig  a {@link #FILE_SYSTEM_ELEMENT}.
-     * @return a {@link org.apache.jackrabbit.core.fs.FileSystem} instance.
-     * @throws RepositoryException if an error occurs while creating the
-     *                             {@link org.apache.jackrabbit.core.fs.FileSystem}.
-     */
-    public FileSystem createFileSystem(Element fsConfig) throws RepositoryException {
-        FileSystem fs;
-        String className = "";
-        try {
-            // create the file system object
-            className = fsConfig.getAttributeValue(CLASS_ATTRIBUTE);
-            Class c = Class.forName(className);
-            fs = (FileSystem) c.newInstance();
-
-            // set the properties of the file system object from the
-            // param elements in the config
-            BeanMap bm = new BeanMap(fs);
-            List paramList = fsConfig.getChildren(PARAM_ELEMENT);
-            for (Iterator i = paramList.iterator(); i.hasNext();) {
-                Element param = (Element) i.next();
-                String paramName = param.getAttributeValue(NAME_ATTRIBUTE);
-                String paramValue = param.getAttributeValue(VALUE_ATTRIBUTE);
-                // replace variables in param value
-                bm.put(paramName, replaceVariables(paramValue));
-            }
-            fs.init();
-        } catch (Exception e) {
-            String msg = "Cannot instantiate implementing class " + className;
-            throw new RepositoryException(msg, e);
-        }
-        return fs;
     }
 
     /**

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/PersistenceManagerConfig.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/PersistenceManagerConfig.java?view=diff&r1=156057&r2=156058
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/PersistenceManagerConfig.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/PersistenceManagerConfig.java
Thu Mar  3 09:31:41 2005
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.core.config;
 
-import java.util.Properties;
 
 /**
  * A <code>PersistenceManagerConfig</code> represents the configuration of a
@@ -26,8 +25,8 @@
  */
 public class PersistenceManagerConfig extends BeanConfig {
 
-    public PersistenceManagerConfig(String className, Properties properties) {
-        super(className, properties);
+    public PersistenceManagerConfig(BeanConfig config) {
+        super(config);
     }
 
 }

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=156057&r2=156058
==============================================================================
--- 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
Thu Mar  3 09:31:41 2005
@@ -32,6 +32,7 @@
 import java.io.IOException;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.Properties;
 
 /**
  * A <code>RepositoryConfig</code> ...
@@ -70,7 +71,7 @@
     /**
      * map of variable names and their respective values
      */
-    private final HashMap vars;
+    private final Properties vars;
 
     /**
      * map of workspace names and workspace configurations
@@ -107,7 +108,7 @@
     /**
      * configuration for the access manager
      */
-    private AccessManagerConfig amConfig;
+    private BeanConfig amConfig;
 
     /**
      * the versioning config
@@ -127,7 +128,7 @@
         this.repHomeDir = repHomeDir;
         wspConfigs = new HashMap();
         // initialize variables
-        vars = new HashMap();
+        vars = new Properties();
         vars.put(REPOSITORY_HOME_VARIABLE, repHomeDir);
         // read config
         init(config);
@@ -140,63 +141,75 @@
      * @throws RepositoryException
      */
     protected void init(Document config) throws RepositoryException {
-        ConfigurationParser parser = new ConfigurationParser(vars);
+        try {
+            Element root = config.getRootElement();
+            ConfigurationParser parser = new ConfigurationParser(vars);
 
-        // file system
-        Element fsConfig = config.getRootElement().getChild(FILE_SYSTEM_ELEMENT);
-        repFS = parser.createFileSystem(fsConfig);
-
-        // security & access manager config
-        Element secEleme = config.getRootElement().getChild(SECURITY_ELEMENT);
-        appName = secEleme.getAttributeValue(APP_NAME_ATTRIB);
-        Element amElem = secEleme.getChild(ACCESS_MANAGER_ELEMENT);
-        amConfig = parser.parseAccessManagerConfig(amElem);
-
-        // workspaces
-        Element wspsElem = config.getRootElement().getChild(WORKSPACES_ELEMENT);
-        wspConfigRootDir = parser.replaceVariables(wspsElem.getAttributeValue(ROOT_PATH_ATTRIB));
-        defaultWspName = parser.replaceVariables(wspsElem.getAttributeValue(DEFAULT_WORKSPACE_ATTRIB));
-
-        // load wsp configs
-        File wspRoot = new File(wspConfigRootDir);
-        if (!wspRoot.exists()) {
-            wspRoot.mkdir();
-        }
-        File[] files = wspRoot.listFiles();
-        if (files == null) {
-            String msg = "invalid repsitory home directory";
-            log.debug(msg);
-            throw new RepositoryException(msg);
-        }
-        for (int i = 0; i < files.length; i++) {
-            // check if <subfolder>/workspace.xml exists
-            File configFile = new File(files[i], WorkspaceConfig.CONFIG_FILE_NAME);
-            if (configFile.isFile()) {
-                // create workspace config
-                WorkspaceConfig wspConfig = WorkspaceConfig.create(configFile.getPath(),
configFile.getParent());
-                String wspName = wspConfig.getName();
-                if (wspConfigs.containsKey(wspName)) {
-                    String msg = "duplicate workspace name: " + wspName;
-                    log.debug(msg);
-                    throw new RepositoryException(msg);
-                }
-                wspConfigs.put(wspName, wspConfig);
+            // file system
+            BeanConfig fsc = parser.parseBeanConfig(root, FILE_SYSTEM_ELEMENT);
+            repFS = (FileSystem) fsc.newInstance();
+
+            // security & access manager config
+            Element secEleme = root.getChild(SECURITY_ELEMENT);
+            appName = secEleme.getAttributeValue(APP_NAME_ATTRIB);
+            amConfig = parser.parseBeanConfig(secEleme, ACCESS_MANAGER_ELEMENT);
+
+            // workspaces
+            Element wspsElem = root.getChild(WORKSPACES_ELEMENT);
+            wspConfigRootDir = parser.replaceVariables(wspsElem.getAttributeValue(ROOT_PATH_ATTRIB));
+            defaultWspName = parser.replaceVariables(wspsElem.getAttributeValue(DEFAULT_WORKSPACE_ATTRIB));
+
+            // load wsp configs
+            File wspRoot = new File(wspConfigRootDir);
+            if (!wspRoot.exists()) {
+                wspRoot.mkdir();
             }
-        }
-        if (wspConfigs.isEmpty()) {
-            // create initial default workspace
-            createWorkspaceConfig(defaultWspName);
-        } else {
-            if (!wspConfigs.containsKey(defaultWspName)) {
-                String msg = "no configuration found for default workspace: " + defaultWspName;
+            File[] files = wspRoot.listFiles();
+            if (files == null) {
+                String msg = "invalid repsitory home directory";
                 log.debug(msg);
                 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
+                    WorkspaceConfig wspConfig =
+                        ConfigurationParser.parseWorkspaceConfig(
+                                configFile.getPath(), configFile.getParent());
+                    String wspName = wspConfig.getName();
+                    if (wspConfigs.containsKey(wspName)) {
+                        String msg = "duplicate workspace name: " + wspName;
+                        log.debug(msg);
+                        throw new RepositoryException(msg);
+                    }
+                    wspConfigs.put(wspName, wspConfig);
+                }
+            }
+            if (wspConfigs.isEmpty()) {
+                // create initial default workspace
+                createWorkspaceConfig(defaultWspName);
+            } else {
+                if (!wspConfigs.containsKey(defaultWspName)) {
+                    String msg = "no configuration found for default workspace: " + defaultWspName;
+                    log.debug(msg);
+                    throw new RepositoryException(msg);
+                }
+            }
 
-        // load versioning config
-        Element vElement = config.getRootElement().getChild(VERSIONING_ELEMENT);
-        vConfig = parser.parseVersioningConfig(vElement);
+            // load versioning config
+            Element vElement = config.getRootElement().getChild(VERSIONING_ELEMENT);
+            vConfig = parser.parseVersioningConfig(vElement);
+        } catch (ClassNotFoundException ex) {
+            throw new RepositoryException(ex);
+        } catch (InstantiationException ex) {
+            throw new RepositoryException(ex);
+        } catch (IllegalAccessException ex) {
+            throw new RepositoryException(ex);
+        } catch (ClassCastException ex) {
+            throw new RepositoryException(ex);
+        }
     }
 
     /**
@@ -316,7 +329,7 @@
      * @return an <code>AccessManagerConfig</code> object
      */
     public AccessManagerConfig getAccessManagerConfig() {
-        return amConfig;
+        return new AccessManagerConfig(amConfig);
     }
 
     /**
@@ -351,7 +364,7 @@
 */
         Document doc = new Document(wspCongigElem);
         XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
-        File configFile = new File(wspFolder, WorkspaceConfig.CONFIG_FILE_NAME);
+        File configFile = new File(wspFolder, "workspace.xml");
         FileOutputStream fos = null;
         try {
             fos = new FileOutputStream(configFile);
@@ -371,23 +384,11 @@
         }
 
         // create workspace config object
-        WorkspaceConfig wspConfig = WorkspaceConfig.create(configFile.getPath(), configFile.getParent());
+        WorkspaceConfig wspConfig =
+            ConfigurationParser.parseWorkspaceConfig(
+                    configFile.getPath(), configFile.getParent());
         wspConfigs.put(name, wspConfig);
         return wspConfig;
     }
 
-    //-------------------------------------------------------< EntityResolver >
-    /**
-     * @see org.xml.sax.EntityResolver#resolveEntity(String, String)
-     */
-    public InputSource resolveEntity(String publicId, String systemId)
-            throws SAXException, IOException {
-        if (publicId.equals(PUBLIC_ID)) {
-            // load dtd resource
-            return new InputSource(getClass().getClassLoader().getResourceAsStream(CONFIG_DTD_RESOURCE_PATH));
-        } else {
-            // use the default behaviour
-            return null;
-        }
-    }
 }

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=156057&r2=156058
==============================================================================
--- 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
Thu Mar  3 09:31:41 2005
@@ -32,14 +32,14 @@
     private final FileSystem fs;
 
     /** The <code>PersistenceManagerConfig</code> for the versioning */
-    private final PersistenceManagerConfig pmConfig;
+    private final BeanConfig pmc;
 
-    public VersioningConfig(File homeDir, FileSystem fs, PersistenceManagerConfig pmc) {
+    public VersioningConfig(File homeDir, FileSystem fs, BeanConfig pmc) {
         this.homeDir = homeDir;
         this.fs = fs;
-        this.pmConfig = pmc;
+        this.pmc = pmc;
     }
-    
+
     /**
      * Returns the virtual file system where the workspace stores global state.
      *
@@ -55,7 +55,7 @@
      * @return the <code>PersistenceManagerConfig</code> for this workspace
      */
     public PersistenceManagerConfig getPersistenceManagerConfig() {
-        return pmConfig;
+        return new PersistenceManagerConfig(pmc);
     }
 
     public File getHomeDir() {

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=156057&r2=156058
==============================================================================
--- 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
Thu Mar  3 09:31:41 2005
@@ -17,46 +17,11 @@
 package org.apache.jackrabbit.core.config;
 
 import org.apache.jackrabbit.core.fs.FileSystem;
-import org.apache.log4j.Logger;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import javax.jcr.RepositoryException;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Properties;
 
 /**
  * A <code>WorkspaceConfig</code> ...
  */
-public class WorkspaceConfig extends AbstractConfig {
-    private static Logger log = Logger.getLogger(WorkspaceConfig.class);
-
-    /**
-     * name of workspace configuration file
-     */
-    public static final String CONFIG_FILE_NAME = "workspace.xml";
-
-    /**
-     * public id
-     */
-    public static final String PUBLIC_ID = "-//The Apache Software Foundation//DTD Workspace//EN";
-
-    static final String PERSISTENCE_MANAGER_ELEMENT = "PersistenceManager";
-    private static final String SEARCH_INDEX_ELEMENT = "SearchIndex";
-
-    /**
-     * wellknown variables (will be replaced with their respective values
-     * whereever they occur within the configuration)
-     */
-    public static final String WORKSPACE_HOME_VARIABLE = "${wsp.home}";
-    public static final String WORKSPACE_NAME_VARIABLE = "${wsp.name}";
-
-    private final Properties vars;
+public class WorkspaceConfig {
 
     /**
      * workspace home directory
@@ -76,103 +41,19 @@
     /**
      * configuration for the persistence manager
      */
-    private PersistenceManagerConfig pmConfig;
+    private BeanConfig pmc;
 
     /**
      * configuration for the search manager
      */
     private SearchConfig searchConfig;
 
-    /**
-     * private constructor.
-     *
-     * @param is
-     * @param wspHomeDir
-     * @throws RepositoryException
-     */
-    private WorkspaceConfig(InputSource is, String wspHomeDir)
-            throws RepositoryException {
-        super(is);
-        this.wspHomeDir = wspHomeDir;
-        // initialize variables
-        vars = new Properties();
-        vars.put(WORKSPACE_HOME_VARIABLE, wspHomeDir);
-        // read config
-        init(config);
-    }
-
-    /**
-     * Initializes this <code>WorkspaceConfig</code> object.
-     *
-     * @param config
-     * @throws RepositoryException
-     */
-    protected void init(Document config) throws RepositoryException {
-        Element wspElem = config.getRootElement();
-        // name
-        wspName = wspElem.getAttributeValue(NAME_ATTRIB);
-        if (wspName == null) {
-            // init with wsp home dirname
-            wspName = new File(wspHomeDir).getName();
-        } else {
-            ConfigurationParser parser = new ConfigurationParser(vars);
-            wspName = parser.replaceVariables(wspName);
-        }
-
-        // set name variable
-        vars.put(WORKSPACE_NAME_VARIABLE, wspName);
-        ConfigurationParser parser = new ConfigurationParser(vars);
-
-        // file system
-        Element fsElem = wspElem.getChild(FILE_SYSTEM_ELEMENT);
-        wspFS = parser.createFileSystem(fsElem);
-
-        // persistence manager config
-        Element pmElem = wspElem.getChild(PERSISTENCE_MANAGER_ELEMENT);
-        pmConfig = parser.parsePersistenceManagerConfig(pmElem);
-
-        // search config (optional)
-        Element searchElem = wspElem.getChild(SEARCH_INDEX_ELEMENT);
-        if (searchElem != null) {
-            searchConfig = parser.parseSearchConfig(searchElem);
-        }
-    }
-
-    /**
-     * Creates a new <code>WorkspaceConfig</code> instance. The configuration
-     * is read from the specified configuration file.
-     *
-     * @param configFilePath path to the configuration file
-     * @param wspHomeDir     workspace home directory
-     * @return a new <code>WorkspaceConfig</code> instance
-     * @throws RepositoryException If an error occurs
-     */
-    public static WorkspaceConfig create(String configFilePath, String wspHomeDir)
-            throws RepositoryException {
-        try {
-            File config = new File(configFilePath);
-            InputSource is = new InputSource(new FileReader(config));
-            is.setSystemId(config.toURI().toString());
-            return new WorkspaceConfig(is, wspHomeDir);
-        } catch (IOException ioe) {
-            String msg = "error while reading config file " + configFilePath;
-            log.debug(msg);
-            throw new RepositoryException(msg, ioe);
-        }
-    }
-
-    /**
-     * Creates a new <code>WorkspaceConfig</code> instance. The configuration
-     * is read from the specified input source.
-     *
-     * @param is         <code>InputSource</code> where the configuration is
read from
-     * @param wspHomeDir workspace home directory
-     * @return a new <code>WorkspaceConfig</code> instance
-     * @throws RepositoryException If an error occurs
-     */
-    public static WorkspaceConfig create(InputSource is, String wspHomeDir)
-            throws RepositoryException {
-        return new WorkspaceConfig(is, wspHomeDir);
+    public WorkspaceConfig(String home, String name, FileSystem fs, BeanConfig pmc, SearchConfig
sc) {
+        this.wspHomeDir = home;
+        this.wspName = name;
+        this.wspFS = fs;
+        this.pmc = pmc;
+        this.searchConfig = sc;
     }
 
     /**
@@ -208,7 +89,7 @@
      * @return the <code>PersistenceManagerConfig</code> for this workspace
      */
     public PersistenceManagerConfig getPersistenceManagerConfig() {
-        return pmConfig;
+        return new PersistenceManagerConfig(pmc);
     }
 
     /**
@@ -221,18 +102,4 @@
         return searchConfig;
     }
 
-    //------------------------------------------------------< EntityResolver >
-    /**
-     * @see org.xml.sax.EntityResolver#resolveEntity(String, String)
-     */
-    public InputSource resolveEntity(String publicId, String systemId)
-            throws SAXException, IOException {
-        if (publicId.equals(PUBLIC_ID)) {
-            // load dtd resource
-            return new InputSource(getClass().getClassLoader().getResourceAsStream(CONFIG_DTD_RESOURCE_PATH));
-        } else {
-            // use the default behaviour
-            return null;
-        }
-    }
 }

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=156057&r2=156058
==============================================================================
--- 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
Thu Mar  3 09:31:41 2005
@@ -38,11 +38,11 @@
         InputStream xml = getClass().getClassLoader().getResourceAsStream(
                 "org/apache/jackrabbit/core/config/repository.xml");
         RepositoryConfig config =
-            RepositoryConfig.create(new InputSource(xml), "foo");
+            RepositoryConfig.create(new InputSource(xml), "target");
 
-        assertEquals("foo", config.getHomeDir());
+        assertEquals("target", config.getHomeDir());
         assertEquals("default", config.getDefaultWorkspaceName());
-        assertEquals("foo/workspaces", config.getWorkspacesConfigRootDir());
+        assertEquals("target/workspaces", config.getWorkspacesConfigRootDir());
         assertEquals("Jackrabbit", config.getAppName());
 
         AccessManagerConfig amc = config.getAccessManagerConfig();
@@ -52,7 +52,7 @@
         assertTrue(amc.getParameters().isEmpty());
 
         VersioningConfig vc = config.getVersioningConfig();
-        assertEquals(new File("foo/version"), vc.getHomeDir());
+        assertEquals(new File("target/version"), vc.getHomeDir());
         assertEquals(
                 "org.apache.jackrabbit.core.state.obj.ObjectPersistenceManager",
                 vc.getPersistenceManagerConfig().getClassName());

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/TestAll.java?view=auto&rev=156058
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/TestAll.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/TestAll.java Thu
Mar  3 09:31:41 2005
@@ -0,0 +1,45 @@
+/*
+ * 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 junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Collects all test classes setting up test data in the workspace. This test
+ * data is specific to Jackrabbit and will probably not work in other
+ * implementations.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a <code>Test</code> suite that executes all tests inside this
+     * package.
+     *
+     * @return a <code>Test</code> suite that executes all tests inside this
+     *         package.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("Setup data for tests");
+
+        suite.addTestSuite(RepositoryConfigTest.class);
+        suite.addTestSuite(WorkspaceConfigTest.class);
+
+        return suite;
+    }
+}

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=156057&r2=156058
==============================================================================
--- 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
Thu Mar  3 09:31:41 2005
@@ -36,10 +36,10 @@
     public void testWorkspaceXml() throws Exception {
         InputStream xml = getClass().getClassLoader().getResourceAsStream(
                 "org/apache/jackrabbit/core/config/workspace.xml");
-        WorkspaceConfig config =
-            WorkspaceConfig.create(new InputSource(xml), "foo");
+        WorkspaceConfig config = ConfigurationParser.parseWorkspaceConfig(
+                new InputSource(xml), "target");
 
-        assertEquals("foo", config.getHomeDir());
+        assertEquals("target", config.getHomeDir());
         assertEquals("default", config.getName());
 
         PersistenceManagerConfig pmc = config.getPersistenceManagerConfig();



Mime
View raw message