You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by st...@apache.org on 2005/01/07 15:48:49 UTC

svn commit: r124504 - /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java

Author: stefan
Date: Fri Jan  7 06:48:46 2005
New Revision: 124504

URL: http://svn.apache.org/viewcvs?view=rev&rev=124504
Log:
fixed creation of workspaces through api
Modified:
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.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=124504&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java&r1=124503&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java&r2=124504
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java	Fri Jan  7 06:48:46 2005
@@ -263,25 +263,11 @@
 
         ntReg = NodeTypeRegistry.create(nsReg, new BasedFileSystem(repStore, "/nodetypes"));
 
-        /**
-         * todo implement 'System' workspace
-         * - the system workspace should have the /jcr:system node
-         * - versions, version history and node types should be reflected in
-         *   this system workspace as content under /jcr:system
-         * - all other workspaces should be dynamic workspaces based on
-         *   this 'read-only' system workspace
-         */
-
-        // check system root node of system workspace
-        // (for now, we just create a system root node in all workspaces)
-        Iterator wspNames = wspInfos.keySet().iterator();
-        while (wspNames.hasNext()) {
-            String wspName = (String) wspNames.next();
-            NodeImpl rootNode = (NodeImpl) getSystemSession(wspName).getRootNode();
-            if (!rootNode.hasNode(SYSTEM_ROOT_NAME)) {
-                rootNode.addNode(SYSTEM_ROOT_NAME, NodeTypeRegistry.REP_SYSTEM);
-                rootNode.save();
-            }
+        // initialize workspaces
+        iter = wspInfos.keySet().iterator();
+        while (iter.hasNext()) {
+            String wspName = (String) iter.next();
+            initWorkspace(wspName);
         }
 
         // init version manager
@@ -296,29 +282,6 @@
         nodesCount = Long.parseLong(repProps.getProperty(STATS_NODE_COUNT_PROPERTY, "0"));
         propsCount = Long.parseLong(repProps.getProperty(STATS_PROP_COUNT_PROPERTY, "0"));
 
-        // get the system session for every defined workspace and
-        // register as an event listener
-        iter = wspInfos.values().iterator();
-        while (iter.hasNext()) {
-            String wspName = ((WorkspaceInfo) iter.next()).getName();
-            Session s = getSystemSession(wspName);
-            s.getWorkspace().getObservationManager().addEventListener(this,
-                    Event.NODE_ADDED | Event.NODE_REMOVED
-                    | Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED,
-                    "/", true, null, null, false);
-
-            // register SearchManager as EventListener
-            SearchManager searchMgr = getSearchManager(wspName);
-
-            if (searchMgr != null) {
-                s.getWorkspace().getObservationManager().addEventListener(searchMgr,
-                        Event.NODE_ADDED | Event.NODE_REMOVED |
-                        Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED |
-                        Event.PROPERTY_CHANGED,
-                        "/", true, null, null, false);
-            }
-        }
-
         // finally register shutdown hook
         Runtime.getRuntime().addShutdownHook(new Thread() {
             public void run() {
@@ -341,6 +304,46 @@
         return new RepositoryImpl(config);
     }
 
+    private void initWorkspace(String wspName) throws RepositoryException {
+        // get system session and Workspace instance
+        SessionImpl sysSession = getSystemSession(wspName);
+        WorkspaceImpl wsp = (WorkspaceImpl) sysSession.getWorkspace();
+
+        /**
+         * todo implement 'System' workspace
+         * FIXME
+         * - the should be one 'System' workspace per repositoy
+         * - the 'System' workspace should have the /jcr:system node
+         * - versions, version history and node types should be reflected in
+         *   this system workspace as content under /jcr:system
+         * - all other workspaces should be dynamic workspaces based on
+         *   this 'read-only' system workspace
+         *
+         * for now, we just create a /jcr:system node in every workspace
+         */
+        NodeImpl rootNode = (NodeImpl) sysSession.getRootNode();
+        if (!rootNode.hasNode(SYSTEM_ROOT_NAME)) {
+            rootNode.addNode(SYSTEM_ROOT_NAME, NodeTypeRegistry.REP_SYSTEM);
+            rootNode.save();
+        }
+
+        // register the repository as event listener for keeping repository statistics
+        wsp.getObservationManager().addEventListener(this,
+                Event.NODE_ADDED | Event.NODE_REMOVED
+                | Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED,
+                "/", true, null, null, false);
+
+        // register SearchManager as event listener
+        SearchManager searchMgr = getSearchManager(wspName);
+        if (searchMgr != null) {
+            wsp.getObservationManager().addEventListener(searchMgr,
+                    Event.NODE_ADDED | Event.NODE_REMOVED |
+                    Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED |
+                    Event.PROPERTY_CHANGED,
+                    "/", true, null, null, false);
+        }
+    }
+
     RepositoryConfig getConfig() {
         // check state
         if (disposed) {
@@ -390,8 +393,9 @@
      * Returns the names of all workspaces of this repository.
      *
      * @return the names of all workspaces of this repository.
+     * @see SessionImpl#getWorkspaceNames
      */
-    protected String[] getWorkspaceNames() {
+    String[] getWorkspaceNames() {
         return (String[]) wspInfos.keySet().toArray(new String[wspInfos.keySet().size()]);
     }
 
@@ -401,8 +405,9 @@
      * @param workspaceName name of the new workspace
      * @throws RepositoryException if a workspace with the given name
      *                             already exists or if another error occurs
+     * @see SessionImpl#createWorkspace(String)
      */
-    public void createWorkspace(String workspaceName) throws RepositoryException {
+     synchronized void createWorkspace(String workspaceName) throws RepositoryException {
         if (wspInfos.containsKey(workspaceName)) {
             throw new RepositoryException("workspace '" + workspaceName + "' already exists.");
         }
@@ -411,6 +416,9 @@
         WorkspaceConfig config = repConfig.createWorkspaceConfig(workspaceName);
         WorkspaceInfo info = new WorkspaceInfo(config);
         wspInfos.put(workspaceName, info);
+
+        // setup/initialize new workspace
+        initWorkspace(workspaceName);
     }
 
     PersistentItemStateProvider getWorkspaceStateManager(String workspaceName)

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java?view=diff&rev=124504&p1=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java&r1=124503&p2=incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java&r2=124504
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java	Fri Jan  7 06:48:46 2005
@@ -23,7 +23,6 @@
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.PersistentItemStateProvider;
 import org.apache.jackrabbit.core.state.SessionItemStateManager;
-import org.apache.jackrabbit.core.version.VersionManagerImpl;
 import org.apache.jackrabbit.core.version.VersionManager;
 import org.apache.jackrabbit.core.xml.ImportHandler;
 import org.apache.log4j.Logger;
@@ -329,10 +328,23 @@
      * Returns the names of all workspaces of this repository with respect of the
      * access rights of this session.
      *
-     * @return the names of all workspaces of this repository.
+     * @return the names of all accessible workspaces
      */
     public String[] getWorkspaceNames() {
+        // @todo filter workspace names based on credentials of this session
         return rep.getWorkspaceNames();
+    }
+
+    /**
+     * Creates a workspace with the given name.
+     *
+     * @param workspaceName name of the new workspace
+     * @throws RepositoryException if a workspace with the given name
+     *                             already exists or if another error occurs
+     */
+    public void createWorkspace(String workspaceName) throws RepositoryException {
+        // @todo verify that this session has the right privileges for this operation
+        rep.createWorkspace(workspaceName);
     }
 
     /**