jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1299363 - /jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java
Date Sun, 11 Mar 2012 14:28:55 GMT
Author: mduerig
Date: Sun Mar 11 14:28:55 2012
New Revision: 1299363

URL: http://svn.apache.org/viewvc?rev=1299363&view=rev
Log:
Microkernel based prototype of JCR implementation (WIP)
- improve parsing of child node entries 

Modified:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java?rev=1299363&r1=1299362&r2=1299363&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java
Sun Mar 11 14:28:55 2012
@@ -7,7 +7,6 @@ import org.apache.jackrabbit.json.JsonTo
 import org.apache.jackrabbit.json.JsonValue;
 import org.apache.jackrabbit.json.JsonValue.JsonArray;
 import org.apache.jackrabbit.json.JsonValue.JsonAtom;
-import org.apache.jackrabbit.json.JsonValue.JsonObject;
 import org.apache.jackrabbit.json.Token;
 import org.apache.jackrabbit.json.UnescapingJsonTokenizer;
 import org.apache.jackrabbit.mk.api.MicroKernel;
@@ -16,17 +15,12 @@ import org.apache.jackrabbit.oak.model.A
 import org.apache.jackrabbit.oak.model.ChildNodeEntry;
 import org.apache.jackrabbit.oak.model.NodeState;
 import org.apache.jackrabbit.oak.model.PropertyState;
-import org.apache.jackrabbit.spi.commons.iterator.Iterators;
-import org.apache.jackrabbit.spi.commons.iterator.Predicate;
-import org.apache.jackrabbit.spi.commons.iterator.Transformer;
 import org.apache.jackrabbit.utils.Function0;
 
+import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
-
-import static org.apache.jackrabbit.json.FullJsonParser.parseObject;
 
 public class PersistentNodeState extends AbstractNodeState {
     private final MicroKernel microkernel;
@@ -88,33 +82,18 @@ public class PersistentNodeState extends
     @Override
     public Iterable<ChildNodeEntry> getChildNodeEntries(final long offset, final long
length) {
         // fixme: microkernel should also use long for length
-        final String json = microkernel.getNodes(path.toMkPath(), revision, 1, offset, (int)
length, null);
-        return new Iterable<ChildNodeEntry>() {
-            private final JsonObject jsonObject = parseObject(new UnescapingJsonTokenizer(json));
-
-            private final Iterator<Entry<String, JsonValue>> childObjects =
-                Iterators.filterIterator(jsonObject.value().entrySet().iterator(),
-                    new Predicate<Entry<String, JsonValue>>() {
-                        @Override
-                        public boolean evaluate(Entry<String, JsonValue> entry) {
-                            return entry.getValue().isObject();
-                        }
-                    });
-
-            private final Iterator<ChildNodeEntry> childNodeEntry =
-                Iterators.transformIterator(childObjects,
-                    new Transformer<Entry<String, JsonValue>, ChildNodeEntry>()
{
-                        @Override
-                        public ChildNodeEntry transform(Entry<String, JsonValue> entry)
{
-                            return createChildNodeEntry(entry.getKey());
-                        }
-                    });
+        String json = microkernel.getNodes(path.toMkPath(), revision, 1, offset, (int) length,
null);
+        final List<ChildNodeEntry> childNodeEntries = new ArrayList<ChildNodeEntry>();
 
+        new JsonParser(new JsonHandler(){
             @Override
-            public Iterator<ChildNodeEntry> iterator() {
-                return childNodeEntry;
+            public void object(JsonParser parser, Token key, JsonTokenizer tokenizer) {
+                super.object(parser, key, tokenizer);
+                childNodeEntries.add(createChildNodeEntry(key.text()));
             }
-        };
+        }).parseObject(new UnescapingJsonTokenizer(json));
+
+        return childNodeEntries;
     }
 
     //------------------------------------------< private >---
@@ -130,6 +109,11 @@ public class PersistentNodeState extends
             public NodeState getNode() {
                 return new PersistentNodeState(microkernel, revision, path.concat(name));
             }
+
+            @Override
+            public String toString() {
+                return "ChildNodeEntry(" + name + ')';
+            }
         };
     }
 



Mime
View raw message