jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1196002 - in /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/ main/java/org/apache/jackrabbit/spi2microkernel/json/ test/java/org/apache/jackrabbit/spi2microkernel/
Date Tue, 01 Nov 2011 14:16:22 GMT
Author: mduerig
Date: Tue Nov  1 14:16:21 2011
New Revision: 1196002

URL: http://svn.apache.org/viewvc?rev=1196002&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
Minor improvement, cleanup

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitInfo.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/NodeTypeStore.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/DefaultJsonTokenizer.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsonParser.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsonValue.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/LevelOrderJsonParser.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitInfo.java?rev=1196002&r1=1196001&r2=1196002&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitInfo.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/CommitInfo.java
Tue Nov  1 14:16:21 2011
@@ -75,7 +75,7 @@ public class CommitInfo {
 
     public String getValue(String key) {
         JsonValue value = object.get(key);
-        return value == null ? null : value.value().toString();
+        return value == null ? null : value.asAtom().value();
     }
 
     public CommitInfo setValue(String key, String value) {

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/NodeTypeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/NodeTypeStore.java?rev=1196002&r1=1196001&r2=1196002&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/NodeTypeStore.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/NodeTypeStore.java
Tue Nov  1 14:16:21 2011
@@ -30,6 +30,7 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.nodetype.QDefinitionBuilderFactory;
 import org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefWriter;
 import org.apache.jackrabbit.spi2microkernel.json.FullJsonParser;
+import org.apache.jackrabbit.spi2microkernel.json.JsonValue.JsonAtom;
 import org.apache.jackrabbit.spi2microkernel.json.JsonValue.JsonObject;
 import org.apache.jackrabbit.spi2microkernel.json.UnescapingJsonTokenizer;
 import org.slf4j.Logger;
@@ -150,8 +151,8 @@ public class NodeTypeStore {
             String ntDefinitions = microKernel.getNodes(ntDefinitionPath, rev);
 
             JsonObject jsonObject = FullJsonParser.parseObject(new UnescapingJsonTokenizer(ntDefinitions));
-            Object cnd = jsonObject.get("cnd").value();
-            return cnd == null ? null : new StringReader(cnd.toString());
+            JsonAtom cnd = jsonObject.get("cnd").asAtom();
+            return cnd == null ? null : new StringReader(cnd.value());
         }
         else {
             return null;

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java?rev=1196002&r1=1196001&r2=1196002&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
Tue Nov  1 14:16:21 2011
@@ -485,7 +485,7 @@ public class SubscriptionImpl implements
                 return null;
             }
             else if (!o.type().compound()) {
-                return o.value().toString();
+                return o.asAtom().value();
             }
             else {
                 IllegalArgumentException e = new IllegalArgumentException("Not a string:
" + jsonObject);
@@ -497,7 +497,7 @@ public class SubscriptionImpl implements
         private long getLong(JsonObject jsonObject, String key) {
             JsonValue o = jsonObject.get(key);
             if (o.type() == Type.NUMBER) {
-                return Long.parseLong(o.value().toString());
+                return Long.parseLong(o.asAtom().value());
             }
             else {
                 IllegalArgumentException e = new IllegalArgumentException("Not a long: "
+ jsonObject);

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/DefaultJsonTokenizer.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/DefaultJsonTokenizer.java?rev=1196002&r1=1196001&r2=1196002&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/DefaultJsonTokenizer.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/DefaultJsonTokenizer.java
Tue Nov  1 14:16:21 2011
@@ -118,8 +118,7 @@ public class DefaultJsonTokenizer extend
         }
 
         if (found) {
-            String text = json.substring(pos + 1, i);
-            Token token = createToken(Type.STRING, text, pos);
+            Token token = createToken(Type.STRING, json.substring(pos + 1, i), pos);
             pos = i + 1;
             return token;
         }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsonParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsonParser.java?rev=1196002&r1=1196001&r2=1196002&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsonParser.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsonParser.java
Tue Nov  1 14:16:21 2011
@@ -46,7 +46,6 @@ public final class JsonParser {
                 }
             }
         }
-
         tokenizer.read(Type.END_OBJECT);
     }
 
@@ -94,7 +93,6 @@ public final class JsonParser {
                 }
             }
         }
-
         tokenizer.read(Type.END_ARRAY);
     }
 
@@ -113,7 +111,8 @@ public final class JsonParser {
     private boolean tryParseValue(JsonTokenizer tokenizer) {
         if (tokenizer.peek(Type.END_ARRAY)) {
             return false;
-        } else {
+        }
+        else {
             parseValue(null, tokenizer);
             return true;
         }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsonValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsonValue.java?rev=1196002&r1=1196001&r2=1196002&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsonValue.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsonValue.java
Tue Nov  1 14:16:21 2011
@@ -89,10 +89,6 @@ public abstract class JsonValue {
      * Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through
U+001F).
      */
     public static String escape(String string) {
-        if (string == null) {
-            return null;
-        }
-
         StringBuilder sb = new StringBuilder();
         for (int i = 0; i < string.length(); i++) {
             char ch = string.charAt(i);
@@ -130,7 +126,8 @@ public abstract class JsonValue {
                             sb.append('0');
                         }
                         sb.append(ss.toUpperCase());
-                    } else {
+                    }
+                    else {
                         sb.append(ch);
                     }
             }
@@ -192,6 +189,18 @@ public abstract class JsonValue {
     public abstract Type type();
     public abstract void accept(Visitor visitor);
 
+    public JsonAtom asAtom() {
+        throw new UnsupportedOperationException();
+    }
+
+    public JsonArray asArray() {
+        throw new UnsupportedOperationException();
+    }
+
+    public JsonObject asObject() {
+        throw new UnsupportedOperationException();
+    }
+
     public String toJson() {
         return toJson(this);
     }
@@ -210,6 +219,11 @@ public abstract class JsonValue {
         }
 
         @Override
+        public JsonAtom asAtom() {
+            return this;
+        }
+
+        @Override
         public String value() {
             return value;
         }
@@ -280,6 +294,11 @@ public abstract class JsonValue {
         }
 
         @Override
+        public JsonArray asArray() {
+            return this;
+        }
+
+        @Override
         public List<JsonValue> value() {
             return values;
         }
@@ -332,6 +351,11 @@ public abstract class JsonValue {
         }
 
         @Override
+        public JsonObject asObject() {
+            return this;
+        }
+
+        @Override
         public Map<String, JsonValue> value() {
             return values;
         }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/LevelOrderJsonParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/LevelOrderJsonParser.java?rev=1196002&r1=1196001&r2=1196002&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/LevelOrderJsonParser.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/LevelOrderJsonParser.java
Tue Nov  1 14:16:21 2011
@@ -93,12 +93,16 @@ public final class LevelOrderJsonParser 
 
     //------------------------------------------< private >---
 
+    private static class BreakException extends RuntimeException{
+        private static final BreakException BREAK = new BreakException();
+    }
+
     private static int getNextPairPos(JsonTokenizer tokenizer) {
         SkipObjectHandler skipObjectHandler = new SkipObjectHandler(tokenizer.pos());
         try {
             new JsonParser(skipObjectHandler).parseObject(tokenizer);
         }
-        catch (ParseException e) {
+        catch (BreakException e) {
             return skipObjectHandler.newPos;
         }
         return tokenizer.pos();
@@ -119,7 +123,7 @@ public final class LevelOrderJsonParser 
 
         @Override
         public JsonValue get(String key) {
-            throw new IllegalStateException("Cannot get single value");
+            return value().get(key);
         }
 
         @Override
@@ -146,7 +150,7 @@ public final class LevelOrderJsonParser 
         public void atom(Token key, Token value) {
             if (key != null && ":size".equals(key.text()) && Token.Type.NUMBER
== value.type()) {
                 newPos = startPos + Integer.parseInt(value.text());
-                throw new ParseException(-1, null);
+                throw BreakException.BREAK;
             }
         }
     }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java?rev=1196002&r1=1196001&r2=1196002&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
Tue Nov  1 14:16:21 2011
@@ -205,7 +205,7 @@ public class MicrokernelTest {
         JsonObject result = FullJsonParser.parseObject(new UnescapingJsonTokenizer(json));
         JsonValue stringProp = result.get("stringProp");
         assertEquals(Type.STRING, stringProp.type());
-        assertEquals("stringVal", stringProp.value());
+        assertEquals("stringVal", stringProp.asAtom().value());
     }
 
     @Test
@@ -217,7 +217,7 @@ public class MicrokernelTest {
         JsonObject result = FullJsonParser.parseObject(new UnescapingJsonTokenizer(json));
         JsonValue intProp = result.get("intProp");
         assertEquals(Type.NUMBER, intProp.type());
-        assertEquals(42L, Long.parseLong(intProp.value().toString()));
+        assertEquals(42L, Long.parseLong(intProp.asAtom().value()));
     }
 
     @Test
@@ -229,7 +229,7 @@ public class MicrokernelTest {
         JsonObject result = FullJsonParser.parseObject(new UnescapingJsonTokenizer(json));
         JsonValue floatProp = result.get("floatProp");
         assertEquals(Type.NUMBER, floatProp.type());
-        assertEquals(42.2d, Double.parseDouble(floatProp.value().toString()), 0.01);
+        assertEquals(42.2d, Double.parseDouble(floatProp.asAtom().value()), 0.01);
     }
 
     @Test
@@ -271,9 +271,9 @@ public class MicrokernelTest {
         String journal = mk.getJournal(head, head);
 
         JsonArray jsonArray = FullJsonParser.parseArray(new UnescapingJsonTokenizer(journal));
-        JsonValue jsonObject = jsonArray.get(0);
+        JsonObject jsonObject = jsonArray.get(0).asObject();
         assertEquals(Type.OBJECT, jsonObject.type());
-        String changes = ((JsonObject) jsonObject).get("changes").value().toString();
+        String changes = jsonObject.get("changes").asAtom().value();
 
         JsopTokenizer tokenizer = new JsopTokenizer(changes);
         tokenizer.read('+');
@@ -304,9 +304,9 @@ public class MicrokernelTest {
         String journal = mk.getJournal(head, head);
 
         JsonArray jsonArray = FullJsonParser.parseArray(new UnescapingJsonTokenizer(journal));
-        JsonValue jsonObject = jsonArray.get(0);
+        JsonObject jsonObject = jsonArray.get(0).asObject();
         assertEquals(Type.OBJECT, jsonObject.type());
-        String changes = ((JsonObject) jsonObject).get("changes").value().toString();
+        String changes = jsonObject.get("changes").asAtom().value();
 
         JsopTokenizer tokenizer = new JsopTokenizer(changes);
         tokenizer.read('^');
@@ -333,9 +333,9 @@ public class MicrokernelTest {
         String journal = mk.getJournal(head, head);
 
         JsonArray jsonArray = FullJsonParser.parseArray(new UnescapingJsonTokenizer(journal));
-        JsonValue jsonObject = jsonArray.get(0);
+        JsonObject jsonObject = jsonArray.get(0).asObject();
         assertEquals(Type.OBJECT, jsonObject.type());
-        String changes = ((JsonObject) jsonObject).get("changes").value().toString();
+        String changes = jsonObject.get("changes").asAtom().value();
 
         JsopTokenizer tokenizer = new JsopTokenizer(changes);
         tokenizer.read('^');



Mime
View raw message