jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1135641 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/mem/ test/java/org/apache/jackrabbit/mk/json/
Date Tue, 14 Jun 2011 15:20:29 GMT
Author: thomasm
Date: Tue Jun 14 15:20:28 2011
New Revision: 1135641

URL: http://svn.apache.org/viewvc?rev=1135641&view=rev
Log:
Simplify the in-memory implementation (store raw Json)

Removed:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/PropertyType.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Val.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/ValTest.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java?rev=1135641&r1=1135640&r2=1135641&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
Tue Jun 14 15:20:28 2011
@@ -20,6 +20,7 @@ import java.io.InputStream;
 import java.util.HashMap;
 import java.util.TreeMap;
 import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
 
 /**
@@ -110,13 +111,13 @@ public class MemoryKernelImpl implements
             case '^':
                 path = t.readString();
                 t.read(':');
-                Val val;
+                String value;
                 if (t.matches(JsopTokenizer.NULL)) {
-                    val = null;
+                    value = null;
                 } else {
-                    val = NodeImpl.parseValue(t);
+                    value = t.readRawValue().trim();
                 }
-                headRoot = headRoot.cloneAndSetProperty(rootPath + path, val, headRevId);
+                headRoot = headRoot.cloneAndSetProperty(rootPath + path, value, headRevId);
                 break;
             default:
                 throw new AssertionError("token type: " + t.getTokenType());
@@ -125,12 +126,13 @@ public class MemoryKernelImpl implements
     }
 
     public long getChildNodeCount(String path, String revisionId) {
-        // TODO is it required? might as well use getNodes(path) with depth 0
         return getNode(path, revisionId).getChildNodeCount();
     }
 
     public String getChildNodes(String path, long offset, long count, int depth, String revisionId)
{
-        return getNode(path, revisionId).toString(false, depth, (int) offset, (int) count);
+        JsopBuilder json = new JsopBuilder().array();
+        getNode(path, revisionId).appendChildNodes(json, (int) offset, (int) count);
+        return json.endArray().toString();
     }
 
     private NodeImpl getNode(String path, String revisionId) {
@@ -168,7 +170,9 @@ public class MemoryKernelImpl implements
         if (n == null) {
             throw new RuntimeException("path not found: " + path);
         }
-        return n.toString(true, depth, -1, -1);
+        JsopBuilder json = new JsopBuilder();
+        n.append(json, true, depth);
+        return json.toString();
     }
 
     public String getRevisions(long since, int maxEntries) {

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java?rev=1135641&r1=1135640&r2=1135641&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
Tue Jun 14 15:20:28 2011
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.mk.mem;
 
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map.Entry;
@@ -26,7 +25,7 @@ import org.apache.jackrabbit.mk.json.Jso
 public class NodeImpl {
 
     final long revId;
-    HashMap<String, Val> properties;
+    HashMap<String, String> properties;
     LinkedHashMap<String, NodeImpl> childNodes;
 
     NodeImpl(long revId) {
@@ -39,7 +38,7 @@ public class NodeImpl {
         }
         NodeImpl clone = new NodeImpl(revId);
         if (properties != null) {
-            clone.properties = new HashMap<String, Val>(properties);
+            clone.properties = new HashMap<String, String>(properties);
         }
         if (childNodes != null) {
             clone.childNodes = new LinkedHashMap<String, NodeImpl>(childNodes);
@@ -122,7 +121,7 @@ public class NodeImpl {
         return c;
     }
 
-    public NodeImpl cloneAndSetProperty(String path, Val value, long revId) {
+    public NodeImpl cloneAndSetProperty(String path, String value, long revId) {
         int index = path.indexOf('/');
         if (index < 0) {
             NodeImpl clone = clone(revId);
@@ -141,24 +140,34 @@ public class NodeImpl {
     }
 
     public String toString() {
-        return toString(true, 1, -1, -1);
+        JsopBuilder json = new JsopBuilder();
+        append(json, true, 1);
+        return json.toString();
     }
 
-    public String toString(boolean includeProperties, int depth, int childOffset, int childCount)
{
-        JsopBuilder json = new JsopBuilder();
+    public void appendChildNodes(JsopBuilder json, int childOffset, int childCount) {
+        if (childNodes != null) {
+            for (Entry<String, NodeImpl> e : childNodes.entrySet()) {
+                json.value(e.getKey());
+            }
+        }
+    }
+
+    public void append(JsopBuilder json, boolean includeProperties, int depth) {
         if (includeProperties) {
             json.object();
             if (properties != null) {
-                for (Entry<String, Val> e : properties.entrySet()) {
-                    json.key(e.getKey()).encodedValue(e.getValue().toString());
+                for (Entry<String, String> e : properties.entrySet()) {
+                    json.key(e.getKey()).encodedValue(e.getValue());
                 }
             }
         }
         if (childNodes != null) {
             json.key(":childNodeCount").value(childNodes.size());
-            if (depth > 0) {
+            if (depth >= 0) {
                 for (Entry<String, NodeImpl> e : childNodes.entrySet()) {
-                    json.key(e.getKey()).encodedValue(e.getValue().toString(true, depth -
1, -1, -1));
+                    json.key(e.getKey());
+                    e.getValue().append(json, true, depth - 1);
                 }
             }
         } else {
@@ -169,7 +178,6 @@ public class NodeImpl {
         if (includeProperties) {
             json.endObject();
         }
-        return json.toString();
     }
 
     void addChildNode(String name, NodeImpl node) {
@@ -179,7 +187,7 @@ public class NodeImpl {
             throw new RuntimeException("Node already exiss: " + name);
         }
         if (Constants.NODE_NAME_AS_PROPERTY) {
-            node.setProperty(":name", Val.get(name));
+            node.setProperty(":name", JsopBuilder.encode(name));
         }
         childNodes.put(name, node);
     }
@@ -196,9 +204,9 @@ public class NodeImpl {
         }
     }
 
-    void setProperty(String name, Val value) {
+    void setProperty(String name, String value) {
         if (properties == null) {
-            properties = new HashMap<String, Val>();
+            properties = new HashMap<String, String>();
         }
         if (value == null) {
             properties.remove(name);
@@ -219,8 +227,8 @@ public class NodeImpl {
                 if (t.matches('{')) {
                     node.addChildNode(key, parse(t, revId));
                 } else {
-                    Val val = parseValue(t);
-                    node.setProperty(key, val);
+                    String value = t.readRawValue().trim();
+                    node.setProperty(key, value);
                 }
             } while (t.matches(','));
             t.read('}');
@@ -228,47 +236,5 @@ public class NodeImpl {
         return node;
     }
 
-    static Val parseValue(JsopTokenizer t) {
-        if (t.matches('[')) {
-            ArrayList<Val> list = new ArrayList<Val>();
-            if (!t.matches(']')) {
-                do {
-                    list.add(parseValue(t));
-                } while (t.matches(','));
-                t.read(']');
-            }
-            Val[] array = new Val[list.size()];
-            list.toArray(array);
-            return Val.get(array);
-        } else if (t.matches(JsopTokenizer.NUMBER)) {
-            String token = t.getToken();
-            if (token.indexOf('.') >= 0) {
-                if (token.indexOf('e') >= 0) {
-                    return Val.get(Double.parseDouble(token));
-                }
-                return Val.get(PropertyType.DECIMAL, token);
-            }
-            return Val.get(Long.parseLong(token));
-        } else if (t.matches(JsopTokenizer.TRUE)) {
-            return Val.TRUE;
-        } else if (t.matches(JsopTokenizer.FALSE)) {
-            return Val.FALSE;
-        } else if (t.matches(JsopTokenizer.COMMENT)) {
-            String typeName = t.getToken().trim();
-            int type = PropertyType.valueFromName(typeName);
-            return Val.get(type, t.readString());
-        }
-        String s = t.readString();
-        String escaped = t.getEscapedToken();
-        if (!escaped.startsWith("\\/")) {
-            return Val.get(s);
-        }
-        s = escaped.substring(2);
-        if (s.startsWith("NaN")) {
-            return Val.get(Double.NaN);
-        }
-        return Val.get(s);
-
-    }
 
 }



Mime
View raw message