jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1158460 - in /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel: RepositoryServiceImpl.java util/ItemInfos.java
Date Tue, 16 Aug 2011 22:07:05 GMT
Author: mduerig
Date: Tue Aug 16 22:07:05 2011
New Revision: 1158460

URL: http://svn.apache.org/viewvc?rev=1158460&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1158460&r1=1158459&r2=1158460&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Tue Aug 16 22:07:05 2011
@@ -35,7 +35,6 @@ import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.NodeInfo;
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.PropertyId;
-import org.apache.jackrabbit.spi.PropertyInfo;
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.spi.QValue;
@@ -125,8 +124,6 @@ import static org.apache.jackrabbit.spi.
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.ROOT;
 import static org.apache.jackrabbit.spi2microkernel.util.Arrays.contains;
 import static org.apache.jackrabbit.spi2microkernel.util.ItemInfos.buildItemInfos;
-import static org.apache.jackrabbit.spi2microkernel.util.ItemInfos.buildNodeInfo;
-import static org.apache.jackrabbit.spi2microkernel.util.ItemInfos.buildPropertyInfo;
 import static org.apache.jackrabbit.spi2microkernel.util.Maps.getOrElse;
 import static org.apache.jackrabbit.spi2microkernel.util.Predicates.containsElement;
 import static org.apache.jackrabbit.spi2microkernel.util.Predicates.exists;
@@ -332,28 +329,18 @@ public class RepositoryServiceImpl exten
 
     public Iterator<? extends ItemInfo> getItemInfos(SessionInfo sessionInfo, ItemId
itemId) throws RepositoryException {
         try {
-            String wspName = sessionInfo.getWorkspaceName();
-            Path path = getPath(itemId);
+            Path itemPath = getPath(itemId);
+            Path nodePath = itemId.denotesNode() ? itemPath : itemPath.getAncestor(1);
             String rev = microKernel.getHeadRevision();
-            String mkPath = Paths.pathToString(wspName, itemId.denotesNode() ? path : path.getAncestor(1));
+            String mkPath = Paths.pathToString(sessionInfo.getWorkspaceName(), nodePath);
 
             if (!microKernel.nodeExists(mkPath, rev)) {
-                throw new PathNotFoundException(path.toString());
+                throw new PathNotFoundException(itemPath.toString());
             }
 
             String json = microKernel.getNodes(mkPath, rev);
-
-            if (itemId.denotesNode()) {
-                return buildItemInfos(path, json, readFromDataStore);
-            }
-            else {
-                PropertyInfo info = buildPropertyInfo(path, json, readFromDataStore);
-                if (info == null) {
-                    throw new PathNotFoundException(path.toString());
-                }
-
-                return Iterators.singleton(info);
-            }
+            Iterator<? extends ItemInfo> infos = buildItemInfos(nodePath, itemPath,
json, false, readFromDataStore);
+            return infos;
         }
         catch (MicroKernelException e) {
             throw new RepositoryException(e.getMessage(), e);
@@ -362,9 +349,8 @@ public class RepositoryServiceImpl exten
 
     public Iterator<ChildInfo> getChildInfos(SessionInfo sessionInfo, NodeId parentId)
throws RepositoryException {
         try {
-            String wspName = sessionInfo.getWorkspaceName();
             Path path = getPath(parentId);
-            String mkPath = Paths.pathToString(wspName, path);
+            String mkPath = Paths.pathToString(sessionInfo.getWorkspaceName(), path);
             String rev = microKernel.getHeadRevision();
 
             if (!microKernel.nodeExists(mkPath, rev)) {
@@ -372,11 +358,8 @@ public class RepositoryServiceImpl exten
             }
 
             String json = microKernel.getNodes(mkPath, rev);
-            NodeInfo info = buildNodeInfo(path, json, readFromDataStore);
-            if (info == null) {
-                throw new PathNotFoundException(path.toString());
-            }
-
+            Iterator<? extends ItemInfo> infos = buildItemInfos(path, path, json, true,
readFromDataStore);
+            NodeInfo info = (NodeInfo) infos.next();
             return info.getChildInfos();
         }
         catch (MicroKernelException e) {

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java?rev=1158460&r1=1158459&r2=1158460&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
Tue Aug 16 22:07:05 2011
@@ -31,113 +31,72 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.Listener;
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.NodeInfoBuilder;
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.PropertyInfoBuilder;
+import org.apache.jackrabbit.spi.commons.iterator.Iterators;
 import org.json.simple.parser.JSONParser;
 import org.json.simple.parser.ParseException;
 
+import javax.jcr.PathNotFoundException;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedList;
+import java.util.List;
 
-import static org.apache.jackrabbit.spi.commons.name.NameConstants.*;
+import static org.apache.jackrabbit.spi.commons.iterator.Iterators.*;
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_MIXINTYPES;
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_PRIMARYTYPE;
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_UUID;
 import static org.apache.jackrabbit.spi2microkernel.util.Exceptions.setCause;
 import static org.json.simple.parser.ParseException.ERROR_UNEXPECTED_EXCEPTION;
 
 public final class ItemInfos {
     private ItemInfos() {}
 
-    public static Iterator<? extends ItemInfo> buildItemInfos(Path path, String json,
Function1<String, QValue> binaryHandler)
-            throws RepositoryException {
+    public static Iterator<? extends ItemInfo> buildItemInfos(Path rootPath, final
Path targetPath,
+            String json, final boolean stopOnTarget, Function1<String, QValue> binaryHandler)
throws RepositoryException {
 
-        final LinkedList<ItemInfo> itemInfos = new LinkedList<ItemInfo>();
+        final List<ItemInfo> itemInfos = new ArrayList<ItemInfo>();
+        final ItemInfo[] targetInfo = new ItemInfo[1];
 
         InfoListener infoListener = new InfoListener() {
             public void createNodeInfo(NodeInfo nodeInfo) {
-                if (nodeInfo.getChildInfos() != null) {
-                    // null child node infos indicate an empty node. Do not include!
-                    itemInfos.addFirst(nodeInfo);
+                if (nodeInfo.getChildInfos() != null) {  // null indicates an empty node.
Do not include!
+                    if (targetPath.equals(nodeInfo.getPath())) {
+                        targetInfo[0] = nodeInfo;
+                    }
+                    else {
+                        itemInfos.add(nodeInfo);
+                    }
                 }
             }
 
-            public void createChildInfos(NodeId id, Iterator<ChildInfo> childInfos)
{}
-
             public void createPropertyInfo(PropertyInfo propertyInfo) {
-                itemInfos.addFirst(propertyInfo);
-            }
-
-            public boolean done() {
-                return false;
-            }
-        };
-
-        try {
-            JSONParser parser = new JSONParser();
-            JsonHandler handler = new JsonHandler(parent(path), path.getName(), infoListener,
binaryHandler);
-            parser.parse(json, handler);
-            return itemInfos.iterator();
-        }
-        catch (ParseException e) {
-            throw new RepositoryException(e.getMessage(), e);
-        }
-    }
-
-    public static NodeInfo buildNodeInfo(final Path path, String json, Function1<String,
QValue> binaryHandler)
-            throws RepositoryException {
-
-        final NodeInfo[] nodeInfos = new NodeInfo[1];
-
-        InfoListener infoListener = new InfoListener() {
-            public void createNodeInfo(NodeInfo nodeInfo) {
-                if (path.equals(nodeInfo.getPath())) {
-                    nodeInfos[0] = nodeInfo;
+                if (targetPath.equals(propertyInfo.getPath())) {
+                    targetInfo[0] = propertyInfo;
+                }
+                else {
+                    itemInfos.add(propertyInfo);
                 }
             }
 
             public void createChildInfos(NodeId id, Iterator<ChildInfo> childInfos)
{}
-            public void createPropertyInfo(PropertyInfo propertyInfo) {}
 
             public boolean done() {
-                return nodeInfos[0] != null;
+                return stopOnTarget && targetInfo[0] != null;
             }
         };
 
         try {
             JSONParser parser = new JSONParser();
-            JsonHandler handler = new JsonHandler(parent(parent(path)), parent(path).getName(),
infoListener, binaryHandler);
+            JsonHandler handler = new JsonHandler(parent(rootPath), rootPath.getName(), infoListener,
binaryHandler);
             parser.parse(json, handler);
-            return nodeInfos[0];
-        }
-        catch (ParseException e) {
-            throw new RepositoryException(e.getMessage(), e);
-        }
-    }
-
-    public static PropertyInfo buildPropertyInfo(final Path path, String json, Function1<String,
QValue> binaryHandler)
-            throws RepositoryException {
-        
-        final PropertyInfo[] propertyInfos = new PropertyInfo[1];
-
-        InfoListener infoListener = new InfoListener() {
-            public void createNodeInfo(NodeInfo nodeInfo) {}
-            public void createChildInfos(NodeId id, Iterator<ChildInfo> childInfos)
{}
-
-            public void createPropertyInfo(PropertyInfo propertyInfo) {
-                if (path.equals(propertyInfo.getPath())) {
-                    propertyInfos[0] = propertyInfo;
-                }
+            if (targetInfo[0] == null) {
+                throw new PathNotFoundException(targetPath.toString());
             }
-
-            public boolean done() {
-                return propertyInfos[0] != null;
-            }
-        };
-
-        try {
-            JSONParser parser = new JSONParser();
-            JsonHandler handler = new JsonHandler(parent(parent(path)), parent(path).getName(),
infoListener, binaryHandler);
-            parser.parse(json, handler);
-            return propertyInfos[0];
+            
+            return iteratorChain(singleton(targetInfo[0]), itemInfos.iterator());
         }
         catch (ParseException e) {
             if (e.getCause() instanceof RepositoryException) {



Mime
View raw message