jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: rev 54857 - in incubator/jackrabbit/trunk/src: conf java/org/apache/jackrabbit/core java/org/apache/jackrabbit/core/config java/org/apache/jackrabbit/core/jndi java/org/apache/jackrabbit/core/state java/org/apache/jackrabbit/core/state/xml test/org/apache/jackrabbit/test
Date Fri, 15 Oct 2004 17:01:13 GMT
Author: stefan
Date: Fri Oct 15 10:01:13 2004
New Revision: 54857

Removed:
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/DynamicWorkspaceDef.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryFactory.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/StableWorkspaceDef.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceDef.java
Modified:
   incubator/jackrabbit/trunk/src/conf/repository.xml
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SystemSession.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Test.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.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/jndi/BindableRepository.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistenceManager.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
   incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JackrabbitRepositoryStub.java
Log:
changed configuration layout and bootstrapping of repository:
- added jndi support
- workspace configuration is now separated from repository config
  

Modified: incubator/jackrabbit/trunk/src/conf/repository.xml
==============================================================================
--- incubator/jackrabbit/trunk/src/conf/repository.xml	(original)
+++ incubator/jackrabbit/trunk/src/conf/repository.xml	Fri Oct 15 10:01:13 2004
@@ -18,14 +18,19 @@
     -->
     <Workspace name="${wsp.name}">
         <!--
-            virtual file system of the workspace
+            virtual file system of the workspace:
+            class: FQN of class implementing FileSystem interface
         -->
         <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
             <param name="path" value="${wsp.home}"/>
         </FileSystem>
+        <!--
+            persistence of the workspace:
+            class: FQN of class implementing PersistenceManager interface
+        -->
         <PersistenceManager class="org.apache.jackrabbit.core.state.xml.XMLPersistenceManager">
             <!-- <param name="someParam" value="someValue"/> -->
         </PersistenceManager>
-        <SearchIndex path="${wsp.home}/index"/>
+        <SearchIndex path="/index"/>
     </Workspace>
 </Repository>

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ItemImpl.java	Fri Oct 15
10:01:13 2004
@@ -1224,6 +1224,9 @@
      * @see Item#isSame(Item)
      */
     public boolean isSame(Item otherItem) {
+        if (this == otherItem) {
+            return true;
+        }
         if (otherItem instanceof ItemImpl) {
             ItemImpl other = (ItemImpl) otherItem;
             return id.equals(other.id);

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java	Fri
Oct 15 10:01:13 2004
@@ -15,14 +15,18 @@
  */
 package org.apache.jackrabbit.core;
 
-import org.apache.commons.collections.BeanMap;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.apache.jackrabbit.core.config.WorkspaceConfig;
 import org.apache.jackrabbit.core.fs.BasedFileSystem;
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.FileSystemException;
 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.*;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.ItemStateProvider;
+import org.apache.jackrabbit.core.state.PersistentItemStateManager;
+import org.apache.jackrabbit.core.state.ReferenceManager;
 import org.apache.jackrabbit.core.util.uuid.UUID;
 import org.apache.jackrabbit.core.version.VersionManager;
 import org.apache.log4j.Logger;
@@ -44,9 +48,10 @@
 
     private static Logger log = Logger.getLogger(RepositoryImpl.class);
 
-    private static final String DEFAULT_WORKSPACE_NAME = "default";
-
-    private static final String VERSION_WORKSPACE_NAME = "default";
+    /**
+     * hardcoded uuid of the repository root node
+     */
+    private static final String ROOT_NODE_UUID = "ac3b5c25-613d-4798-8494-ffbcca9c5c6c";
 
     private static final String ANONYMOUS_USER = "anonymous";
 
@@ -77,6 +82,8 @@
     private final NodeTypeRegistry ntReg;
     private final VersionManager vMgr;
 
+    // configuration of the repository
+    private final RepositoryConfig repConfig;
     // the master filesystem
     private final FileSystem repStore;
     // sub file system where the repository stores meta data such as uuid of root node, etc.
@@ -84,8 +91,8 @@
     // sub file system where the repository stores versions
     private final FileSystem versionStore;
 
-    // map of workspace names and workspace definitions
-    private final HashMap wspDefs = new HashMap();
+    // 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
@@ -111,13 +118,14 @@
     private long propsCount = 0;
 
     /**
-     * Package private constructor.
+     * private constructor
      *
-     * @param repStore
-     * @param swda
+     * @param repConfig
      */
-    RepositoryImpl(FileSystem repStore, StableWorkspaceDef[] swda) throws RepositoryException
{
+    private RepositoryImpl(RepositoryConfig repConfig) throws RepositoryException {
+        this.repConfig = repConfig;
         // setup file systems
+        repStore = repConfig.getFileSystem();
         String fsRootPath = "/meta";
         try {
             if (!repStore.exists(fsRootPath) || !repStore.isFolder(fsRootPath)) {
@@ -128,7 +136,6 @@
             log.error(msg, fse);
             throw new RepositoryException(msg, fse);
         }
-        this.repStore = repStore;
         metaDataStore = new BasedFileSystem(repStore, fsRootPath);
 
         fsRootPath = "/versions";
@@ -175,7 +182,14 @@
                             // ignore
                         }
                     }
-                    rootNodeUUID = new UUID(new String(chars)).toString();
+                    /**
+                     * use hard-coded uuid for root node rather than generating
+                     * a different uuid per repository instance; using a
+                     * hard-coded uuid makes it easier to copy/move entire
+                     * workspaces from one repository instance to another.
+                     */
+                    //rootNodeUUID = new UUID(new String(chars)).toString();
+                    rootNodeUUID = ROOT_NODE_UUID;
 
                 } catch (Exception e) {
                     String msg = "failed to load persisted repository state";
@@ -225,30 +239,10 @@
         }
 
         // workspaces
-        for (int i = 0; i < swda.length; i++) {
-            StableWorkspaceDef swd = swda[i];
-            if (wspDefs.containsKey(swd.getName())) {
-                String msg = "workspace '" + swd.getName() + "' already defined";
-                log.error(msg);
-                throw new RepositoryException(msg);
-            }
-            wspDefs.put(swd.getName(), swd);
-            DynamicWorkspaceDef[] dwda = swd.getDynWorkspaces();
-            for (int j = 0; j < dwda.length; j++) {
-                DynamicWorkspaceDef dwd = dwda[j];
-                if (wspDefs.containsKey(dwd.getName())) {
-                    String msg = "workspace '" + dwd.getName() + "' already defined";
-                    log.error(msg);
-                    throw new RepositoryException(msg);
-                }
-                wspDefs.put(dwd.getName(), dwd);
-            }
-        }
-        WorkspaceDef wd = (WorkspaceDef) wspDefs.get(DEFAULT_WORKSPACE_NAME);
-        if (wd == null || wd.isDynamic()) {
-            String msg = "mandatory stable workspace 'default' not defined";
-            log.error(msg);
-            throw new RepositoryException(msg);
+        Iterator iter = repConfig.getWorkspaceConfigs().iterator();
+        while (iter.hasNext()) {
+            WorkspaceConfig config = (WorkspaceConfig) iter.next();
+            wspConfigs.put(config.getName(), config);
         }
 
         nsReg = new NamespaceRegistryImpl(new BasedFileSystem(repStore, "/namespaces"));
@@ -265,7 +259,7 @@
          */
 
         // check system root node of system workspace
-        SessionImpl sysSession = getSystemSession(DEFAULT_WORKSPACE_NAME);
+        SessionImpl sysSession = getSystemSession(repConfig.getDefaultWorkspaceName());
         NodeImpl rootNode = (NodeImpl) sysSession.getRootNode();
         if (!rootNode.hasNode(SYSTEM_ROOT_NAME)) {
             rootNode.addNode(SYSTEM_ROOT_NAME, NodeTypeRegistry.NT_UNSTRUCTURED);
@@ -274,11 +268,11 @@
 
         // init version manager
         // todo: as soon as dynamic workspaces are available, base on system ws
-        SessionImpl verSession = getSystemSession(VERSION_WORKSPACE_NAME);
+        SessionImpl verSession = getSystemSession(repConfig.getDefaultWorkspaceName());
         NodeImpl vRootNode = (NodeImpl) verSession.getRootNode();
         try {
             if (!vRootNode.hasNode(SYSTEM_ROOT_NAME)) {
-                verSession.getWorkspace().clone(DEFAULT_WORKSPACE_NAME,
+                verSession.getWorkspace().clone(repConfig.getDefaultWorkspaceName(),
                         SYSTEM_ROOT_NAME.toJCRName(verSession.getNamespaceResolver()),
                         SYSTEM_ROOT_NAME.toJCRName(verSession.getNamespaceResolver()));
             }
@@ -295,9 +289,9 @@
 
         // get the system session for every defined workspace and
         // register as an event listener
-        Iterator iter = wspDefs.values().iterator();
+        iter = wspConfigs.values().iterator();
         while (iter.hasNext()) {
-            String wspName = ((WorkspaceDef) iter.next()).getName();
+            String wspName = ((WorkspaceConfig) iter.next()).getName();
             Session s = getSystemSession(wspName);
             s.getWorkspace().getObservationManager().addEventListener(this,
                     EventType.CHILD_NODE_ADDED | EventType.CHILD_NODE_REMOVED
@@ -317,6 +311,24 @@
         }
     }
 
+    /**
+     * Creates a new <code>RepositoryImpl</code> instance.
+     * <p/>
+     * todo prevent multiple instantiation from same configuration as this could lead to
data corruption/loss
+     *
+     * @param config the configuration of the repository
+     * @return a new <code>RepositoryImpl</code> instance
+     * @throws RepositoryException If an error occurs
+     */
+    public static RepositoryImpl create(RepositoryConfig config)
+            throws RepositoryException {
+        return new RepositoryImpl(config);
+    }
+
+    RepositoryConfig getConfig() {
+        return repConfig;
+    }
+
     NamespaceRegistryImpl getNamespaceRegistry() {
         return nsReg;
     }
@@ -335,35 +347,21 @@
 
     synchronized PersistentItemStateManager getWorkspaceStateManager(String workspaceName)
             throws NoSuchWorkspaceException, RepositoryException {
-        WorkspaceDef wd = (WorkspaceDef) wspDefs.get(workspaceName);
-        if (wd == null) {
+        WorkspaceConfig wspConfig = (WorkspaceConfig) wspConfigs.get(workspaceName);
+        if (wspConfig == null) {
             throw new NoSuchWorkspaceException(workspaceName);
         }
         // get/create per named workspace (i.e. per physical storage) item state manager
         PersistentItemStateManager stateMgr =
                 (PersistentItemStateManager) wspStateMgrs.get(workspaceName);
         if (stateMgr == null) {
-            if (wd.isDynamic()) {
-/*
-		// create dynamic (i.e. transparent) state manager backed
-		// by a 'master' state manager
-		DynamicWorkspaceDef dwd = (DynamicWorkspaceDef) wd;
-		StableWorkspaceDef swd = (StableWorkspaceDef) wspDefs.get(dwd.getStableWorkspace());
-		stateMgr = new TransparentItemStateManager(dwd.getFS(), getWorkspaceStateManager(swd));
-*/
-                // @todo implement dynamic workspace support
-                throw new RepositoryException("dynamic workspaces are not supported");
-            } else {
-                // create stable (i.e. opaque) state manager
-                StableWorkspaceDef swd = (StableWorkspaceDef) wd;
-                PersistenceManager persistMgr = createPersistenceManager(swd);
-                try {
-                    stateMgr = new PersistentItemStateManager(persistMgr, rootNodeUUID, ntReg);
-                } catch (ItemStateException ise) {
-                    String msg = "failed to instantiate the persistent state manager";
-                    log.error(msg, ise);
-                    throw new RepositoryException(msg, ise);
-                }
+            // 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);
         }
@@ -372,8 +370,8 @@
 
     synchronized ReferenceManager getWorkspaceReferenceManager(String workspaceName)
             throws NoSuchWorkspaceException, RepositoryException {
-        WorkspaceDef wd = (WorkspaceDef) wspDefs.get(workspaceName);
-        if (wd == null) {
+        WorkspaceConfig wspConfig = (WorkspaceConfig) wspConfigs.get(workspaceName);
+        if (wspConfig == null) {
             throw new NoSuchWorkspaceException(workspaceName);
         }
         ReferenceManager refMgr
@@ -381,7 +379,7 @@
         if (refMgr == null) {
             // create reference mgr that uses the perstistence mgr configured
             // in the workspace definition
-            refMgr = new ReferenceManager(createPersistenceManager(wd));
+            refMgr = new ReferenceManager(wspConfig.getPersistenceManager());
             wspRefMgrs.put(workspaceName, refMgr);
         }
         return refMgr;
@@ -389,7 +387,7 @@
 
     synchronized ObservationManagerFactory getObservationManagerFactory(String workspaceName)
             throws NoSuchWorkspaceException {
-        if (!wspDefs.containsKey(workspaceName)) {
+        if (!wspConfigs.containsKey(workspaceName)) {
             throw new NoSuchWorkspaceException(workspaceName);
         }
         ObservationManagerFactory obsMgr
@@ -416,19 +414,19 @@
      */
     synchronized SearchManager getSearchManager(String workspaceName)
             throws NoSuchWorkspaceException, RepositoryException {
+        WorkspaceConfig wspConfig = (WorkspaceConfig) wspConfigs.get(workspaceName);
         SearchManager searchMgr
                 = (SearchManager) wspSearchMgrs.get(workspaceName);
         if (searchMgr == null) {
             try {
-                StableWorkspaceDef wspDef = (StableWorkspaceDef) wspDefs.get(workspaceName);
-                if (wspDef.getSearchIndexPath() == null) {
+                if (wspConfig.getSearchIndexDir() == null) {
                     // no search index location configured
                     return null;
                 }
                 ItemStateProvider stateProvider = getWorkspaceStateManager(workspaceName);
                 SystemSession s = getSystemSession(workspaceName);
                 searchMgr = new SearchManager(stateProvider, s.hierMgr, s,
-                        wspDef.getWorkspaceStore(), wspDef.getSearchIndexPath());
+                        wspConfig.getFileSystem(), wspConfig.getSearchIndexDir());
             } catch (IOException e) {
                 throw new RepositoryException("Exception opening search index.", e);
             }
@@ -439,46 +437,20 @@
 
     synchronized SystemSession getSystemSession(String workspaceName)
             throws NoSuchWorkspaceException, RepositoryException {
+        WorkspaceConfig wspConfig = (WorkspaceConfig) wspConfigs.get(workspaceName);
+        if (wspConfig == null) {
+            throw new NoSuchWorkspaceException(workspaceName);
+        }
         SystemSession systemSession
                 = (SystemSession) wspSystemSessions.get(workspaceName);
         if (systemSession == null) {
-            systemSession = new SystemSession(this, workspaceName);
+            systemSession = new SystemSession(this, wspConfig);
             wspSystemSessions.put(workspaceName, systemSession);
         }
         return systemSession;
     }
 
     /**
-     * @param wspDef
-     * @return
-     * @throws RepositoryException
-     */
-    private PersistenceManager createPersistenceManager(WorkspaceDef wspDef) throws RepositoryException
{
-        PersistenceManager persistMgr;
-        String className = wspDef.getPersistenceManagerClass();
-        try {
-            // Create the persistence manager object
-            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);
-            HashMap params = wspDef.getPersistenceManagerParams();
-            Iterator iter = params.keySet().iterator();
-            while (iter.hasNext()) {
-                Object name = iter.next();
-                Object value = params.get(name);
-                bm.put(name, value);
-            }
-            persistMgr.init(wspDef);
-        } catch (Exception e) {
-            log.error("Cannot instantiate implementing class " + className, e);
-            throw new RepositoryException("Cannot instantiate implementing class " + className,
e);
-        }
-        return persistMgr;
-    }
-
-    /**
      * Shuts down this repository
      */
     protected void shutdown() {
@@ -598,19 +570,20 @@
     public Session login(Credentials credentials, String workspaceName)
             throws LoginException, NoSuchWorkspaceException, RepositoryException {
         if (workspaceName == null) {
-            workspaceName = DEFAULT_WORKSPACE_NAME;
+            workspaceName = repConfig.getDefaultWorkspaceName();
         }
-        if (!wspDefs.containsKey(workspaceName)) {
+        WorkspaceConfig wspConfig = (WorkspaceConfig) wspConfigs.get(workspaceName);
+        if (wspConfig == null) {
             throw new NoSuchWorkspaceException(workspaceName);
         }
         if (credentials == null) {
             // anonymous login
-            return new SessionImpl(this, ANONYMOUS_CREDENTIALS, workspaceName);
+            return new SessionImpl(this, ANONYMOUS_CREDENTIALS, wspConfig);
         } else if (credentials instanceof SimpleCredentials) {
             // username/password credentials
 
             // @todo implement authentication/authorization
-            return new SessionImpl(this, credentials, workspaceName);
+            return new SessionImpl(this, credentials, wspConfig);
         } else {
             String msg = "login failed: incompatible credentials";
             log.error(msg);

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java	Fri Oct
15 10:01:13 2004
@@ -19,6 +19,7 @@
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.SessionItemStateManager;
 import org.apache.jackrabbit.core.xml.ImportHandler;
+import org.apache.jackrabbit.core.config.WorkspaceConfig;
 import org.apache.log4j.Logger;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.InputSource;
@@ -98,9 +99,9 @@
      *
      * @param rep
      * @param credentials
-     * @param wspName
+     * @param wspConfig
      */
-    SessionImpl(RepositoryImpl rep, Credentials credentials, String wspName)
+    SessionImpl(RepositoryImpl rep, Credentials credentials, WorkspaceConfig wspConfig)
             throws RepositoryException {
         this.rep = rep;
 
@@ -125,7 +126,8 @@
         nsMappings = new TransientNamespaceMappings(rep.getNamespaceRegistry());
 
         ntMgr = new NodeTypeManagerImpl(rep.getNodeTypeRegistry(), getNamespaceResolver());
-        wsp = new WorkspaceImpl(wspName, rep.getWorkspaceStateManager(wspName),
+        String wspName = wspConfig.getName();
+        wsp = new WorkspaceImpl(wspConfig, rep.getWorkspaceStateManager(wspName),
                 rep.getWorkspaceReferenceManager(wspName), rep, this);
         itemStateMgr = new SessionItemStateManager(rep.getRootNodeUUID(), wsp.getPersistentStateManager(),
getNamespaceResolver());
         hierMgr = itemStateMgr.getHierarchyMgr();
@@ -138,9 +140,9 @@
      *
      * @param rep
      * @param userId
-     * @param wspName
+     * @param wspConfig
      */
-    protected SessionImpl(RepositoryImpl rep, String userId, String wspName)
+    protected SessionImpl(RepositoryImpl rep, String userId, WorkspaceConfig wspConfig)
             throws RepositoryException {
         this.rep = rep;
 
@@ -149,7 +151,8 @@
         nsMappings = new TransientNamespaceMappings(rep.getNamespaceRegistry());
 
         ntMgr = new NodeTypeManagerImpl(rep.getNodeTypeRegistry(), getNamespaceResolver());
-        wsp = new WorkspaceImpl(wspName, rep.getWorkspaceStateManager(wspName),
+        String wspName = wspConfig.getName();
+        wsp = new WorkspaceImpl(wspConfig, rep.getWorkspaceStateManager(wspName),
                 rep.getWorkspaceReferenceManager(wspName), rep, this);
         itemStateMgr = new SessionItemStateManager(rep.getRootNodeUUID(), wsp.getPersistentStateManager(),
getNamespaceResolver());
         hierMgr = itemStateMgr.getHierarchyMgr();

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SystemSession.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SystemSession.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SystemSession.java	Fri
Oct 15 10:01:13 2004
@@ -15,6 +15,7 @@
  */
 package org.apache.jackrabbit.core;
 
+import org.apache.jackrabbit.core.config.WorkspaceConfig;
 import org.apache.log4j.Logger;
 
 import javax.jcr.PathNotFoundException;
@@ -33,11 +34,11 @@
      * Package private constructor.
      *
      * @param rep
-     * @param wspName
+     * @param wspConfig
      */
-    SystemSession(RepositoryImpl rep, String wspName)
+    SystemSession(RepositoryImpl rep, WorkspaceConfig wspConfig)
             throws RepositoryException {
-        super(rep, SYSTEM_USER_ID, wspName);
+        super(rep, SYSTEM_USER_ID, wspConfig);
 
         accessMgr = new SystemAccessManqager();
     }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Test.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Test.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Test.java	Fri Oct 15 10:01:13
2004
@@ -28,7 +28,6 @@
 import javax.jcr.util.TraversingItemVisitor;
 import javax.naming.InitialContext;
 import javax.naming.Context;
-import javax.naming.Reference;
 import java.io.*;
 import java.util.*;
 
@@ -37,42 +36,38 @@
     private static final String LOG_CONFIG_FILE_NAME = "log4j.properties";
 
     public static void main(String[] args) throws Exception {
-        // location of config.xml & log4j.properties
+        // config dir: location of repository.xml & log4j.properties
         String configDir = System.getProperty("config.dir");
         if (configDir == null) {
             // fallback to cwd
             configDir = System.getProperty("user.dir");
         }
         PropertyConfigurator.configure(configDir + "/" + LOG_CONFIG_FILE_NAME);
-        String configFile = configDir + "/" + RepositoryFactory.DEFAULT_CONFIG_FILE;
+        String configFile = configDir + "/" + RepositoryConfig.CONFIG_FILE_NAME;
 
-        // repository factory home dir
-        String factoryHomeDir = System.getProperty("repository.factory.home");
-        if (factoryHomeDir == null) {
+        // repository home dir
+        String repHomeDir = System.getProperty("repository.home");
+        if (repHomeDir == null) {
             // fallback to cwd
-            factoryHomeDir = System.getProperty("user.dir");
+            repHomeDir = System.getProperty("user.dir");
         }
-/*
-        RepositoryConfig repConf = RepositoryConfig.create(configDir + "/" + "repository.xml",
factoryHomeDir);
-        Collection wspConfigs = repConf.getWorkspaceConfigs();
-*/
+
+        RepositoryConfig repConf = RepositoryConfig.create(configDir + "/" + "repository.xml",
repHomeDir);
+        Repository r = RepositoryImpl.create(repConf);
 /*
         // Set up the environment for creating the initial context
         Hashtable env = new Hashtable();
         //env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
         //env.put(Context.PROVIDER_URL, "file:./jndi");
 
-        //env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ervacon.xnam.XMLInitialContextFactory");
-        //env.put(Context.PROVIDER_URL, "d:/temp/jndi.xml");
+        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ervacon.xnam.XMLInitialContextFactory");
+        env.put(Context.PROVIDER_URL, "d:/temp/jndi.xml");
 
-        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.codehaus.spice.jndikit.memory.StaticMemoryInitialContextFactory");
+        //env.put(Context.INITIAL_CONTEXT_FACTORY, "org.codehaus.spice.jndikit.memory.StaticMemoryInitialContextFactory");
         InitialContext ctx = new InitialContext(env);
-        RegistryHelper.registerRepository(ctx, "blah", configFile, factoryHomeDir, true);
-        Repository repo1 = (Repository) ctx.lookup("blah");
-        Repository repo2 = (Repository) ctx.lookup("blah");
+        RegistryHelper.registerRepository(ctx, "repo", configFile, repHomeDir, true);
+        Repository r = (Repository) ctx.lookup("repo");
 */
-        RepositoryFactory rf = RepositoryFactory.create(configFile, factoryHomeDir);
-        Repository r = rf.getRepository("localfs");
         Session session = r.login(new SimpleCredentials("anonymous", "".toCharArray()), null);
         Workspace wsp = session.getWorkspace();
 
@@ -93,12 +88,13 @@
 	String dvExportFilePath = "d:/temp/dv_export0.xml";
 	String importTargetName = "sandbox";
 
-	wsp.exportSysView("/", new FileOutputStream(svExportFilePath), true, false);
-	wsp.exportDocView("/", new FileOutputStream(dvExportFilePath), true, false);
+	//wsp.exportSysView("/", new FileOutputStream(svExportFilePath), true, false);
+	//wsp.exportDocView("/", new FileOutputStream(dvExportFilePath), true, false);
 	if (!root.hasNode(importTargetName)) {
 	    root.addNode(importTargetName, "nt:unstructured");
 	}
-	FileInputStream fin = new FileInputStream(svExportFilePath);
+	//FileInputStream fin = new FileInputStream(svExportFilePath);
+        FileInputStream fin = new FileInputStream("d:/temp/test.xml");
 	session.importXML("/" + importTargetName, fin);
 	session.save();
 */
@@ -140,7 +136,7 @@
         root.addNode("blu", "nt:folder");
         root.addNode("blu");
 
-        Properties repProps = ((RepositoryImpl) r).getProperties();
+        Properties repProps = r.getProperties();
         System.out.println("repository properties:");
         System.out.println(repProps);
 
@@ -274,11 +270,11 @@
         //wsp.exportSysView("/", new FileOutputStream("d:/temp/sv_export1.xml"), false, false);
         wsp.exportDocView("/", new FileOutputStream("d:/temp/dv_export1.xml"), false, false);
 
-        repProps = ((RepositoryImpl) r).getProperties();
+        repProps = r.getProperties();
         System.out.println("repository properties:");
         System.out.println(repProps);
 
-        ((RepositoryImpl) r).shutdown();
+        //((RepositoryImpl) r).shutdown();
     }
 
     public static void importNode(File file, Node parent) throws Exception {

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/WorkspaceImpl.java	Fri
Oct 15 10:01:13 2004
@@ -15,6 +15,7 @@
  */
 package org.apache.jackrabbit.core;
 
+import org.apache.jackrabbit.core.config.WorkspaceConfig;
 import org.apache.jackrabbit.core.nodetype.*;
 import org.apache.jackrabbit.core.search.QueryManagerImpl;
 import org.apache.jackrabbit.core.state.*;
@@ -53,9 +54,9 @@
     private static Logger log = Logger.getLogger(WorkspaceImpl.class);
 
     /**
-     * The name of this <code>Workspace</code>
+     * The configuration of this <code>Workspace</code>
      */
-    protected final String wspName;
+    protected final WorkspaceConfig wspConfig;
 
     /**
      * The repository that created this workspace instance
@@ -99,14 +100,14 @@
     /**
      * Package private constructor.
      *
-     * @param wspName
+     * @param wspConfig
      * @param persistentStateMgr
      * @param rep
      * @param session
      */
-    WorkspaceImpl(String wspName, PersistentItemStateManager persistentStateMgr,
+    WorkspaceImpl(WorkspaceConfig wspConfig, PersistentItemStateManager persistentStateMgr,
                   ReferenceManager refMgr, RepositoryImpl rep, SessionImpl session) {
-        this.wspName = wspName;
+        this.wspConfig = wspConfig;
         this.rep = rep;
         this.persistentStateMgr = persistentStateMgr;
         this.refMgr = refMgr;
@@ -134,7 +135,7 @@
      * @throws RepositoryException
      */
     void dump(PrintStream ps) throws RepositoryException {
-        ps.println("Workspace: " + wspName + " (" + this + ")");
+        ps.println("Workspace: " + wspConfig.getName() + " (" + this + ")");
         ps.println();
         persistentStateMgr.dump(ps);
     }
@@ -654,7 +655,7 @@
      * @see Workspace#getName
      */
     public String getName() {
-        return wspName;
+        return wspConfig.getName();
     }
 
     /**
@@ -865,7 +866,7 @@
             throws UnsupportedRepositoryOperationException, RepositoryException {
         if (obsMgr == null) {
             try {
-                obsMgr = rep.getObservationManagerFactory(wspName).createObservationManager(session,
session.getItemManager());
+                obsMgr = rep.getObservationManagerFactory(wspConfig.getName()).createObservationManager(session,
session.getItemManager());
             } catch (NoSuchWorkspaceException nswe) {
                 // should never get here
                 String msg = "internal error: failed to instantiate observation manager";
@@ -882,7 +883,7 @@
     public QueryManager getQueryManager() throws RepositoryException {
         if (queryManager == null) {
             try {
-                SearchManager searchManager = rep.getSearchManager(wspName);
+                SearchManager searchManager = rep.getSearchManager(wspConfig.getName());
                 if (searchManager == null) {
                     throw new UnsupportedOperationException("No search manager configured
for this workspace.");
                 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
==============================================================================
--- 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
Fri Oct 15 10:01:13 2004
@@ -157,6 +157,12 @@
         if (wspConfigs.isEmpty()) {
             // create initial default workspace
             createWorkspaceConfig(defaultWspName);
+        } else {
+            if (!wspConfigs.containsKey(defaultWspName)) {
+                String msg = "no configuration found for default workspace: " + defaultWspName;
+                log.error(msg);
+                throw new RepositoryException(msg);
+            }
         }
     }
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java
==============================================================================
--- 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
Fri Oct 15 10:01:13 2004
@@ -149,8 +149,7 @@
                 Object value = params.get(name);
                 bm.put(name, value);
             }
-            // @todo fix PersistenceManager initialization
-            //persistMgr.init(this);
+            persistMgr.init(this);
         } catch (Exception e) {
             log.error("Cannot instantiate implementing class " + className, e);
             throw new RepositoryException("Cannot instantiate implementing class " + className,
e);

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/jndi/BindableRepository.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/jndi/BindableRepository.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/jndi/BindableRepository.java
Fri Oct 15 10:01:13 2004
@@ -16,6 +16,7 @@
 package org.apache.jackrabbit.core.jndi;
 
 import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.apache.jackrabbit.core.RepositoryImpl;
 
 import javax.jcr.*;
 import javax.naming.NamingException;
@@ -70,8 +71,7 @@
 
     private void init() throws RepositoryException {
         RepositoryConfig config = RepositoryConfig.create(configFilePath, repHomeDir);
-        // @todo fix repository instantiation
-        //delegatee = new RepositoryImpl(config);
+        delegatee = RepositoryImpl.create(config);
     }
 
     //-----------------------------------------------------------< Repository >

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/PersistenceManager.java
==============================================================================
--- 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
Fri Oct 15 10:01:13 2004
@@ -16,7 +16,7 @@
 package org.apache.jackrabbit.core.state;
 
 import org.apache.jackrabbit.core.QName;
-import org.apache.jackrabbit.core.WorkspaceDef;
+import org.apache.jackrabbit.core.config.WorkspaceConfig;
 
 /**
  * <code>PersistenceManager</code> ...
@@ -24,10 +24,10 @@
 public interface PersistenceManager {
 
     /**
-     * @param wspDef
+     * @param wspConfig
      * @throws Exception
      */
-    public void init(WorkspaceDef wspDef) throws Exception;
+    public void init(WorkspaceConfig wspConfig) throws Exception;
 
     /**
      * @param uuid

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/xml/XMLPersistenceManager.java
==============================================================================
--- 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
Fri Oct 15 10:01:13 2004
@@ -16,10 +16,10 @@
 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.FileSystemException;
-import org.apache.jackrabbit.core.fs.FileSystemPathUtil;
-import org.apache.jackrabbit.core.fs.FileSystemResource;
+import org.apache.jackrabbit.core.fs.local.LocalFileSystem;
 import org.apache.jackrabbit.core.nodetype.NodeDefId;
 import org.apache.jackrabbit.core.nodetype.PropDefId;
 import org.apache.jackrabbit.core.state.*;
@@ -361,13 +361,21 @@
     /**
      * @see PersistenceManager#init
      */
-    public void init(WorkspaceDef wspDef) throws Exception {
-        itemStateStore = wspDef.getWorkspaceStore();
-        if (wspDef.getBlobStore() != null) {
-            blobStore = wspDef.getBlobStore();
-        } else {
-            blobStore = itemStateStore;
-        }
+    public void init(WorkspaceConfig wspConfig) throws Exception {
+        FileSystem wspFS = wspConfig.getFileSystem();
+        itemStateStore = new BasedFileSystem(wspFS, "/data");
+
+        //blobStore = new BasedFileSystem(wspFS, "/blobs");
+        /**
+         * store blob's in local file system in a sub directory
+         * of the workspace home directory
+         * todo make blob store configurable
+         */
+        LocalFileSystem blobFS = new LocalFileSystem();
+        blobFS.setPath(wspConfig.getHomeDir() + "/blobs");
+        blobFS.init();
+        blobStore = blobFS;
+
         initialized = true;
     }
 

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JackrabbitRepositoryStub.java
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JackrabbitRepositoryStub.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/JackrabbitRepositoryStub.java
Fri Oct 15 10:01:13 2004
@@ -15,10 +15,14 @@
  */
 package org.apache.jackrabbit.test;
 
-import org.apache.jackrabbit.core.RepositoryFactory;
+import org.apache.jackrabbit.core.jndi.RegistryHelper;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.apache.jackrabbit.core.RepositoryImpl;
 
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 import java.util.Properties;
 
 /**
@@ -27,19 +31,24 @@
 public class JackrabbitRepositoryStub extends RepositoryStub {
 
     /**
-     * Property for the repositry name
+     * Property for the repository name (used for jndi lookup)
      */
     public static final String PROP_REPOSITORY_NAME = "org.apache.jackrabbit.repository.name";
 
-    public static final String PROP_REPOSITRY_HOME = "org.apache.jackrabbit.repository.home";
+    /**
+     * Property for the repository configuration file (used for repository instantiation)
+     */
+    public static final String PROP_REPOSITORY_CONFIG = "org.apache.jackrabbit.repository.config";
+    /**
+     * Property for the repository home directory (used for repository instantiation)
+     */
+    public static final String PROP_REPOSITORY_HOME = "org.apache.jackrabbit.repository.home";
 
     /**
      * The repository instance
      */
     private Repository repository;
 
-    private RepositoryFactory factory;
-
     /**
      * Constructor as required by the JCR TCK.
      *
@@ -52,7 +61,7 @@
     /**
      * Returns the configured <code>Repository</code> instance.
      * <br>
-     * The default repository name is 'localfs'.
+     * The default repository name is 'repo'.
      *
      * @return the configured <code>Repository</code> instance.
      * @throws RepositoryStubException if an error occurs while
@@ -61,15 +70,25 @@
     public synchronized Repository getRepository() throws RepositoryStubException {
         if (repository == null) {
             try {
-                String repName = environment.getProperty(PROP_REPOSITORY_NAME, "localfs");
-                String repHome = environment.getProperty(PROP_REPOSITRY_HOME);
-                factory = RepositoryFactory.create(repHome + "/config.xml", repHome);
-                repository = factory.getRepository(repName);
+                String repName = environment.getProperty(PROP_REPOSITORY_NAME, "repo");
+                String repConfig = environment.getProperty(PROP_REPOSITORY_CONFIG);
+                String repHome = environment.getProperty(PROP_REPOSITORY_HOME);
+/*
+                RepositoryConfig repConf = RepositoryConfig.create(repConfig, repHome);
+                repository = RepositoryImpl.create(repConf);
+*/
+                InitialContext ctx = new InitialContext();
+                RegistryHelper.registerRepository(ctx, "repo", repConfig, repHome, true);
+                repository = (Repository) ctx.lookup("repo");
+/*
                 Runtime.getRuntime().addShutdownHook(new Thread() {
                     public void run() {
-                        factory.shutdown();
+                        repository.shutdown();
                     }
                 });
+*/
+            } catch (NamingException e) {
+                throw new RepositoryStubException(e.toString());
             } catch (RepositoryException e) {
                 throw new RepositoryStubException(e.toString());
             }

Mime
View raw message