jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1128339 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/ main/java/org/apache/jackrabbit/spi2microkernel/util/ test/java/org/apache/jackrabbit/spi2microkernel/
Date Fri, 27 May 2011 14:55:09 GMT
Author: mduerig
Date: Fri May 27 14:55:08 2011
New Revision: 1128339

URL: http://svn.apache.org/viewvc?rev=1128339&view=rev
Log:
spi2microkernel prototype (WIP)

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTests.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1128339&r1=1128338&r2=1128339&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Fri May 27 14:55:08 2011
@@ -54,7 +54,11 @@ import java.util.Map;
 
 public class RepositoryServiceImpl extends AbstractRepositoryService {
     private static final Map<String, QValue[]> DESCRIPTORS = new HashMap<String,
QValue[]>() {{
-        put(Repository.NODE_TYPE_MANAGEMENT_SAME_NAME_SIBLINGS_SUPPORTED, new QValue[] {
Values.FALSE });
+        QValue[] FALSE = new QValue[]{Values.FALSE};
+        QValue[] TRUE = new QValue[]{Values.TRUE};
+
+        put(Repository.NODE_TYPE_MANAGEMENT_SAME_NAME_SIBLINGS_SUPPORTED, FALSE);
+        put(Repository.OPTION_WORKSPACE_MANAGEMENT_SUPPORTED, TRUE);
     }};
 
     private static final Map<String, String> NAMESPACES = Collections.emptyMap();
@@ -67,7 +71,10 @@ public class RepositoryServiceImpl exten
 
         try {
             microKernel = new MicroKernelImpl(homeDir);  // xxx who disposes the micro kernel?
-            // todo add default and system wsp if necessary
+
+            String head = microKernel.getHeadRevision();
+            createWorkspace(head, Paths.DEFAULT_WORKSPACE, true);
+            createWorkspace(head, Paths.SYSTEM_WORKSPACE, true);            
         }
         catch (MicroKernelException e) {
             throw new RepositoryException(e.getMessage(), e); 
@@ -107,6 +114,11 @@ public class RepositoryServiceImpl exten
     }
 
     public String[] getWorkspaceNames(SessionInfo sessionInfo) throws RepositoryException
{
+        String rev = getRevision(sessionInfo);
+        String json = microKernel.getNodes("/", 0, rev);
+
+        // Names of first level nodes correspond to workspace names
+
         return new String[0]; // todo implement getWorkspaceNames
     }
 
@@ -197,6 +209,25 @@ public class RepositoryServiceImpl exten
         throw new UnsupportedRepositoryOperationException();
     }
 
+    //------------------------------------------< Workspace management >---
+
+    @Override
+    public void createWorkspace(SessionInfo sessionInfo, String name, String srcWorkspaceName)
throws RepositoryException {
+        String rev = getRevision(sessionInfo);
+        if (srcWorkspaceName == null) {
+            createWorkspace(rev, name, false);
+        }
+        else {
+            copyWorkspace(rev, name, srcWorkspaceName);
+        }
+    }
+
+    @Override
+    public void deleteWorkspace(SessionInfo sessionInfo, String name) throws RepositoryException
{
+        String rev = getRevision(sessionInfo);
+        deleteWorkspace(rev, name);
+    }
+
     //------------------------------------------< private >---
 
     private String getRevision(SessionInfo sessionInfo) throws RepositoryException {
@@ -219,4 +250,28 @@ public class RepositoryServiceImpl exten
         }
     }
 
+    private void createWorkspace(String revisionId, String name, boolean ignoreExisting)
throws RepositoryException {
+        String wspName = Paths.getWorkspaceName(name);
+        if (microKernel.nodeExists('/' + wspName, revisionId)) {
+            if (ignoreExisting) {
+                return;
+            }
+            else {
+                throw new RepositoryException("Workspace already exists: " + name);
+            }
+        }
+
+        microKernel.commit("/", '+' + wspName + " : {}" , revisionId);
+    }
+
+    private void copyWorkspace(String revisionId, String name, String srcWorkspaceName) throws
RepositoryException {
+        // todo implement copyWorkspace
+        throw new UnsupportedRepositoryOperationException();
+    }
+
+    private void deleteWorkspace(String revisionId, String name)  throws RepositoryException
{
+        // todo implement deleteWorkspace
+        throw new UnsupportedRepositoryOperationException();
+    }
+
 }

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java?rev=1128339&r1=1128338&r2=1128339&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Paths.java
Fri May 27 14:55:08 2011
@@ -27,7 +27,8 @@ import org.apache.jackrabbit.spi.commons
 import javax.jcr.RepositoryException;
 
 public final class Paths {
-    public static final String ROOT = "/";
+    public static final String DEFAULT_WORKSPACE = "default";
+    public static final String SYSTEM_WORKSPACE = "system";
 
     private static final NameFactory NAME_FACTORY = NameFactoryImpl.getInstance();
 
@@ -45,7 +46,19 @@ public final class Paths {
     }
 
     public static String translateQPath(String wspName, Path path) throws RepositoryException
{
-        return translateQPath(path); // todo honor wspName
+        return cat('/' + getWorkspaceName(wspName), translateQPath(path));
+    }
+
+    public static String getWorkspaceName(String name) throws RepositoryException {
+        if (name == null || "".equals(name)) {
+            return DEFAULT_WORKSPACE;
+        }
+        else if (name.contains("/")) {
+            throw new RepositoryException("Invalid workspace name: " + name);
+        }
+        else {
+            return name;
+        }
     }
 
     //------------------------------------------< private >---
@@ -59,14 +72,18 @@ public final class Paths {
     }
 
     private static String cat(String absPath, String relPath) {
-        return ROOT.equals(absPath)
-            ? absPath + relPath
-            : absPath + '/' + relPath;
+        if ("".equals(absPath)) {
+            return relPath;
+        }
+        if ("".equals(relPath)) {
+            return absPath;
+        }
+        return absPath + '/' + relPath;
     }
 
     private static String translateQPath(Path path) throws RepositoryException {
         return path.denotesRoot()
-            ? "/"
+            ? ""
             : cat(translateQPath(path.getAncestor(1)), translateQName(path.getName()));
     }
 

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTests.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTests.java?rev=1128339&r1=1128338&r2=1128339&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTests.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTests.java
Fri May 27 14:55:08 2011
@@ -41,8 +41,7 @@ public class MicrokernelTests {
         }
     }
 
-    @Ignore
-    // todo fix in microkernel
+    @Ignore  // todo fix in microkernel
     @Test
     public void missingName() {
         MicroKernelImpl mk = new MicroKernelImpl(REPO_HOME_DIR.getAbsolutePath());

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java?rev=1128339&r1=1128338&r2=1128339&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/Tests.java
Fri May 27 14:55:08 2011
@@ -48,13 +48,14 @@ public class Tests {
         MicroKernelImpl mk = new MicroKernelImpl(REPO_HOME_DIR.getAbsolutePath());
         String head = mk.getHeadRevision();
 
-        if (!mk.nodeExists("/{}foo", head)) {
+        if (!mk.nodeExists("/default", head)) {
             mk.commit("/",
-                "+{}foo : {" +
-                    "\"{}stringProp\":\"stringVal\"," +
-                    "\"{}intProp\":42," +
-                    "\"{}mvProp\":[1,2,3]} " +
-                "\r+{}bar : {}", head);
+                "+default : {" +
+                    "\"{}foo\" : {" +
+                        "\"{}stringProp\":\"stringVal\"," +
+                        "\"{}intProp\":42," +
+                        "\"{}mvProp\":[1,2,3]} " +
+                    "\"{}bar\" : {}}", head);
         }
     }
 
@@ -71,6 +72,12 @@ public class Tests {
     }
 
     @Test
+    public void getWorkspaceNames() throws RepositoryException {
+        Session session = getSession();
+        String[] workspaces = session.getWorkspace().getAccessibleWorkspaceNames();
+    }
+
+    @Test
     public void getRoot() throws RepositoryException {
         Session session = getSession();
         Node root = session.getRootNode();



Mime
View raw message