jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1099493 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store: DiffBuilder.java RevisionDiffBuilder.java
Date Wed, 04 May 2011 15:42:34 GMT
Author: stefan
Date: Wed May  4 15:42:33 2011
New Revision: 1099493

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

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/RevisionDiffBuilder.java
      - copied, changed from r1098632, jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DiffBuilder.java
Removed:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DiffBuilder.java

Copied: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/RevisionDiffBuilder.java
(from r1098632, jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DiffBuilder.java)
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/RevisionDiffBuilder.java?p2=jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/RevisionDiffBuilder.java&p1=jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DiffBuilder.java&r1=1098632&r2=1099493&rev=1099493&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/DiffBuilder.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/RevisionDiffBuilder.java
Wed May  4 15:42:33 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.mk.store;
 
+import org.apache.jackrabbit.mk.Repository;
+
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
@@ -23,78 +25,96 @@ import java.util.Set;
 /**
  *
  */
-public class DiffBuilder {
+public class RevisionDiffBuilder {
 
-    final Node before;
-    final Node after;
-    final DiffHandler handler;
-
-    public DiffBuilder(Node before, Node after, DiffHandler handler) {
-        this.before = before;
-        this.after = after;
+    final String revisionId1;
+    final String revisionId2;
+    final Repository rep;
+    final RevisionDiffHandler handler;
+
+    public RevisionDiffBuilder(String revisionId1, String revisionId2, Repository rep, RevisionDiffHandler
handler) {
+        this.revisionId1 = revisionId1;
+        this.revisionId2 = revisionId2;
+        this.rep = rep;
         this.handler = handler;
     }
 
-    public void build() {
+    public void build() throws Exception {
+        // start at root node
+        String path = "/";
+        Node node1 = rep.getNode(revisionId1, path);
+        Node node2 = rep.getNode(revisionId2, path);
+
+        diff(path, node1, node2);
+    }
+
+    void diff(String path, Node node1, Node node2) throws Exception {
 
         // compare properties
-        Map<String, String> oldProps = before.getProperties();
-        Map<String, String> newProps = after.getProperties();
+        Map<String, String> oldProps = node1.getProperties();
+        Map<String, String> newProps = node2.getProperties();
         if (!oldProps.equals(newProps)) {
             Set<String> set = new HashSet<String>();
             set.addAll(oldProps.keySet());
             set.removeAll(newProps.keySet());
             for (String name : set) {
-                handler.propDeleted(name);
+                handler.propDeleted(path, name);
             }
             set.clear();
             set.addAll(newProps.keySet());
             set.removeAll(oldProps.keySet());
             for (String name : set) {
-                handler.propAdded(name, newProps.get(name));
+                handler.propAdded(path, name, newProps.get(name));
             }
             for (Map.Entry<String, String> entry : oldProps.entrySet()) {
                 String val = newProps.get(entry.getKey());
                 if (val != null && !entry.getValue().equals(val)) {
-                    handler.propChanged(entry.getKey(), entry.getValue(), val);
+                    handler.propChanged(path, entry.getKey(), entry.getValue(), val);
                 }
             }
         }
 
+        // todo determine copy/move and child-node reorder operations
+
         // compare child node entries
-        Map<String, String> oldEntries = before.getChildNodeEntries();
-        Map<String, String> newEntries = after.getChildNodeEntries();
+        Map<String, String> oldEntries = node1.getChildNodeEntries();
+        Map<String, String> newEntries = node2.getChildNodeEntries();
         if (!oldEntries.equals(newEntries)) {
             Set<String> set = new HashSet<String>();
             set.addAll(oldEntries.keySet());
             set.removeAll(newEntries.keySet());
             for (String name : set) {
-                handler.nodeDeleted(name);
+                handler.childNodeDeleted(path, name, oldEntries.get(name));
             }
             set.clear();
             set.addAll(newEntries.keySet());
             set.removeAll(oldEntries.keySet());
             for (String name : set) {
-                handler.nodeAdded(name, newEntries.get(name));
+                handler.childNodeAdded(path, name, newEntries.get(name));
             }
             for (Map.Entry<String, String> entry : oldEntries.entrySet()) {
                 String id = newEntries.get(entry.getKey());
                 if (id != null && !entry.getValue().equals(id)) {
-                    handler.nodeChanged(entry.getKey(), entry.getValue(), id);
+                    node1 = rep.getStore().getNode(entry.getValue());
+                    node2 = rep.getStore().getNode(id);
+                    if (!path.equals("/")) {
+                        path += "/";
+                    }
+                    path += entry.getKey();
+                    // do recurse
+                    diff(path, node1, node2);
                 }
             }
         }
-
     }
 
-    public static interface DiffHandler {
+    public static interface RevisionDiffHandler {
+
+        void propAdded(String nodePath, String propName, String value);
+        void propChanged(String nodePath, String propName, String oldValue, String newValue);
+        void propDeleted(String nodePath, String propName);
 
-        void propAdded(String name, String value);
-        void propChanged(String name, String oldValue, String newValue);
-        void propDeleted(String name);
-
-        void nodeAdded(String name, String id);
-        void nodeChanged(String name, String oldId, String newId);
-        void nodeDeleted(String name);
+        void childNodeAdded(String nodePath, String childName, String id);
+        void childNodeDeleted(String nodePath, String childName, String id);
     }
 }



Mime
View raw message