jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1208439 - in /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/json/ test/java/org/apache/jackrabbit/spi2microkernel/json/
Date Wed, 30 Nov 2011 14:02:01 GMT
Author: mduerig
Date: Wed Nov 30 14:02:00 2011
New Revision: 1208439

URL: http://svn.apache.org/viewvc?rev=1208439&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
- implemented support for @ and = as specified here: http://wiki.apache.org/jackrabbit/Jsop

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsopHandler.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsopParser.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/json/JsopParserTest.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsopHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsopHandler.java?rev=1208439&r1=1208438&r2=1208439&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsopHandler.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsopHandler.java
Wed Nov 30 14:02:00 2011
@@ -32,4 +32,10 @@ public class JsopHandler {
     public void set(Token path, Token[] values) { }
     public void reorder(Token path, Token position, Token target) { }
     public void move(Token path, Token target) { }
+    public void test(Token path, Token value) { }
+    public void test(Token path, Token[] values) { }
+
+    public void metaData(JsonTokenizer value) {
+        new JsonParser(JsonHandler.INSTANCE).parseObject(value);
+    }
 }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsopParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsopParser.java?rev=1208439&r1=1208438&r2=1208439&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsopParser.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/json/JsopParser.java
Wed Nov 30 14:02:00 2011
@@ -26,11 +26,13 @@ import java.util.List;
 
 /*
  * DIFFS    ::= DIFF*
- * DIFF     ::= ADD | SET | REMOVE | MOVE
+ * DIFF     ::= ADD | SET | REMOVE | MOVE | TEST | METADATA
  * ADD      ::= + STRING : (OBJECT | ATOM | ARRAY)
  * SET      ::= ^ STRING : ATOM | ARRAY
  * REMOVE   ::= - STRING
  * MOVE     ::= > STRING : (STRING | { STRING : STRING })
+ * TEST     ::= = STRING : ATOM | ARRAY
+ * METADATA ::= @ OBJECT
  */
 public class JsopParser {
     private final JsopHandler jsopHandler;
@@ -67,6 +69,12 @@ public class JsopParser {
             case '>':
                 parseMove(tokenizer);
                 break;
+            case '=':
+                parseTest(tokenizer);
+                break;
+            case '@':
+                parseMetadata(tokenizer);
+                break;
             default:
                 throw new ParseException(token.pos(), "Expected one of +, -, ^ or >. Found:
" + token);
         }
@@ -107,8 +115,6 @@ public class JsopParser {
             default:
                 jsopHandler.set(path, parseAtom(tokenizer));
         }
-        if (tokenizer.peek(Type.BEGIN_OBJECT)) {
-        }
     }
 
     /* MOVE     ::= > STRING : (STRING | { STRING : STRING }) */
@@ -128,6 +134,27 @@ public class JsopParser {
         }
     }
 
+    /* TEST     ::= = STRING : ATOM | ARRAY */
+    public void parseTest(JsonTokenizer tokenizer) {
+        Token path = tokenizer.read(Type.STRING);
+        tokenizer.read(Type.COLON);
+        Token token = tokenizer.peek();
+        switch (token.type()) {
+            case BEGIN_OBJECT:
+                throw new ParseException(token.pos(), "Expected one of atom or array. Found:
" + token);
+            case BEGIN_ARRAY:
+                jsopHandler.test(path, parseArray(tokenizer));
+                break;
+            default:
+                jsopHandler.test(path, parseAtom(tokenizer));
+        }
+    }
+
+    /* METADATA ::= @ OBJECT */
+    public void parseMetadata(JsonTokenizer tokenizer) {
+        jsopHandler.metaData(tokenizer);
+    }
+
     //------------------------------------------< private >---
 
     private static Token parseAtom(JsonTokenizer tokenizer) {

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/json/JsopParserTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/json/JsopParserTest.java?rev=1208439&r1=1208438&r2=1208439&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/json/JsopParserTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/json/JsopParserTest.java
Wed Nov 30 14:02:00 2011
@@ -18,7 +18,10 @@ public class JsopParserTest {
             "> \"foo\" : \"bar\"" +
             "> \"foo\" : {\"moo\" : \"bar\"}" +
             "+ \"foo\" : [12, 34]" +
-            "^ \"foo\" : [12, 34]";
+            "^ \"foo\" : [12, 34]" +
+            "= \"foo\" : \"bar\"" +
+            "= \"foo\" : [12, 34]" +
+            "@ {\"key\" : [12, 34]}";
 
         new JsopParser(new JsopHandler(){
             @Override
@@ -78,6 +81,32 @@ public class JsopParserTest {
                 assertEquals("foo", path.text());
                 assertEquals("bar", target.text());
             }
+
+            @Override
+            public void test(Token path, Token value) {
+                assertEquals("foo", path.text());
+                assertEquals("bar", value.text());
+            }
+
+            @Override
+            public void test(Token path, Token[] values) {
+                assertEquals(2, values.length);
+                assertEquals("12", values[0].text());
+                assertEquals("34", values[1].text());
+            }
+
+            @Override
+            public void metaData(JsonTokenizer value) {
+                assertEquals(Type.BEGIN_OBJECT, value.read().type());
+                assertEquals("key", value.read().text());
+                assertEquals(Type.COLON, value.read().type());
+                assertEquals(Type.BEGIN_ARRAY, value.read().type());
+                assertEquals("12", value.read().text());
+                assertEquals(Type.COMMA, value.read().type());
+                assertEquals("34", value.read().text());
+                assertEquals(Type.END_ARRAY, value.read().type());
+                assertEquals(Type.END_OBJECT, value.read().type());
+            }
         }).parseJsop(new DefaultJsonTokenizer(jsop));
     }
 }



Mime
View raw message