jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1210491 - in /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/json/ test/java/org/apache/jackrabbit/spi2microkernel/json/
Date Mon, 05 Dec 2011 15:11:18 GMT
Author: mduerig
Date: Mon Dec  5 15:11:17 2011
New Revision: 1210491

URL: http://svn.apache.org/viewvc?rev=1210491&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
- add support for extension points

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=1210491&r1=1210490&r2=1210491&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
Mon Dec  5 15:11:17 2011
@@ -38,4 +38,11 @@ public class JsopHandler {
     public void metaData(JsonTokenizer value) {
         new JsonParser(JsonHandler.INSTANCE).parseObject(value);
     }
+
+    public void extension(char op, Token path, JsonTokenizer value) {
+        new JsonParser(JsonHandler.INSTANCE).parseObject(value);
+    }
+
+    public void extension(char op, Token[] values) { }
+    public void extension(char op, Token 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=1210491&r1=1210490&r2=1210491&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
Mon Dec  5 15:11:17 2011
@@ -25,14 +25,15 @@ import java.util.ArrayList;
 import java.util.List;
 
 /*
- * DIFFS    ::= DIFF*
- * 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
+ * DIFFS     ::= DIFF*
+ * DIFF      ::= ADD | SET | REMOVE | MOVE | TEST | METADATA | EXTENSION
+ * ADD       ::= + STRING : (OBJECT | ATOM | ARRAY)
+ * SET       ::= ^ STRING : ATOM | ARRAY
+ * REMOVE    ::= - STRING
+ * MOVE      ::= > STRING : (STRING | { STRING : STRING })
+ * TEST      ::= = STRING : ATOM | ARRAY
+ * METADATA  ::= @ OBJECT
+ * EXTENSION ::= OP STRING ":" (OBJECT | ATOM | ARRAY)
  */
 public class JsopParser {
     private final JsopHandler jsopHandler;
@@ -76,7 +77,7 @@ public class JsopParser {
                 parseMetadata(tokenizer);
                 break;
             default:
-                throw new ParseException(token.pos(), "Expected one of +, -, ^, >, = and
@. Found: " + token);
+                parseExtension(text.charAt(0), tokenizer);
         }
     }
 
@@ -155,6 +156,22 @@ public class JsopParser {
         jsopHandler.metaData(tokenizer);
     }
 
+    /* EXTENSION ::= OP STRING ":" (OBJECT | ATOM | ARRAY) */
+    public void parseExtension(char op, JsonTokenizer tokenizer) {
+        Token path = tokenizer.read(Type.STRING);
+        tokenizer.read(Type.COLON);
+        switch (tokenizer.peek().type()) {
+            case BEGIN_OBJECT:
+                jsopHandler.extension(op, path, tokenizer);
+                break;
+            case BEGIN_ARRAY:
+                jsopHandler.extension(op, parseArray(tokenizer));
+                break;
+            default:
+                jsopHandler.extension(op, parseAtom(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=1210491&r1=1210490&r2=1210491&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
Mon Dec  5 15:11:17 2011
@@ -21,7 +21,10 @@ public class JsopParserTest {
             "^ \"foo\" : [12, 34]" +
             "= \"foo\" : \"bar\"" +
             "= \"foo\" : [12, 34]" +
-            "@ {\"key\" : [12, 34]}";
+            "@ {\"key\" : [12, 34]}" +
+            "x \"foo\" : {\"key\" : [12, 34]}" +
+            "x \"foo\" : [12, 34]" +
+            "x \"foo\" : 12";
 
         new JsopParser(new JsopHandler(){
             @Override
@@ -107,6 +110,35 @@ public class JsopParserTest {
                 assertEquals(Type.END_ARRAY, value.read().type());
                 assertEquals(Type.END_OBJECT, value.read().type());
             }
+
+            @Override
+            public void extension(char op, Token path, JsonTokenizer value) {
+                assertEquals('x', op);
+                assertEquals("foo", path.text());
+                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());
+            }
+
+            @Override
+            public void extension(char op, Token[] values) {
+                assertEquals('x', op);
+                assertEquals(2, values.length);
+                assertEquals("12", values[0].text());
+                assertEquals("34", values[1].text());
+            }
+
+            @Override
+            public void extension(char op, Token value) {
+                assertEquals('x', op);
+                assertEquals("12", value.text());
+                            }
         }).parseJsop(new DefaultJsonTokenizer(jsop));
     }
 }



Mime
View raw message