jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r732728 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ config/ state/
Date Thu, 08 Jan 2009 15:40:13 GMT
Author: jukka
Date: Thu Jan  8 07:40:13 2009
New Revision: 732728

URL: http://svn.apache.org/viewvc?rev=732728&view=rev
Log:
JCR-1438: Replace Config classes with factories 

Replaced ISMLockingConfig with ISMLockingFactory.

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ISMLockingFactory.java
  (with props)
Removed:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/ISMLockingConfig.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/VersioningConfig.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=732728&r1=732727&r2=732728&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
Thu Jan  8 07:40:13 2009
@@ -455,7 +455,7 @@
                 ntReg,
                 dataStore);
 
-        ISMLocking ismLocking = vConfig.getISMLockingConfig().createISMLocking();
+        ISMLocking ismLocking = vConfig.getISMLocking();
 
         return new VersionManagerImpl(pm, fs, ntReg, delegatingDispatcher,
                 VERSION_STORAGE_NODE_ID, SYSTEM_ROOT_NODE_ID, cacheFactory,
@@ -1906,7 +1906,7 @@
                     ntReg,
                     dataStore);
 
-            ISMLocking ismLocking = config.getISMLockingConfig().createISMLocking();
+            ISMLocking ismLocking = config.getISMLocking();
 
             // create item state manager
             try {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java?rev=732728&r1=732727&r2=732728&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfigurationParser.java
Thu Jan  8 07:40:13 2009
@@ -21,6 +21,9 @@
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.jackrabbit.core.fs.FileSystemFactory;
+import org.apache.jackrabbit.core.state.DefaultISMLocking;
+import org.apache.jackrabbit.core.state.ISMLocking;
+import org.apache.jackrabbit.core.state.ISMLockingFactory;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -436,12 +439,15 @@
         SearchConfig sc = tmpParser.parseSearchConfig(root);
 
         // Item state manager locking configuration (optional)
-        ISMLockingConfig ismLockingConfig = tmpParser.parseISMLockingConfig(root);
+        ISMLockingFactory ismLockingFactory =
+            tmpParser.getISMLockingFactory(root);
 
         // workspace specific security configuration
         WorkspaceSecurityConfig workspaceSecurityConfig = tmpParser.parseWorkspaceSecurityConfig(root);
 
-        return new WorkspaceConfig(home, name, clustered, fsf, pmc, sc, ismLockingConfig,
workspaceSecurityConfig);
+        return new WorkspaceConfig(
+                home, name, clustered, fsf, pmc, sc,
+                ismLockingFactory, workspaceSecurityConfig);
     }
 
     /**
@@ -529,7 +535,8 @@
     }
 
     /**
-     * Parses ism locking configuration. ism locking configuration  uses the
+     * Returns an ISM locking factory that creates {@link ISMLocking} instances
+     * based on the given configuration. ISM locking configuration uses the
      * following format:
      * <pre>
      *   &lt;ISMLocking class="..."&gt;
@@ -537,37 +544,35 @@
      *     ...
      *   &lt;/ISMLocking&gt;
      * </pre>
-     * <p/>
+     * <p>
      * The <code>ISMLocking</code> is a
      * {@link #parseBeanConfig(Element,String) bean configuration} element.
-     * <p/>
-     * The ism locking is an optional part of the  workspace configuration. If
-     * the ism locking element is not found, then this method returns
-     * <code>null</code>.
+     * <p>
+     * ISM locking is an optional part of the  workspace configuration. If
+     * the ISM locking element is not found, then the returned factory will
+     * create instances of the {@link DefaultISMLocking} class.
      *
      * @param parent parent of the <code>ISMLocking</code> element
-     * @return search configuration, or <code>null</code>
-     * @throws ConfigurationException if the configuration is broken
+     * @return ISM locking factory
      */
-    protected ISMLockingConfig parseISMLockingConfig(Element parent)
-            throws ConfigurationException {
-        NodeList children = parent.getChildNodes();
-        for (int i = 0; i < children.getLength(); i++) {
-            Node child = children.item(i);
-            if (child.getNodeType() == Node.ELEMENT_NODE
-                    && ISM_LOCKING_ELEMENT.equals(child.getNodeName())) {
-                Element element = (Element) child;
-
-                // ism locking implementation class
-                String className = getAttribute(element, CLASS_ATTRIBUTE);
-
-                // ism locking parameters
-                Properties parameters = parseParameters(element);
-
-                return new ISMLockingConfig(className, parameters);
+    protected ISMLockingFactory getISMLockingFactory(final Element parent) {
+        return new ISMLockingFactory() {
+            public ISMLocking getISMLocking() throws RepositoryException {
+                Element element = getElement(parent, ISM_LOCKING_ELEMENT, false);
+                if (element != null) {
+                    BeanConfig config = parseBeanConfig(element);
+                    try {
+                        return (ISMLocking) config.newInstance();
+                    } catch (ClassCastException e) {
+                        throw new RepositoryException(
+                                "Invalid ISMLocking class: "
+                                + config.getClassName(), e);
+                    }
+                } else {
+                    return new DefaultISMLocking();
+                }
             }
-        }
-        return null;
+        };
     }
 
     /**
@@ -606,9 +611,10 @@
         PersistenceManagerConfig pmc = parsePersistenceManagerConfig(element);
 
         // Item state manager locking configuration (optional)
-        ISMLockingConfig ismLockingConfig = parseISMLockingConfig(element);
+        ISMLockingFactory ismLockingFactory =
+            getISMLockingFactory(element);
 
-        return new VersioningConfig(home, fsf, pmc, ismLockingConfig);
+        return new VersioningConfig(home, fsf, pmc, ismLockingFactory);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/VersioningConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/VersioningConfig.java?rev=732728&r1=732727&r2=732728&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/VersioningConfig.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/VersioningConfig.java
Thu Jan  8 07:40:13 2009
@@ -22,6 +22,8 @@
 
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.FileSystemFactory;
+import org.apache.jackrabbit.core.state.ISMLocking;
+import org.apache.jackrabbit.core.state.ISMLockingFactory;
 
 /**
  * Versioning configuration. This configuration class is used to
@@ -33,7 +35,7 @@
  *
  * @see RepositoryConfig#getVersioningConfig()
  */
-public class VersioningConfig implements FileSystemFactory {
+public class VersioningConfig implements FileSystemFactory, ISMLockingFactory {
 
     /**
      * Versioning home directory.
@@ -51,9 +53,9 @@
     private final PersistenceManagerConfig pmc;
 
     /**
-     * ISM locking configuration
+     * ISM locking factory
      */
-    private final ISMLockingConfig ismLockingConfig;
+    private final ISMLockingFactory ismLockingFactory;
 
     /**
      * Creates a versioning configuration object.
@@ -61,22 +63,16 @@
      * @param home             home directory
      * @param fsf              file system factory
      * @param pmc              persistence manager configuration
-     * @param ismLockingConfig the item state manager locking configuration, if
-     *                         <code>null</code> is passed a default
-     *                         configuration is used.
+     * @param ismLockingFactory the item state manager locking factory
      */
     public VersioningConfig(String home,
                             FileSystemFactory fsf,
                             PersistenceManagerConfig pmc,
-                            ISMLockingConfig ismLockingConfig) {
+                            ISMLockingFactory ismLockingFactory) {
         this.home = home;
         this.fsf = fsf;
         this.pmc = pmc;
-        if (ismLockingConfig != null) {
-            this.ismLockingConfig = ismLockingConfig;
-        } else {
-            this.ismLockingConfig = ISMLockingConfig.createDefaultConfig();
-        }
+        this.ismLockingFactory = ismLockingFactory;
     }
 
     /**
@@ -108,10 +104,13 @@
     }
 
     /**
-     * @return name of the ISM locking configuration
+     * Creates and returns the configured versioning locking strategy.
+     *
+     * @return the configured {@link ISMLocking}
+     * @throws RepositoryException if the locking strategy can not be created
      */
-    public ISMLockingConfig getISMLockingConfig() {
-        return ismLockingConfig;
+    public ISMLocking getISMLocking() throws RepositoryException {
+        return ismLockingFactory.getISMLocking();
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java?rev=732728&r1=732727&r2=732728&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java
Thu Jan  8 07:40:13 2009
@@ -20,6 +20,8 @@
 
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.FileSystemFactory;
+import org.apache.jackrabbit.core.state.ISMLocking;
+import org.apache.jackrabbit.core.state.ISMLockingFactory;
 
 /**
  * Workspace configuration. This configuration class is used to create
@@ -30,7 +32,7 @@
  * the item state manager locking configuration. The search index and the item
  * state manager locking and the security config are optional parts.
  */
-public class WorkspaceConfig implements FileSystemFactory {
+public class WorkspaceConfig implements FileSystemFactory, ISMLockingFactory {
 
     /**
      * Workspace home directory.
@@ -63,9 +65,9 @@
     private SearchConfig sc;
 
     /**
-     * The item state manager locking configuration.
+     * The item state manager locking factory.
      */
-    private ISMLockingConfig ismLockingConfig;
+    private ISMLockingFactory ismLockingFactory;
 
     /**
      * Workspace security configuration. Can be <code>null</code>.
@@ -80,13 +82,12 @@
      * @param fsc file system factory
      * @param pmc persistence manager configuration
      * @param sc search index configuration
-     * @param ismLockingConfig the item state manager locking configuration. If
-     * <code>null</code> is passed, a default configuration is taken.
+     * @param ismLockingFactory the item state manager locking factory
      * @param workspaceSecurityConfig the workspace specific security configuration.
      */
     public WorkspaceConfig(String home, String name, boolean clustered,
                            FileSystemFactory fsf, PersistenceManagerConfig pmc,
-                           SearchConfig sc, ISMLockingConfig ismLockingConfig,
+                           SearchConfig sc, ISMLockingFactory ismLockingFactory,
                            WorkspaceSecurityConfig workspaceSecurityConfig) {
         this.home = home;
         this.name = name;
@@ -94,11 +95,7 @@
         this.fsf = fsf;
         this.pmc = pmc;
         this.sc = sc;
-        if (ismLockingConfig != null) {
-            this.ismLockingConfig = ismLockingConfig;
-        } else {
-            this.ismLockingConfig = ISMLockingConfig.createDefaultConfig();
-        }
+        this.ismLockingFactory = ismLockingFactory;
         this.workspaceSecurityConfig = workspaceSecurityConfig;
     }
 
@@ -131,10 +128,13 @@
     }
 
     /**
-     * @return the configuration for the item state locking.
+     * Creates and returns the configured workspace locking strategy.
+     *
+     * @return the configured {@link ISMLocking}
+     * @throws RepositoryException if the locking strategy can not be created
      */
-    public ISMLockingConfig getISMLockingConfig() {
-        return ismLockingConfig;
+    public ISMLocking getISMLocking() throws RepositoryException {
+        return ismLockingFactory.getISMLocking();
     }
 
     /**

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ISMLockingFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ISMLockingFactory.java?rev=732728&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ISMLockingFactory.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ISMLockingFactory.java
Thu Jan  8 07:40:13 2009
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.state;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Factory interface for creating {@link ISMLocking} instances. Used
+ * to decouple the repository internals from the repository configuration
+ * mechanism.
+ */
+public interface ISMLockingFactory {
+
+    /**
+     * Creates, initializes, and returns an {@link ISMLocking} instance
+     * for use by the repository. Note that no information is passed from
+     * the client, so all required configuration information must be
+     * encapsulated in the factory.
+     *
+     * @return initialized item state locking strategy
+     * @throws RepositoryException if the locking strategy can not be created
+     */
+    ISMLocking getISMLocking() throws RepositoryException;
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ISMLockingFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message