jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r106580 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: . config state state/mem state/obj state/xml
Date Thu, 25 Nov 2004 16:17:37 GMT
Author: stefan
Date: Thu Nov 25 08:17:37 2004
New Revision: 106580

URL: http://svn.apache.org/viewcvs?view=rev&rev=106580
Log:
- refactored WorkspaceConfig and cleaned-up per-workspace objects 
  held in RepositoryImpl
- added PersistenceManagerConfig, RepositoryImpl.WorkspaceInfo, PMContext
- changed PersistenceManager initialization
Added:
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/PersistenceManagerConfig.java
  (contents, props changed)
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PMContext.java   (contents,
props changed)
Modified:
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistenceManager.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/mem/InMemPersistenceManager.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java?view=diff&rev=106580&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java&r1=106579&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java&r2=106580
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java	Thu
Nov 25 08:17:37 2004
@@ -15,7 +15,9 @@
  */
 package org.apache.jackrabbit.core;
 
+import org.apache.commons.collections.BeanMap;
 import org.apache.commons.collections.ReferenceMap;
+import org.apache.jackrabbit.core.config.PersistenceManagerConfig;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
 import org.apache.jackrabbit.core.config.WorkspaceConfig;
 import org.apache.jackrabbit.core.fs.BasedFileSystem;
@@ -24,10 +26,7 @@
 import org.apache.jackrabbit.core.fs.FileSystemResource;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.observation.ObservationManagerFactory;
-import org.apache.jackrabbit.core.state.ItemStateException;
-import org.apache.jackrabbit.core.state.PersistentItemStateManager;
-import org.apache.jackrabbit.core.state.PersistentItemStateProvider;
-import org.apache.jackrabbit.core.state.ReferenceManager;
+import org.apache.jackrabbit.core.state.*;
 import org.apache.jackrabbit.core.state.tx.TransactionManager;
 import org.apache.jackrabbit.core.state.tx.XASessionImpl;
 import org.apache.jackrabbit.core.util.uuid.UUID;
@@ -41,6 +40,7 @@
 import java.io.*;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Properties;
 
 /**
@@ -95,31 +95,10 @@
     // sub file system where the repository stores versions
     private final FileSystem versionStore;
 
-    // map of workspace names and workspace configurations
-    private final HashMap wspConfigs = new HashMap();
-
     /**
-     * map of workspace names and workspace item state managers
-     * (might be shared among multiple workspace instances representing
-     * the same named workspace, i.e. the same physical storage)
+     * map of workspace names and <code>WorkspaceInfo<code>s.
      */
-    private final HashMap wspStateMgrs = new HashMap();
-
-    /**
-     * map of workspace names and workspace reference managers
-     * (might be shared among multiple workspace instances representing
-     * the same named workspace, i.e. the same physical storage)
-     */
-    private final HashMap wspRefMgrs = new HashMap();
-
-    // map of workspace names and observation managers
-    private final HashMap wspObsMgrFactory = new HashMap();
-
-    // map of search managers
-    private final HashMap wspSearchMgrs = new HashMap();
-
-    // map of workspace names and system sessions
-    private final HashMap wspSystemSessions = new HashMap();
+    private final HashMap wspInfos = new HashMap();
 
     /**
      * active sessions (weak references)
@@ -271,7 +250,8 @@
         Iterator iter = repConfig.getWorkspaceConfigs().iterator();
         while (iter.hasNext()) {
             WorkspaceConfig config = (WorkspaceConfig) iter.next();
-            wspConfigs.put(config.getName(), config);
+            WorkspaceInfo info = new WorkspaceInfo(config);
+            wspInfos.put(config.getName(), info);
         }
 
         nsReg = new NamespaceRegistryImpl(new BasedFileSystem(repStore, "/namespaces"));
@@ -289,7 +269,7 @@
 
         // check system root node of system workspace
         // (for now, we just create a system root node in all workspaces)
-        Iterator wspNames = wspConfigs.keySet().iterator();
+        Iterator wspNames = wspInfos.keySet().iterator();
         while (wspNames.hasNext()) {
             String wspName = (String) wspNames.next();
             NodeImpl rootNode = (NodeImpl) getSystemSession(wspName).getRootNode();
@@ -324,9 +304,9 @@
 
         // get the system session for every defined workspace and
         // register as an event listener
-        iter = wspConfigs.values().iterator();
+        iter = wspInfos.values().iterator();
         while (iter.hasNext()) {
-            String wspName = ((WorkspaceConfig) iter.next()).getName();
+            String wspName = ((WorkspaceInfo) iter.next()).getName();
             Session s = getSystemSession(wspName);
             s.getWorkspace().getObservationManager().addEventListener(this,
                     Event.NODE_ADDED | Event.NODE_REMOVED
@@ -418,7 +398,7 @@
      * @return the names of all workspaces of this repository.
      */
     protected String[] getWorkspaceNames() {
-        return (String[]) wspConfigs.keySet().toArray(new String[wspConfigs.keySet().size()]);
+        return (String[]) wspInfos.keySet().toArray(new String[wspInfos.keySet().size()]);
     }
 
     /**
@@ -429,14 +409,14 @@
      *                             already exists or if another error occurs
      */
     public void createWorkspace(String workspaceName) throws RepositoryException {
-        if (wspConfigs.containsKey(workspaceName)) {
+        if (wspInfos.containsKey(workspaceName)) {
             throw new RepositoryException("workspace '" + workspaceName + "' already exists.");
         }
 
         // create the workspace configuration
-        repConfig.createWorkspaceConfig(workspaceName);
-        // add new configuration to map of workspace configs
-        wspConfigs.put(workspaceName, repConfig.getWorkspaceConfig(workspaceName));
+        WorkspaceConfig config = repConfig.createWorkspaceConfig(workspaceName);
+        WorkspaceInfo info = new WorkspaceInfo(config);
+        wspInfos.put(workspaceName, info);
     }
 
     PersistentItemStateProvider getWorkspaceStateManager(String workspaceName)
@@ -446,28 +426,11 @@
             throw new IllegalStateException("repository instance has been shut down");
         }
 
-        WorkspaceConfig wspConfig = (WorkspaceConfig) wspConfigs.get(workspaceName);
-        if (wspConfig == null) {
+        WorkspaceInfo wspInfo = (WorkspaceInfo) wspInfos.get(workspaceName);
+        if (wspInfo == null) {
             throw new NoSuchWorkspaceException(workspaceName);
         }
-
-        synchronized (wspStateMgrs) {
-            // get/create per named workspace (i.e. per physical storage) item state manager
-            PersistentItemStateProvider stateMgr =
-                    (PersistentItemStateProvider) wspStateMgrs.get(workspaceName);
-            if (stateMgr == null) {
-                // create state manager
-                try {
-                    stateMgr = new PersistentItemStateManager(wspConfig.getPersistenceManager(),
rootNodeUUID, ntReg);
-                } catch (ItemStateException ise) {
-                    String msg = "failed to instantiate the persistent state manager";
-                    log.error(msg, ise);
-                    throw new RepositoryException(msg, ise);
-                }
-                wspStateMgrs.put(workspaceName, stateMgr);
-            }
-            return stateMgr;
-        }
+        return wspInfo.getItemStateProvider();
     }
 
     ReferenceManager getWorkspaceReferenceManager(String workspaceName)
@@ -477,22 +440,11 @@
             throw new IllegalStateException("repository instance has been shut down");
         }
 
-        WorkspaceConfig wspConfig = (WorkspaceConfig) wspConfigs.get(workspaceName);
-        if (wspConfig == null) {
+        WorkspaceInfo wspInfo = (WorkspaceInfo) wspInfos.get(workspaceName);
+        if (wspInfo == null) {
             throw new NoSuchWorkspaceException(workspaceName);
         }
-
-        synchronized (wspRefMgrs) {
-            ReferenceManager refMgr
-                    = (ReferenceManager) wspRefMgrs.get(workspaceName);
-            if (refMgr == null) {
-                // create reference mgr that uses the perstistence mgr configured
-                // in the workspace definition
-                refMgr = new ReferenceManager(wspConfig.getPersistenceManager());
-                wspRefMgrs.put(workspaceName, refMgr);
-            }
-            return refMgr;
-        }
+        return wspInfo.getReferenceManager();
     }
 
     ObservationManagerFactory getObservationManagerFactory(String workspaceName)
@@ -502,19 +454,11 @@
             throw new IllegalStateException("repository instance has been shut down");
         }
 
-        if (!wspConfigs.containsKey(workspaceName)) {
+        WorkspaceInfo wspInfo = (WorkspaceInfo) wspInfos.get(workspaceName);
+        if (wspInfo == null) {
             throw new NoSuchWorkspaceException(workspaceName);
         }
-
-        synchronized (wspObsMgrFactory) {
-            ObservationManagerFactory obsMgr
-                    = (ObservationManagerFactory) wspObsMgrFactory.get(workspaceName);
-            if (obsMgr == null) {
-                obsMgr = new ObservationManagerFactory();
-                wspObsMgrFactory.put(workspaceName, obsMgr);
-            }
-            return obsMgr;
-        }
+        return wspInfo.getObservationManagerFactory();
     }
 
     /**
@@ -537,29 +481,11 @@
             throw new IllegalStateException("repository instance has been shut down");
         }
 
-        WorkspaceConfig wspConfig = (WorkspaceConfig) wspConfigs.get(workspaceName);
-        if (wspConfig == null) {
+        WorkspaceInfo wspInfo = (WorkspaceInfo) wspInfos.get(workspaceName);
+        if (wspInfo == null) {
             throw new NoSuchWorkspaceException(workspaceName);
         }
-
-        synchronized (wspSearchMgrs) {
-            SearchManager searchMgr
-                    = (SearchManager) wspSearchMgrs.get(workspaceName);
-            if (searchMgr == null) {
-                try {
-                    if (wspConfig.getSearchConfig() == null) {
-                        // no search index configured
-                        return null;
-                    }
-                    SystemSession s = getSystemSession(workspaceName);
-                    searchMgr = new SearchManager(s, wspConfig.getSearchConfig());
-                } catch (IOException e) {
-                    throw new RepositoryException("Exception opening search index.", e);
-                }
-                wspSearchMgrs.put(workspaceName, searchMgr);
-            }
-            return searchMgr;
-        }
+        return wspInfo.getSearchManager();
     }
 
     SystemSession getSystemSession(String workspaceName)
@@ -569,20 +495,11 @@
             throw new IllegalStateException("repository instance has been shut down");
         }
 
-        WorkspaceConfig wspConfig = (WorkspaceConfig) wspConfigs.get(workspaceName);
-        if (wspConfig == null) {
+        WorkspaceInfo wspInfo = (WorkspaceInfo) wspInfos.get(workspaceName);
+        if (wspInfo == null) {
             throw new NoSuchWorkspaceException(workspaceName);
         }
-
-        synchronized (wspSystemSessions) {
-            SystemSession systemSession
-                    = (SystemSession) wspSystemSessions.get(workspaceName);
-            if (systemSession == null) {
-                systemSession = new SystemSession(this, wspConfig);
-                wspSystemSessions.put(workspaceName, systemSession);
-            }
-            return systemSession;
-        }
+        return wspInfo.getSystemSession();
     }
 
     /**
@@ -598,18 +515,6 @@
             return;
         }
 
-        // stop / dispose all ObservationManagers
-        for (Iterator it = wspObsMgrFactory.values().iterator(); it.hasNext();) {
-            ObservationManagerFactory obsMgr = (ObservationManagerFactory) it.next();
-            obsMgr.dispose();
-        }
-
-        // shutdown search managers
-        for (Iterator it = wspSearchMgrs.values().iterator(); it.hasNext();) {
-            SearchManager searchMgr = (SearchManager) it.next();
-            searchMgr.close();
-        }
-
         // close active user sessions
         for (Iterator it = activeSessions.values().iterator(); it.hasNext();) {
             SessionImpl session = (SessionImpl) it.next();
@@ -618,36 +523,10 @@
         }
         activeSessions.clear();
 
-        // close system sessions
-        for (Iterator it = wspSystemSessions.values().iterator(); it.hasNext();) {
-            SessionImpl session = (SessionImpl) it.next();
-            session.removeListener(this);
-            session.logout();
-        }
-        wspSystemSessions.clear();
-
-        // dispose persistent item state  mgr's
-        for (Iterator it = wspStateMgrs.values().iterator(); it.hasNext();) {
-            PersistentItemStateManager stateMgr =
-                    (PersistentItemStateManager) it.next();
-            stateMgr.dispose();
-        }
-
-        // shutdown persistence managers & file systems
-        for (Iterator it = wspConfigs.values().iterator(); it.hasNext();) {
-            WorkspaceConfig wspConfig = (WorkspaceConfig) it.next();
-            try {
-                // close persistence manager
-                wspConfig.getPersistenceManager().close();
-            } catch (Exception e) {
-                log.error("error while closing persistence manager of workspace " + wspConfig.getName(),
e);
-            }
-            try {
-                // close workspace file system
-                wspConfig.getFileSystem().close();
-            } catch (FileSystemException e) {
-                log.error("error while closing filesystem of workspace " + wspConfig.getName(),
e);
-            }
+        // shut down workspaces 
+        for (Iterator it = wspInfos.values().iterator(); it.hasNext();) {
+            WorkspaceInfo wspInfo = (WorkspaceInfo) it.next();
+            wspInfo.dispose();
         }
 
         /**
@@ -779,19 +658,19 @@
         if (workspaceName == null) {
             workspaceName = repConfig.getDefaultWorkspaceName();
         }
-        WorkspaceConfig wspConfig = (WorkspaceConfig) wspConfigs.get(workspaceName);
-        if (wspConfig == null) {
+        WorkspaceInfo wspInfo = (WorkspaceInfo) wspInfos.get(workspaceName);
+        if (wspInfo == null) {
             throw new NoSuchWorkspaceException(workspaceName);
         }
         if (credentials == null) {
             // anonymous login
-            SessionImpl ses = new XASessionImpl(this, ANONYMOUS_CREDENTIALS, wspConfig, txMgr);
+            SessionImpl ses = new XASessionImpl(this, ANONYMOUS_CREDENTIALS, wspInfo.getConfig(),
txMgr);
             activeSessions.put(ses, ses);
             return ses;
         } else if (credentials instanceof SimpleCredentials) {
             // username/password credentials
             // @todo implement authentication/authorization
-            Session ses = new XASessionImpl(this, credentials, wspConfig, txMgr);
+            Session ses = new XASessionImpl(this, credentials, wspInfo.getConfig(), txMgr);
             activeSessions.put(ses, ses);
             return ses;
         } else {
@@ -849,6 +728,262 @@
                     propsCount--;
                     repProps.setProperty(STATS_PROP_COUNT_PROPERTY, Long.toString(propsCount));
                 }
+            }
+        }
+    }
+
+    //--------------------------------------------------------< inner classes >
+    /**
+     * <code>WorkspaceInfo</code> holds the objects that are shared
+     * among multiple per-session <code>WorkspaceImpl</code> instances
+     * representing the same named workspace, i.e. the same physical
+     * storage.
+     */
+    class WorkspaceInfo {
+
+        /**
+         * workspace configuration
+         */
+        private final WorkspaceConfig config;
+
+        /**
+         * persistence manager
+         */
+        private PersistenceManager persistMgr;
+
+        /**
+         * item state provider
+         */
+        private PersistentItemStateManager itemStateMgr;
+
+        /**
+         * reference manager
+         */
+        private ReferenceManager refMgr;
+
+        /**
+         * system session
+         */
+        private SystemSession systemSession;
+
+        /**
+         * observation manager factory
+         */
+        private ObservationManagerFactory obsMgrFactory;
+
+        /**
+         * search manager
+         */
+        private SearchManager searchMgr;
+
+        /**
+         * Creates a new <code>WorkspaceInfo</code> based on the given
+         * <code>config</code>.
+         *
+         * @param config workspace configuration
+         */
+        WorkspaceInfo(WorkspaceConfig config) {
+            this.config = config;
+        }
+
+        /**
+         * Returns the workspace name
+         *
+         * @return the workspace name
+         */
+        String getName() {
+            return config.getName();
+        }
+
+        /**
+         * Returns the workspace file system
+         *
+         * @return the workspace file system
+         */
+        FileSystem getFileSystem() {
+            return config.getFileSystem();
+        }
+
+        /**
+         * Returns the workspace configuration
+         *
+         * @return the workspace configuration
+         */
+        WorkspaceConfig getConfig() {
+            return config;
+        }
+
+        /**
+         * Returns the workspace persistence manager
+         *
+         * @return the workspace persistence manager
+         * @throws RepositoryException if the persistence manager could not be instantiated/initialized
+         */
+        synchronized PersistenceManager getPersistenceManager() throws RepositoryException
{
+            if (persistMgr == null) {
+                PersistenceManagerConfig pmConfig = config.getPersistenceManagerConfig();
+                String className = pmConfig.getClassName();
+                Map params = pmConfig.getParameters();
+                try {
+                    Class c = Class.forName(className);
+                    persistMgr = (PersistenceManager) c.newInstance();
+                    /**
+                     * set the properties of the persistence manager object
+                     * from the param map
+                     */
+                    BeanMap bm = new BeanMap(persistMgr);
+                    Iterator iter = params.keySet().iterator();
+                    while (iter.hasNext()) {
+                        Object name = iter.next();
+                        Object value = params.get(name);
+                        bm.put(name, value);
+                    }
+                    PMContext ctx = new PMContext(config, rootNodeUUID, nsReg, ntReg);
+                    persistMgr.init(ctx);
+                } catch (Exception e) {
+                    persistMgr = null;
+                    log.error("Cannot instantiate implementing class " + className, e);
+                    throw new RepositoryException("Cannot instantiate implementing class
" + className, e);
+                }
+            }
+            return persistMgr;
+        }
+
+        /**
+         * Returns the system session for this workspace
+         *
+         * @return the system session for this workspace
+         * @throws RepositoryException if the system session could not be created
+         */
+        synchronized SystemSession getSystemSession() throws RepositoryException {
+            if (systemSession == null) {
+                systemSession = new SystemSession(RepositoryImpl.this, config);
+            }
+            return systemSession;
+        }
+
+        /**
+         * Returns the reference manager for this workspace
+         *
+         * @return the reference manager for this workspace
+         * @throws RepositoryException if the reference manager could not be created
+         */
+        synchronized ReferenceManager getReferenceManager()
+                throws RepositoryException {
+            if (refMgr == null) {
+                // create reference mgr that uses this workspace's perstistence mgr
+                refMgr = new ReferenceManager(getPersistenceManager());
+            }
+            return refMgr;
+        }
+
+        /**
+         * Returns the workspace item state provider
+         *
+         * @return the workspace item state provider
+         * @throws RepositoryException if the workspace item state provider could not be
created
+         */
+        synchronized PersistentItemStateProvider getItemStateProvider()
+                throws RepositoryException {
+            if (itemStateMgr == null) {
+                // create item state manager
+                try {
+                    itemStateMgr = new PersistentItemStateManager(getPersistenceManager(),
rootNodeUUID, ntReg);
+                } catch (ItemStateException ise) {
+                    String msg = "failed to instantiate persistent item state manager";
+                    log.error(msg, ise);
+                    throw new RepositoryException(msg, ise);
+                }
+            }
+            return itemStateMgr;
+        }
+
+        /**
+         * Returns the observation manager factory for this workspace
+         *
+         * @return the observation manager factory for this workspace
+         */
+        synchronized ObservationManagerFactory getObservationManagerFactory() {
+            if (obsMgrFactory == null) {
+                obsMgrFactory = new ObservationManagerFactory();
+            }
+            return obsMgrFactory;
+        }
+
+        /**
+         * Returns the search manager for this workspace
+         *
+         * @return the search manager for this workspace
+         * @throws RepositoryException if the search manager could not be created
+         */
+        synchronized SearchManager getSearchManager() throws RepositoryException {
+            if (searchMgr == null) {
+                if (config.getSearchConfig() == null) {
+                    // no search index configured
+                    return null;
+                }
+                try {
+                    searchMgr = new SearchManager(getSystemSession(), config.getSearchConfig());
+                } catch (IOException ioe) {
+                    String msg = "failed to instantiate search manager";
+                    log.error(msg, ioe);
+                    throw new RepositoryException(msg, ioe);
+                }
+            }
+            return searchMgr;
+        }
+
+        /**
+         * Disposes all objects this <code>WorkspaceInfo</code> is holding.
+         */
+        void dispose() {
+            // dispose observation manager factory
+            if (obsMgrFactory != null) {
+                obsMgrFactory.dispose();
+                obsMgrFactory = null;
+            }
+
+            // shutdown search managers
+            if (searchMgr != null) {
+                searchMgr.close();
+                searchMgr = null;
+            }
+
+            // close system session
+            if (systemSession != null) {
+                systemSession.removeListener(RepositoryImpl.this);
+                systemSession.logout();
+                systemSession = null;
+            }
+
+            // dispose persistent item state mgr
+            if (itemStateMgr != null) {
+                itemStateMgr.dispose();
+                itemStateMgr = null;
+            }
+
+            // close persistence manager
+            if (persistMgr != null) {
+                try {
+                    persistMgr.close();
+                } catch (Exception e) {
+                    log.error("error while closing persistence manager of workspace " + config.getName(),
e);
+                }
+                persistMgr = null;
+            }
+
+            // dispose reference manager
+            if (refMgr != null) {
+                //refMgr.dispose();
+                refMgr = null;
+            }
+
+            // close workspace file system
+            try {
+                // close workspace file system
+                config.getFileSystem().close();
+            } catch (FileSystemException e) {
+                log.error("error while closing filesystem of workspace " + config.getName(),
e);
             }
         }
     }

Added: 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=auto&rev=106580
==============================================================================
--- (empty file)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/PersistenceManagerConfig.java
Thu Nov 25 08:17:37 2004
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.jdom.Element;
+
+import java.util.*;
+
+/**
+ * A <code>PersistenceManagerConfig</code> represents the configuration of a
+ * <code>PersistenceManager</code>.
+ *
+ * @see WorkspaceConfig#getPersistenceManagerConfig()
+ */
+public class PersistenceManagerConfig {
+
+    private static final String CLASS_ATTRIB = "class";
+
+    /**
+     * FQN of class implementing the <code>PersistenceManager</code> interface
+     */
+    private final String className;
+
+    /**
+     * Parameters for configuring the persistence manager.
+     */
+    private final Map params;
+
+    /**
+     * Creates a new <code>PersistenceManagerConfig</code>.
+     *
+     * @param config the config root element for this <code>PersistenceManagerConfig</code>.
+     * @param vars   map of variable values.
+     */
+    PersistenceManagerConfig(Element config, Map vars) {
+        // FQN of persistence manager class
+        className = config.getAttributeValue(CLASS_ATTRIB);
+
+        // read the PersistenceManager properties from the
+        // <param/> elements in the config
+        Map params = new HashMap();
+        List paramList = config.getChildren(AbstractConfig.PARAM_ELEMENT);
+        for (Iterator i = paramList.iterator(); i.hasNext();) {
+            Element param = (Element) i.next();
+            String paramName = param.getAttributeValue(AbstractConfig.NAME_ATTRIB);
+            String paramValue = param.getAttributeValue(AbstractConfig.VALUE_ATTRIB);
+            // replace variables in param value
+            params.put(paramName, AbstractConfig.replaceVars(paramValue, vars));
+        }
+        this.params = Collections.unmodifiableMap(params);
+    }
+
+    /**
+     * Returns configuration parameters. Each entry in the map represents
+     * a name/value pair where both name and value are <code>String</code>s.
+     *
+     * @return Map of configuration parameters.
+     */
+    public Map getParameters() {
+        return params;
+    }
+
+    /**
+     * Returns the FQN of a class implementing the <code>PersistenceManager</code>
interface
+     *
+     * @return FQN of persistence manager class
+     */
+    public String getClassName() {
+        return className;
+    }
+
+}

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&rev=106580&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java&r1=106579&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java&r2=106580
==============================================================================
--- 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 Nov 25 08:17:37 2004
@@ -264,8 +264,9 @@
      * @param name workspace name
      * @throws RepositoryException if the specified name already exists or
      *                             if an error occured during the creation.
+     * @return a new <code>WorkspaceConfig</code> object.
      */
-    public void createWorkspaceConfig(String name) throws RepositoryException {
+    public synchronized WorkspaceConfig createWorkspaceConfig(String name) throws RepositoryException
{
         if (wspConfigs.containsKey(name)) {
             String msg = "A workspace with the specified name alreay exists";
             log.error(msg);
@@ -311,6 +312,7 @@
         // create workspace config object
         WorkspaceConfig wspConfig = WorkspaceConfig.create(configFile.getPath(), configFile.getParent());
         wspConfigs.put(name, wspConfig);
+        return wspConfig;
     }
 
     //------------------------------------------------------< EntityResolver >

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&rev=106580&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java&r1=106579&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java&r2=106580
==============================================================================
--- 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 Nov 25 08:17:37 2004
@@ -15,9 +15,7 @@
  */
 package org.apache.jackrabbit.core.config;
 
-import org.apache.commons.collections.BeanMap;
 import org.apache.jackrabbit.core.fs.FileSystem;
-import org.apache.jackrabbit.core.state.PersistenceManager;
 import org.apache.log4j.Logger;
 import org.jdom.Document;
 import org.jdom.Element;
@@ -29,8 +27,6 @@
 import java.io.FileReader;
 import java.io.IOException;
 import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
 
 /**
  * A <code>WorkspaceConfig</code> ...
@@ -76,12 +72,12 @@
     private String wspName;
 
     /**
-     * persistence manager of the workspace
+     * configuration for the persistence manager
      */
-    private PersistenceManager persistMgr;
+    private PersistenceManagerConfig pmConfig;
 
     /**
-     * configuration for the search manager.
+     * configuration for the search manager
      */
     private SearchConfig searchConfig;
 
@@ -124,46 +120,18 @@
         vars.put(WORKSPACE_NAME_VARIABLE, wspName);
 
         // file system
-        Element fsConfig = wspElem.getChild(FILE_SYSTEM_ELEMENT);
-        wspFS = createFileSystem(fsConfig, vars);
+        Element fsElem = wspElem.getChild(FILE_SYSTEM_ELEMENT);
+        wspFS = createFileSystem(fsElem, vars);
 
-        // search config
+        // persistence manager config
+        Element pmElem = wspElem.getChild(PERSISTENCE_MANAGER_ELEMENT);
+        pmConfig = new PersistenceManagerConfig(pmElem, vars);
+
+        // search config (optional)
         Element searchElem = wspElem.getChild(SEARCH_INDEX_ELEMENT);
         if (searchElem != null) {
             searchConfig = new SearchConfig(searchElem, vars);
         }
-
-        // persistence manager
-        String className = wspElem.getChild(PERSISTENCE_MANAGER_ELEMENT).getAttributeValue(CLASS_ATTRIB);
-        // read the PersistenceManager properties from the
-        // param elements in the config
-        HashMap params = new HashMap();
-        List paramList = wspElem.getChild(PERSISTENCE_MANAGER_ELEMENT).getChildren(PARAM_ELEMENT);
-        for (Iterator i = paramList.iterator(); i.hasNext();) {
-            Element param = (Element) i.next();
-            String paramName = param.getAttributeValue(NAME_ATTRIB);
-            String paramValue = param.getAttributeValue(VALUE_ATTRIB);
-            // replace variables in param value
-            params.put(paramName, replaceVars(paramValue, vars));
-        }
-        // finally do create the persistence manager
-        try {
-            Class c = Class.forName(className);
-            persistMgr = (PersistenceManager) c.newInstance();
-            // set the properties of the persistence manager object from the
-            // param hashmap
-            BeanMap bm = new BeanMap(persistMgr);
-            Iterator iter = params.keySet().iterator();
-            while (iter.hasNext()) {
-                Object name = iter.next();
-                Object value = params.get(name);
-                bm.put(name, value);
-            }
-            persistMgr.init(this);
-        } catch (Exception e) {
-            log.error("Cannot instantiate implementing class " + className, e);
-            throw new RepositoryException("Cannot instantiate implementing class " + className,
e);
-        }
     }
 
     /**
@@ -231,19 +199,19 @@
     }
 
     /**
-     * Returns the workspace's persistence manager.
+     * Returns the configuration of the persistence manager.
      *
-     * @return the persistence manager
+     * @return the <code>PersistenceManagerConfig</code> for this workspace
      */
-    public PersistenceManager getPersistenceManager() {
-        return persistMgr;
+    public PersistenceManagerConfig getPersistenceManagerConfig() {
+        return pmConfig;
     }
 
     /**
      * Returns the configuration of the search manager.
      * Returns <code>null</code> if no search manager is configured.
      *
-     * @return the <code>SearchConfig</code> for this workspace.
+     * @return the <code>SearchConfig</code> for this workspace
      */
     public SearchConfig getSearchConfig() {
         return searchConfig;

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PMContext.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PMContext.java?view=auto&rev=106580
==============================================================================
--- (empty file)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PMContext.java	Thu
Nov 25 08:17:37 2004
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.state;
+
+import org.apache.jackrabbit.core.config.WorkspaceConfig;
+import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
+
+import javax.jcr.NamespaceRegistry;
+
+/**
+ * A <code>PMContext</code> is used to provide context information for a
+ * <code>PersistenceManager</code>.
+ *
+ * @see PersistenceManager#init(PMContext)
+ */
+public class PMContext {
+
+    /**
+     * workspace configuration
+     */
+    private final WorkspaceConfig wspConfig;
+
+    /**
+     * namespace registry
+     */
+    private final NamespaceRegistry nsReg;
+
+    /**
+     * node type registry
+     */
+    private final NodeTypeRegistry ntReg;
+
+    /**
+     * uuid of the root node
+     */
+    private final String rootNodeUUID;
+
+    /**
+     * Creates a new <code>PMContext</code>.
+     *
+     * @param wspConfig    configuration of workspace
+     * @param rootNodeUUID uuid of the root node
+     * @param nsReg        namespace registry
+     * @param ntReg        node type registry
+     */
+    public PMContext(WorkspaceConfig wspConfig,
+                     String rootNodeUUID,
+                     NamespaceRegistry nsReg,
+                     NodeTypeRegistry ntReg) {
+        this.wspConfig = wspConfig;
+        this.rootNodeUUID = rootNodeUUID;
+        this.nsReg = nsReg;
+        this.ntReg = ntReg;
+    }
+
+    /**
+     * Returns the workspace configuration
+     *
+     * @return the workspace configuration
+     */
+    public WorkspaceConfig getWorkspaceConfig() {
+        return wspConfig;
+    }
+
+    /**
+     * Returns the uuid of the root node
+     *
+     * @return the uuid of the root node
+     */
+    public String getRootNodeUUID() {
+        return rootNodeUUID;
+    }
+
+    /**
+     * Returns the namespace registry
+     *
+     * @return the namespace registry
+     */
+    public NamespaceRegistry getNamespaceRegistry() {
+        return nsReg;
+    }
+
+    /**
+     * Returns the node type registry
+     *
+     * @return the node type registry
+     */
+    public NodeTypeRegistry getNodeTypeRegistry() {
+        return ntReg;
+    }
+}

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistenceManager.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistenceManager.java?view=diff&rev=106580&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistenceManager.java&r1=106579&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistenceManager.java&r2=106580
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistenceManager.java
Thu Nov 25 08:17:37 2004
@@ -25,10 +25,10 @@
 public interface PersistenceManager {
 
     /**
-     * @param wspConfig
+     * @param context
      * @throws Exception
      */
-    public void init(WorkspaceConfig wspConfig) throws Exception;
+    public void init(PMContext context) throws Exception;
 
     /**
      * @throws Exception

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/mem/InMemPersistenceManager.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/mem/InMemPersistenceManager.java?view=diff&rev=106580&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/mem/InMemPersistenceManager.java&r1=106579&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/mem/InMemPersistenceManager.java&r2=106580
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/mem/InMemPersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/mem/InMemPersistenceManager.java
Thu Nov 25 08:17:37 2004
@@ -16,7 +16,6 @@
 package org.apache.jackrabbit.core.state.mem;
 
 import org.apache.jackrabbit.core.*;
-import org.apache.jackrabbit.core.config.WorkspaceConfig;
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.FileSystemPathUtil;
 import org.apache.jackrabbit.core.fs.FileSystemResource;
@@ -308,7 +307,7 @@
     /**
      * @see PersistenceManager#init
      */
-    public void init(WorkspaceConfig wspConfig) throws Exception {
+    public void init(PMContext context) throws Exception {
         if (initialized) {
             throw new IllegalStateException("already initialized");
         }
@@ -316,14 +315,14 @@
         stateStore = new HashMap(initialCapacity, loadFactor);
         refsStore = new HashMap(initialCapacity, loadFactor);
 
-        wspFS = wspConfig.getFileSystem();
+        wspFS = context.getWorkspaceConfig().getFileSystem();
         
         /**
          * store blob's in local file system in a sub directory
          * of the workspace home directory
          */
         LocalFileSystem blobFS = new LocalFileSystem();
-        blobFS.setPath(wspConfig.getHomeDir() + "/blobs");
+        blobFS.setPath(context.getWorkspaceConfig().getHomeDir() + "/blobs");
         blobFS.init();
         this.blobFS = blobFS;
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java?view=diff&rev=106580&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java&r1=106579&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java&r2=106580
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
Thu Nov 25 08:17:37 2004
@@ -16,7 +16,6 @@
 package org.apache.jackrabbit.core.state.obj;
 
 import org.apache.jackrabbit.core.*;
-import org.apache.jackrabbit.core.config.WorkspaceConfig;
 import org.apache.jackrabbit.core.fs.*;
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.local.LocalFileSystem;
@@ -404,12 +403,12 @@
     /**
      * @see PersistenceManager#init
      */
-    public void init(WorkspaceConfig wspConfig) throws Exception {
+    public void init(PMContext context) throws Exception {
         if (initialized) {
             throw new IllegalStateException("already initialized");
         }
 
-        FileSystem wspFS = wspConfig.getFileSystem();
+        FileSystem wspFS = context.getWorkspaceConfig().getFileSystem();
         itemStateFS = new BasedFileSystem(wspFS, "/data");
 
         /**
@@ -417,7 +416,7 @@
          * of the workspace home directory
          */
         LocalFileSystem blobFS = new LocalFileSystem();
-        blobFS.setPath(wspConfig.getHomeDir() + "/blobs");
+        blobFS.setPath(context.getWorkspaceConfig().getHomeDir() + "/blobs");
         blobFS.init();
         this.blobFS = blobFS;
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java?view=diff&rev=106580&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java&r1=106579&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java&r2=106580
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
Thu Nov 25 08:17:37 2004
@@ -16,7 +16,6 @@
 package org.apache.jackrabbit.core.state.xml;
 
 import org.apache.jackrabbit.core.*;
-import org.apache.jackrabbit.core.config.WorkspaceConfig;
 import org.apache.jackrabbit.core.fs.*;
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.local.LocalFileSystem;
@@ -336,12 +335,12 @@
     /**
      * @see PersistenceManager#init
      */
-    public void init(WorkspaceConfig wspConfig) throws Exception {
+    public void init(PMContext context) throws Exception {
         if (initialized) {
             throw new IllegalStateException("already initialized");
         }
 
-        FileSystem wspFS = wspConfig.getFileSystem();
+        FileSystem wspFS = context.getWorkspaceConfig().getFileSystem();
         itemStateStore = new BasedFileSystem(wspFS, "/data");
 
         //blobStore = new BasedFileSystem(wspFS, "/blobs");
@@ -351,7 +350,7 @@
          * todo make blob store configurable
          */
         LocalFileSystem blobFS = new LocalFileSystem();
-        blobFS.setPath(wspConfig.getHomeDir() + "/blobs");
+        blobFS.setPath(context.getWorkspaceConfig().getHomeDir() + "/blobs");
         blobFS.init();
         blobStore = blobFS;
 
@@ -807,7 +806,7 @@
                 while (iter.hasNext()) {
                     PropertyId propId = (PropertyId) iter.next();
                     writer.write("\t<" + NODEREFERENCE_ELEMENT + " "
-                    + PROPERTYID_ATTRIBUTE+ "=\"" + propId +  "\"/>\n");
+                            + PROPERTYID_ATTRIBUTE + "=\"" + propId + "\"/>\n");
                 }
                 writer.write("</" + NODEREFERENCES_ELEMENT + ">\n");
             } finally {

Mime
View raw message