jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1138867 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Date Thu, 23 Jun 2011 13:15:45 GMT
Author: mduerig
Date: Thu Jun 23 13:15:45 2011
New Revision: 1138867

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

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java?rev=1138867&r1=1138866&r2=1138867&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
Thu Jun 23 13:15:45 2011
@@ -28,11 +28,13 @@ import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.PropertyId;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.Subscription;
 import org.apache.jackrabbit.spi.commons.EventBundleImpl;
 import org.apache.jackrabbit.spi.commons.EventImpl;
 import org.apache.jackrabbit.spi.commons.identifier.IdFactoryImpl;
+import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
 import org.apache.jackrabbit.spi2microkernel.util.Paths;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
@@ -109,9 +111,38 @@ public class SubscriptionImpl implements
         }
     }
 
+    private static PropertyId createPropertyId(NodeId parentId, Name name) {
+        return IdFactoryImpl.getInstance().createPropertyId(parentId, name);
+    }
+
+    private static NodeId createNodeId(Path path) {
+        return IdFactoryImpl.getInstance().createNodeId((String) null, path);
+    }
+
+    private static Path getParent(Path path) {
+        try {
+            return path.getAncestor(1);
+        }
+        catch (RepositoryException e) {
+            // todo log
+            return null;
+        }
+    }
+
+    private static Path createPath(Path parent, Name name) {
+        try {
+            return PathFactoryImpl.getInstance().create(parent, name, true);
+        }
+        catch (RepositoryException e) {
+            // todo log
+            return null;
+        }
+    }
+
     private class EventSource {
         private final EventFilter[] eventFilters;
         private final List<String> commitLog;
+
         private final String startRevision;
 
         public EventSource(EventFilter[] eventFilters, SessionState sessionState) {
@@ -161,10 +192,10 @@ public class SubscriptionImpl implements
         }
 
         //------------------------------------------< private >---
-        
+
         private EventBundle createEventBundle(JSONObject jsonObject) {
             String revisionId = getString(jsonObject, "id", false);
-            String userData = getString(jsonObject, "msg", true);  
+            String userData = getString(jsonObject, "msg", true);
 
             EventTemplate eventTemplate = new EventTemplate()
                     .setTimestamp(getLong(jsonObject, "ts"))
@@ -200,7 +231,7 @@ public class SubscriptionImpl implements
                     case '-': removeNode(jsopTokenizer, eventTemplate, events); break;
                     case '^': setProperty(jsopTokenizer, eventTemplate, events); break;
                     case '>': moveNode(jsopTokenizer, eventTemplate, events); break;
-                    default: // todo log and continue
+                    default: // todo log
                 }
             }
 
@@ -210,46 +241,56 @@ public class SubscriptionImpl implements
         // Event#NODE_ADDED} Event#NODE_REMOVED} Event#PROPERTY_ADDED} Event#PROPERTY_REMOVED}
         // Event#PROPERTY_CHANGED} Event#NODE_MOVED} Event#PERSIST}
         private void addItem(JsopTokenizer jsopTokenizer, EventTemplate eventTemplate, Collection<Event>
events) {
-            EventTemplate addNodeEvent = eventTemplate.copy();
-
             Path path = Paths.stringToPath(jsopTokenizer.readString());
-            addNodeEvent.setPath(path);
+            NodeId parentId = createNodeId(getParent(path));
 
-            jsopTokenizer.read(':');
+            addItem(jsopTokenizer, eventTemplate, events, path, parentId);
+        }
 
-            NodeId parentId = null;
-            try {
-                parentId = IdFactoryImpl.getInstance().createNodeId((String) null, path.getAncestor(1));
-                addNodeEvent.setParentId(parentId);
-            }
-            catch (RepositoryException e) {
-                e.printStackTrace();  // todo log
-            }
+        private void addItem(JsopTokenizer jsopTokenizer, EventTemplate eventTemplate, Collection<Event>
events,
+                Path path, NodeId parentId) {
+
+            EventTemplate addItemEvent = eventTemplate.copy();
+            addItemEvent.setPath(path);
+            addItemEvent.setParentId(parentId);
+            // todo set primaryType, mixinTypes
+            // this needs context in the journal in the case of property events
+            // fixme it seems type based filtering does not respect the type hierarchy (see
JCR-2542)
 
-            ItemId itemId;
+            jsopTokenizer.read(':');
             if (jsopTokenizer.read() == '{') {
-                addNodeEvent.setType(Event.NODE_ADDED);
-                itemId = IdFactoryImpl.getInstance().createNodeId((String) null, path);
-                // todo parse inner cruft
+                addItemEvent.setType(Event.NODE_ADDED);
+                NodeId nodeId = createNodeId(path);
+                addItemEvent.setItemId(nodeId);
+                events.add(addItemEvent.buildEvent());
+                addInnerItems(jsopTokenizer, eventTemplate, events, nodeId);
             }
             else {
-                addNodeEvent.setType(Event.PROPERTY_ADDED);
-                itemId = IdFactoryImpl.getInstance().createPropertyId(parentId, path.getName());
+                addItemEvent.setType(Event.PROPERTY_ADDED);
+                addItemEvent.setItemId(createPropertyId(parentId, path.getName()));
+                events.add(addItemEvent.buildEvent());
             }
-            addNodeEvent.setItemId(itemId);
+        }
+
+        private void addInnerItems(JsopTokenizer jsopTokenizer, EventTemplate eventTemplate,
Collection<Event> events,
+                NodeId parentId) {
 
-            // todo set type info
-            // todo need more context in journal in case of property mod
-            // todo it seems type filtering does not respect the type hierarchy (https://issues.apache.org/jira/browse/JCR-2542)
-            Name primaryNodeTypeName = null;
-            Name[] mixinTypeNames = null;
+            int tokenType;
+            while ((tokenType = jsopTokenizer.read()) != '}' && tokenType != JsopTokenizer.END)
{
+                if (tokenType == ',') {
+                    jsopTokenizer.read();
+                }
+                
+                Name name = Paths.stringToName(jsopTokenizer.getToken());
+                Path path = createPath(parentId.getPath(), name);
 
-            events.add(addNodeEvent.buildEvent());
+                addItem(jsopTokenizer, eventTemplate, events, path, parentId);
+            }
         }
 
         private void removeNode(JsopTokenizer jsopTokenizer, EventTemplate eventTemplate,
Collection<Event> events) {
             // todo implement removeNode
-            // todo consider ways to handle deep mods
+            // todo consider ways to handle removal of large sub trees
         }
 
         private void setProperty(JsopTokenizer jsopTokenizer, EventTemplate eventTemplate,
Collection<Event> events) {
@@ -259,7 +300,7 @@ public class SubscriptionImpl implements
         private void moveNode(JsopTokenizer jsopTokenizer, EventTemplate eventTemplate, Collection<Event>
events) {
             // todo implement moveNode
         }
-        
+
         private String getString(JSONObject jsonObject, String key, boolean allowNull) {
             Object o = jsonObject.get(key);
             if (o instanceof String || allowNull && o == null) {

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java?rev=1138867&r1=1138866&r2=1138867&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Thu Jun 23 13:15:45 2011
@@ -922,6 +922,7 @@ public class RepositoryTest {
             Event.PROPERTY_REMOVED | Event.PROPERTY_CHANGED | Event.PERSIST, "/", true, null,
null, false);
 
         Node n = getNode(testPath);
+        n.setProperty("prop", "val");
         Node n1 = n.addNode("1");
         n1.setProperty("prop1", "val1");
         n1.setProperty("prop2", "val2");



Mime
View raw message