jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1190709 - in /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel: ./ src/main/java/org/apache/jackrabbit/spi2microkernel/ src/main/java/org/apache/jackrabbit/spi2microkernel/util/ src/test/java/org/apache/jackrabbit/spi2microkernel/
Date Sat, 29 Oct 2011 00:20:23 GMT
Author: mduerig
Date: Sat Oct 29 00:20:23 2011
New Revision: 1190709

URL: http://svn.apache.org/viewvc?rev=1190709&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
Replace SimpleJson

Added:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/WrappedRepositoryException.java
Removed:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/JsonHandlerBase.java
Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/pom.xml
    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/ItemInfos.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/RepositoryServiceImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/pom.xml?rev=1190709&r1=1190708&r2=1190709&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/pom.xml (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/pom.xml Sat Oct 29 00:20:23
2011
@@ -62,11 +62,6 @@
             <version>0.1-SNAPSHOT</version>
         </dependency>
         <dependency>
-            <groupId>com.googlecode.json-simple</groupId>
-            <artifactId>json-simple</artifactId>
-            <version>1.1</version>
-        </dependency>
-        <dependency>
             <groupId>commons-io</groupId>
             <artifactId>commons-io</artifactId>
         </dependency>

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=1190709&r1=1190708&r2=1190709&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
Sat Oct 29 00:20:23 2011
@@ -1,19 +1,21 @@
 package org.apache.jackrabbit.spi2microkernel;
 
-
-import org.apache.jackrabbit.spi.commons.util.Unchecked;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
+import org.apache.jackrabbit.spi2microkernel.json.FullJsonParser;
+import org.apache.jackrabbit.spi2microkernel.json.JsonValue;
+import org.apache.jackrabbit.spi2microkernel.json.JsonValue.JsonAtom;
+import org.apache.jackrabbit.spi2microkernel.json.JsonValue.JsonObject;
+import org.apache.jackrabbit.spi2microkernel.json.JsonValue.Type;
+import org.apache.jackrabbit.spi2microkernel.json.ParseException;
+import org.apache.jackrabbit.spi2microkernel.json.UnescapingJsonTokenizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Map;
+import java.util.HashMap;
 
 public class CommitInfo {
     private static final Logger log = LoggerFactory.getLogger(CommitInfo.class);
     
-    private final JSONObject jsonObject;
+    private final JsonObject object;
 
     public static CommitInfo parse(String json) {
         if (json == null) {
@@ -23,28 +25,20 @@ public class CommitInfo {
         }
 
         try {
-            Object o = new JSONParser().parse(json);
-            if (o instanceof JSONObject) {
-                return new CommitInfo((JSONObject) o);
-            }
-            else {
-                IllegalArgumentException e = new IllegalArgumentException("Not a JSON object:
" + json);
-                log.error(e.getMessage(), e);
-                throw e;
-            }
+            return new CommitInfo(FullJsonParser.parseObject(new UnescapingJsonTokenizer(json)));
         }
-        catch (ParseException pe) {
-            log.error(pe.getMessage(), pe);
-            throw new IllegalArgumentException("Syntax error in JSON: " + json, pe);
+        catch (ParseException e) {
+            log.error(e.getMessage(), e);
+            throw new IllegalArgumentException("Syntax error in JSON: " + json, e);
         }
     }
 
-    private CommitInfo(JSONObject jsonObject) {
-        this.jsonObject = jsonObject;
+    private CommitInfo(JsonObject object) {
+        this.object = object;
     }
 
     public CommitInfo() {
-        jsonObject = new JSONObject();
+        object = new JsonObject(new HashMap<String, JsonValue>());
     }
 
     public String getMessage() {
@@ -80,17 +74,17 @@ public class CommitInfo {
     }
 
     public String getValue(String key) {
-        Object value = jsonObject.get(key);
-        return value == null ? null : value.toString();
+        JsonValue value = object.get(key);
+        return value == null ? null : value.value().toString();
     }
 
     public CommitInfo setValue(String key, String value) {
-        Unchecked.<Map<String, String>>cast(jsonObject).put(key, value);
+        object.put(key, new JsonAtom(value, Type.STRING));
         return this;
     }
 
     public String toJson() {
-        return jsonObject.toJSONString();
+        return JsonValue.toJson(object);
     }
 
     @Override
@@ -100,12 +94,12 @@ public class CommitInfo {
 
     @Override
     public boolean equals(Object that) {
-        return that instanceof CommitInfo && ((CommitInfo) that).jsonObject.equals(jsonObject);
+        return that instanceof CommitInfo && ((CommitInfo) that).object.equals(object);
     }
 
     @Override
     public int hashCode() {
-        return jsonObject.hashCode();
+        return object.hashCode();
     }
 
 }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/ItemInfos.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/ItemInfos.java?rev=1190709&r1=1190708&r2=1190709&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/ItemInfos.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/ItemInfos.java
Sat Oct 29 00:20:23 2011
@@ -21,7 +21,6 @@ package org.apache.jackrabbit.spi2microk
 
 import org.apache.jackrabbit.spi.ChildInfo;
 import org.apache.jackrabbit.spi.ItemInfo;
-import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.NodeInfo;
 import org.apache.jackrabbit.spi.Path;
@@ -32,15 +31,19 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.NodeInfoBuilder;
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.PropertyInfoBuilder;
 import org.apache.jackrabbit.spi.commons.util.Function1;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
+import org.apache.jackrabbit.spi2microkernel.json.JsonHandler;
+import org.apache.jackrabbit.spi2microkernel.json.JsonParser;
+import org.apache.jackrabbit.spi2microkernel.json.JsonTokenizer;
+import org.apache.jackrabbit.spi2microkernel.json.ParseException;
+import org.apache.jackrabbit.spi2microkernel.json.Token;
+import org.apache.jackrabbit.spi2microkernel.json.UnescapingJsonTokenizer;
+import org.apache.jackrabbit.spi2microkernel.util.WrappedRepositoryException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.jcr.PathNotFoundException;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -48,10 +51,8 @@ import java.util.List;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_MIXINTYPES;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_PRIMARYTYPE;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_UUID;
-import static org.apache.jackrabbit.spi.commons.util.Exceptions.setCause;
 import static org.apache.jackrabbit.spi.commons.util.Iterators.iteratorChain;
 import static org.apache.jackrabbit.spi.commons.util.Iterators.singleton;
-import static org.json.simple.parser.ParseException.ERROR_UNEXPECTED_EXCEPTION;
 
 public final class ItemInfos {
     private static final Logger log = LoggerFactory.getLogger(ItemInfos.class);
@@ -59,12 +60,13 @@ public final class ItemInfos {
     private ItemInfos() {}
 
     public static Iterator<? extends ItemInfo> buildItemInfos(Path rootPath, final
Path targetPath,
-            String json, final boolean stopOnTarget, Function1<String, QValue> binaryHandler)
throws RepositoryException {
+            String json, Function1<String, QValue> binaryHandler)
+            throws RepositoryException {
 
         final List<ItemInfo> itemInfos = new ArrayList<ItemInfo>();
         final ItemInfo[] targetInfo = new ItemInfo[1];
 
-        InfoListener infoListener = new InfoListener() {
+        Listener listener = new Listener() {
             @Override
             public void createNodeInfo(NodeInfo nodeInfo) {
                 if (nodeInfo.getChildInfos() != null) {  // null indicates an empty node.
Do not include!
@@ -89,17 +91,17 @@ public final class ItemInfos {
 
             @Override
             public void createChildInfos(NodeId id, Iterator<ChildInfo> childInfos)
{}
-
-            @Override
-            public boolean done() {
-                return stopOnTarget && targetInfo[0] != null;
-            }
         };
 
         try {
-            JSONParser parser = new JSONParser();
-            JsonHandler handler = new JsonHandler(parent(rootPath), rootPath.getName(), infoListener,
binaryHandler);
-            parser.parse(json, handler);
+            NodeInfoBuilder nodeInfoBuilder = ItemInfoBuilder.nodeInfoBuilder(listener)
+                .setParentPath(parent(rootPath))
+                .setName(rootPath.getName());
+
+            JsonHandler objectHandler = new ObjectHandler(nodeInfoBuilder, binaryHandler);
+            new JsonParser(objectHandler).parseObject(new UnescapingJsonTokenizer(json));
+            nodeInfoBuilder.build();
+
             if (targetInfo[0] == null) {
                 throw new PathNotFoundException(targetPath.toString());
             }
@@ -107,157 +109,157 @@ public final class ItemInfos {
             return iteratorChain(singleton(targetInfo[0]), itemInfos.iterator());
         }
         catch (ParseException e) {
-            if (e.getCause() instanceof RepositoryException) {
-                throw (RepositoryException) e.getCause();
-            }
-            else {
-                RepositoryException e0 = new RepositoryException(json + ' ' + e.getMessage(),
e);
-                log.error(e0.getMessage(), e0);
-                throw e0;
-            }
+            RepositoryException e0 = new RepositoryException(json + ' ' + e.getMessage(),
e);
+            log.error(e0.getMessage(), e0);
+            throw e0;
+        }
+        catch (WrappedRepositoryException e) {
+            throw e.wrapped();
         }
     }
 
     //------------------------------------------< private >---
 
-    private interface InfoListener extends Listener {
-        boolean done();
-    }
-
     private static Path parent(Path path) throws RepositoryException {
         return path.denotesRoot() ? null : path.getAncestor(1);
     }
 
-    private static class JsonHandler extends JsonHandlerBase {
-        private final Path parent;
-        private final InfoListener infoListener;
+    private static class ObjectHandler extends JsonHandler {
         private final Function1<String, QValue> binaryHandler;
 
-        private Name name;
-        private String currentKey;
-        private boolean isObjectEmpty;
-        private boolean isArrayEmpty;
         private NodeInfoBuilder nodeInfoBuilder;
         private PropertyInfoBuilder propertyInfoBuilder;
+        private boolean isEmpty;
 
-        public JsonHandler(Path parent, Name name, InfoListener infoListener, Function1<String,
QValue> binaryHandler) {
-            this.infoListener = infoListener;
-            this.parent = parent;
-            this.name = name;
+        public ObjectHandler(NodeInfoBuilder nodeInfoBuilder, Function1<String, QValue>
binaryHandler) {
+            this.nodeInfoBuilder = nodeInfoBuilder;
             this.binaryHandler = binaryHandler;
         }
 
         @Override
-        public boolean startObject() throws ParseException, IOException {
-            if (nodeInfoBuilder == null) {
-                nodeInfoBuilder = ItemInfoBuilder.nodeInfoBuilder(infoListener);
-                nodeInfoBuilder.setParentPath(parent);
-            }
-            else {
-                nodeInfoBuilder = nodeInfoBuilder.createNodeInfo();
-            }
-            if (currentKey != null) {
-                name = Paths.stringToName(currentKey);
-            }
-            nodeInfoBuilder.setName(name);
-
-            isObjectEmpty = true;
-            return !infoListener.done();
-        }
-
-        @Override
-        public boolean endObject() throws ParseException, IOException {
+        public void atom(Token key, Token value) {
+            isEmpty = false;
+            Object val = val(value);
             try {
-                nodeInfoBuilder.includeChildInfos(!isObjectEmpty);
-                nodeInfoBuilder = nodeInfoBuilder.build();
-                isObjectEmpty = false;
-                return !infoListener.done();
+                if (Paths.nameToString(JCR_PRIMARYTYPE).equals(key.text())) {
+                    nodeInfoBuilder.setPrimaryType(Values.objectToValue(val).getName());
+                }
+                else if (Paths.nameToString(JCR_UUID).equals(key.text())) {
+                    nodeInfoBuilder.setUUID(Values.objectToValue(val).getString());
+                }
+                else if (key.text().startsWith(":")) {  // ignore other internal values
+                    return;
+                }
+
+                // Single valued property
+                nodeInfoBuilder.createPropertyInfo()
+                    .setName(Paths.stringToName(key.text()))
+                    .addValue(Values.objectToValue(val, binaryHandler))
+                    .build();
             }
             catch (RepositoryException e) {
-                log.error(e.getMessage(), e);
-                throw setCause(new ParseException(ERROR_UNEXPECTED_EXCEPTION), e);
+                throw new WrappedRepositoryException(e);
             }
         }
-
+        
         @Override
-        public boolean startObjectEntry(String key) throws ParseException, IOException {
-            isObjectEmpty = false;
-            currentKey = key;
-            return !infoListener.done();
-        }
+        public void object(JsonParser parser, Token key, JsonTokenizer tokenizer) {
+            nodeInfoBuilder = nodeInfoBuilder.createNodeInfo();
+            nodeInfoBuilder.setName(Paths.stringToName(key.text()));
 
-        @Override
-        public boolean endObjectEntry() throws ParseException, IOException {
-            currentKey = null;
-            return !infoListener.done();
-        }
+            isEmpty = true;
 
-        @Override
-        public boolean primitive(Object value) throws ParseException, IOException {
-            try {
-                if (Paths.nameToString(JCR_PRIMARYTYPE).equals(currentKey)) {
-                    nodeInfoBuilder.setPrimaryType(Values.objectToValue(value).getName());
-                }
-                else if (Paths.nameToString(JCR_MIXINTYPES).equals(currentKey)) {
-                    nodeInfoBuilder.addMixin(Values.objectToValue(value).getName());
-                }
-                else if (Paths.nameToString(JCR_UUID).equals(currentKey)) {
-                    nodeInfoBuilder.setUUID(Values.objectToValue(value).getString());
-                }
-                else if (currentKey.startsWith(":")) {  // ignore other internal values
-                    return !infoListener.done();
-                }
-
-                if (propertyInfoBuilder == null) {
-                    // Single valued property
-                    nodeInfoBuilder.createPropertyInfo()
-                        .setName(Paths.stringToName(currentKey))
-                        .addValue(Values.objectToValue(value, binaryHandler))
-                        .build();
+            super.object(parser, key, tokenizer);
 
-                    return !infoListener.done();
-                }
-                else {
-                    // Multi valued property
-                    isArrayEmpty = false;
-                    propertyInfoBuilder.addValue(Values.objectToValue(value, binaryHandler));
-                    return true;
-                }
+            try {
+                nodeInfoBuilder.includeChildInfos(!isEmpty);
+                nodeInfoBuilder = nodeInfoBuilder.build();
+                isEmpty = false;
             }
             catch (RepositoryException e) {
-                log.error(e.getMessage(), e);
-                throw setCause(new ParseException(ERROR_UNEXPECTED_EXCEPTION), e);
+                throw new WrappedRepositoryException(e);
             }
         }
 
         @Override
-        public boolean startArray() throws ParseException, IOException {
-            isArrayEmpty = true;
+        public void array(JsonParser parser, Token key, JsonTokenizer tokenizer) {
             propertyInfoBuilder = nodeInfoBuilder.createPropertyInfo()
-                .setName(Paths.stringToName(currentKey))
+                .setName(Paths.stringToName(key.text()))
                 .setMultivalued(true);
-            
-            return true;
-        }
 
-        @Override
-        public boolean endArray() throws ParseException, IOException {
+            ArrayHandler arrayHandler = new ArrayHandler(key.text());
+            new JsonParser(arrayHandler).parseArray(tokenizer);
+
             try {
-                if (isArrayEmpty) {
-                    // xxx workaround for JCR-2992: set to string. This seems to be accepted
by clients. 
+                if (arrayHandler.isEmpty()) {
+                    // xxx workaround for JCR-2992: set to string. This seems to be accepted
by clients.
                     propertyInfoBuilder.setType(PropertyType.STRING);
                 }
                 propertyInfoBuilder.setMultivalued(true);
                 propertyInfoBuilder.build();
                 propertyInfoBuilder = null;
-                return !infoListener.done();
             }
             catch (RepositoryException e) {
-                log.error(e.getMessage(), e);
-                throw setCause(new ParseException(ERROR_UNEXPECTED_EXCEPTION), e);
+                throw new WrappedRepositoryException(e);
             }
         }
 
-    }
+        private class ArrayHandler extends JsonHandler {
+            private final String arrayKey;
+
+            private boolean hasElements;
+
+            public ArrayHandler(String arrayKey) {
+                this.arrayKey = arrayKey;
+            }
 
+            @Override
+            public void atom(Token key, Token value) {
+                try {
+                    hasElements = true;
+                    Object val = val(value);
+                    if (Paths.nameToString(JCR_MIXINTYPES).equals(arrayKey)) {
+                        nodeInfoBuilder.addMixin(Values.objectToValue(val).getName());
+                    }
+                    propertyInfoBuilder.addValue(Values.objectToValue(val, binaryHandler));
+                }
+                catch (RepositoryException e) {
+                    throw new WrappedRepositoryException(e);
+                }
+            }
+
+            public boolean isEmpty() {
+                return !hasElements;
+            }
+        }
+
+        private static Object val(Token value) {  // fixme cleanup: refactor Values.objectToValue
to match
+            Object val;
+            switch (value.type()) {
+                case TRUE:
+                    val = Boolean.TRUE;
+                    break;
+                case FALSE:
+                    val = Boolean.FALSE;
+                    break;
+                case NULL:
+                    val = null;
+                    break;
+                case STRING:
+                    val = value.text();
+                    break;
+                case NUMBER:
+                    try {
+                        val = Long.parseLong(value.text());
+                    }
+                    catch (NumberFormatException e) {
+                        val = Double.parseDouble(value.text());
+                    }
+                    break;
+                default:
+                    val = null;
+            }
+            return val;
+        }
+    }
 }

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=1190709&r1=1190708&r2=1190709&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
Sat Oct 29 00:20:23 2011
@@ -29,8 +29,9 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.nodetype.NodeTypeStorage;
 import org.apache.jackrabbit.spi.commons.nodetype.QDefinitionBuilderFactory;
 import org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefWriter;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
+import org.apache.jackrabbit.spi2microkernel.json.FullJsonParser;
+import org.apache.jackrabbit.spi2microkernel.json.JsonValue.JsonObject;
+import org.apache.jackrabbit.spi2microkernel.json.UnescapingJsonTokenizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -147,24 +148,14 @@ public class NodeTypeStore {
         String ntDefinitionPath = '/' + systemWorkspace + '/' + NT_DEFINITION_NAME;
         if (microKernel.nodeExists(ntDefinitionPath, rev)) {
             String ntDefinitions = microKernel.getNodes(ntDefinitionPath, rev);
-            JSONParser jsonParser = new JSONParser();
-            try {
-                Object parseResult = jsonParser.parse(ntDefinitions);
-                if (parseResult instanceof JSONObject) {
-                    Object value = ((JSONObject) parseResult).get("cnd");
-                    if (value instanceof String) {
-                        String cnd = (String) value;
-                        return new StringReader(cnd);
-                    }
-                }
-            }
-            catch (org.json.simple.parser.ParseException e) {
-                log.error(e.getMessage(), e);
-            }
 
+            JsonObject jsonObject = FullJsonParser.parseObject(new UnescapingJsonTokenizer(ntDefinitions));
+            Object cnd = jsonObject.get("cnd").value();
+            return cnd == null ? null : new StringReader(cnd.toString());
+        }
+        else {
+            return null;
         }
-
-        return null;
     }
 
     private static InputStream getDefaultNodeTypes() throws RepositoryException {

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1190709&r1=1190708&r2=1190709&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Sat Oct 29 00:20:23 2011
@@ -55,8 +55,11 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.util.Function1;
 import org.apache.jackrabbit.spi.commons.util.Iterators;
 import org.apache.jackrabbit.spi.commons.util.Predicate1;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
+import org.apache.jackrabbit.spi2microkernel.json.JsonHandler;
+import org.apache.jackrabbit.spi2microkernel.json.JsonParser;
+import org.apache.jackrabbit.spi2microkernel.json.JsonTokenizer;
+import org.apache.jackrabbit.spi2microkernel.json.Token;
+import org.apache.jackrabbit.spi2microkernel.json.UnescapingJsonTokenizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -279,40 +282,19 @@ public class RepositoryServiceImpl exten
 
         try {
             String json = microKernel.getNodes("/", getRevision(sessionInfo), 0, 0, -1);
-            new JSONParser().parse(json, new JsonHandlerBase() {
-
-                private String key;
 
+            new JsonParser(new JsonHandler(){
                 @Override
-                public boolean startObjectEntry(String key) {
-                    this.key = key;
-                    return true;
+                public void object(JsonParser parser, Token key, JsonTokenizer tokenizer)
{
+                    workspaces.add(key.text());
+                    new JsonParser(JsonHandler.INSTANCE).parseObject(tokenizer);
                 }
-
-                @Override
-                public boolean startObject() {
-                    if (key != null) {
-                        workspaces.add(key);
-                    }
-                    return true;
-                }
-
-                @Override
-                public boolean endObjectEntry() {
-                    key = null;
-                    return true;
-                }
-
-            });
+            }).parseObject(new UnescapingJsonTokenizer(json));
         }
         catch (MicroKernelException e) {
             log.error(e.getMessage(), e);
             throw new RepositoryException(e.getMessage(), e );
         }
-        catch (ParseException e) {
-            log.error(e.getMessage(), e);
-            throw new RepositoryException(e.getMessage(), e );
-        }
 
         return workspaces.toArray(new String[workspaces.size()]);
     }
@@ -358,7 +340,7 @@ public class RepositoryServiceImpl exten
             }
 
             String json = microKernel.getNodes(mkPath, rev);
-            return buildItemInfos(nodePath, itemPath, json, false, readFromDataStore);
+            return buildItemInfos(nodePath, itemPath, json, readFromDataStore);
         }
         catch (MicroKernelException e) {
             log.error(e.getMessage(), e);
@@ -379,7 +361,7 @@ public class RepositoryServiceImpl exten
             }
 
             String json = microKernel.getNodes(mkPath, rev);
-            Iterator<? extends ItemInfo> infos = buildItemInfos(path, path, json, true,
readFromDataStore);
+            Iterator<? extends ItemInfo> infos = buildItemInfos(path, path, json, readFromDataStore);
             NodeInfo info = (NodeInfo) infos.next();
             return info.getChildInfos();
         }

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=1190709&r1=1190708&r2=1190709&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
Sat Oct 29 00:20:23 2011
@@ -36,10 +36,14 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.EventImpl;
 import org.apache.jackrabbit.spi.commons.identifier.IdFactoryImpl;
 import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
+import org.apache.jackrabbit.spi2microkernel.json.FullJsonParser;
+import org.apache.jackrabbit.spi2microkernel.json.JsonValue;
+import org.apache.jackrabbit.spi2microkernel.json.JsonValue.JsonArray;
+import org.apache.jackrabbit.spi2microkernel.json.JsonValue.JsonObject;
+import org.apache.jackrabbit.spi2microkernel.json.JsonValue.Type;
+import org.apache.jackrabbit.spi2microkernel.json.ParseException;
+import org.apache.jackrabbit.spi2microkernel.json.UnescapingJsonTokenizer;
+import org.apache.jackrabbit.spi2microkernel.util.WrappedRepositoryException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -113,28 +117,6 @@ public class SubscriptionImpl implements
 
     //------------------------------------------< private >---
 
-    private static JSONArray jsonArray(Object jsonArray) {
-        if (jsonArray instanceof JSONArray) {
-            return (JSONArray) jsonArray;
-        }
-        else {
-            IllegalArgumentException e = new IllegalArgumentException("Not a JSONArray: "
+ jsonArray);
-            log.error(e.getMessage(), e);
-            throw e;
-        }
-    }
-
-    private static JSONObject jsonObject(Object jsonObject) {
-        if (jsonObject instanceof JSONObject) {
-            return (JSONObject) jsonObject;
-        }
-        else {
-            IllegalArgumentException e = new IllegalArgumentException("Not a JSONObject:
" + jsonObject);
-            log.error(e.getMessage(), e);
-            throw e;
-        }
-    }
-
     private static PropertyId createPropertyId(NodeId parentId, Name name) {
         return IdFactoryImpl.getInstance().createPropertyId(parentId, name);
     }
@@ -267,29 +249,37 @@ public class SubscriptionImpl implements
             String journal = microKernel.getJournal(startRevision, endRevision);
             log.debug("getJournal(" + startRevision + ", " + endRevision + ") returned "
+ journal.length() + " chars");
 
-            List<EventBundle> eventBundles = new ArrayList<EventBundle>();
+            final List<EventBundle> eventBundles = new ArrayList<EventBundle>();
             try {
-                List<?> jsonArray = jsonArray(new JSONParser().parse(journal));
-                log.debug("getJournal() returned array of length " + jsonArray.size());
+                JsonArray jsonArray = FullJsonParser.parseArray(new UnescapingJsonTokenizer(journal));
+                log.debug("getJournal() returned array of length " + jsonArray.value().size());
 
-                Iterator<?> it = jsonArray.iterator();
+                Iterator<JsonValue> it = jsonArray.value().iterator();
                 if (it.hasNext()) {
                     it.next();  // skip base revision
                 }
 
                 while (it.hasNext()) {
-                    JSONObject jsonObject = jsonObject(it.next());
-                    EventBundle eventBundle = createEventBundle(jsonObject);
-                    if (eventBundle != null) {
-                        eventBundles.add(eventBundle);
-                    }
+                    it.next().accept(new JsonValue.Visitor() {
+                        @Override
+                        public void visit(JsonObject object) {
+                            EventBundle eventBundle = createEventBundle(object);
+                            if (eventBundle != null) {
+                                eventBundles.add(eventBundle);
+                            }
+                        }
+                    });
                 }
                 return eventBundles;
+
             }
             catch (ParseException e) {
                 log.error(e.getMessage(), e);
                 throw new RepositoryException(e.getMessage(), e);
             }
+            catch (WrappedRepositoryException e) {
+                throw e.wrapped();
+            }
 
         }
 
@@ -299,7 +289,7 @@ public class SubscriptionImpl implements
 
         //------------------------------------------< private >---
 
-        private EventBundle createEventBundle(JSONObject jsonObject) throws RepositoryException
{
+        private EventBundle createEventBundle(JsonObject jsonObject) {
             String revisionId = getString(jsonObject, "id", false);
             String msg = getString(jsonObject, "msg", true);
             if (msg == null) {
@@ -345,7 +335,7 @@ public class SubscriptionImpl implements
             return new EventBundleImpl(events, isLocal);
         }
 
-        private Collection<Event> getEvents(String changes, EventTemplate eventTemplate)
throws RepositoryException {
+        private Collection<Event> getEvents(String changes, EventTemplate eventTemplate)
{
             Collection<Event> events = new LinkedList<Event>();
             JsopTokenizer jsopTokenizer = new JsopTokenizer(changes);
 
@@ -466,30 +456,36 @@ public class SubscriptionImpl implements
             }
         }
 
-        private void moveNode(JsopTokenizer jsopTokenizer, EventTemplate eventTemplate, Collection<Event>
events)
-                throws RepositoryException {
-
-            Path fromPath = readPath(jsopTokenizer);
-            jsopTokenizer.read(':');
-            Path toPath = readPath(jsopTokenizer);
+        private void moveNode(JsopTokenizer jsopTokenizer, EventTemplate eventTemplate, Collection<Event>
events) {
+            try {
+                Path fromPath = readPath(jsopTokenizer);
+                jsopTokenizer.read(':');
+                Path toPath = readPath(jsopTokenizer);
 
-            EventTemplate moveNodeEvent = eventTemplate.copy();
-            moveNodeEvent.setType(Event.NODE_MOVED);
-            moveNodeEvent.setPath(toPath);
-            moveNodeEvent.setItemId(createNodeId(toPath));
+                EventTemplate moveNodeEvent = eventTemplate.copy();
+                moveNodeEvent.setType(Event.NODE_MOVED);
+                moveNodeEvent.setPath(toPath);
+                moveNodeEvent.setItemId(createNodeId(toPath));
 
-            Map<Name, QValue> info = new HashMap<Name, QValue>();
-            info.put(Paths.stringToName("srcAbsPath"), Values.pathToValue(fromPath));
-            info.put(Paths.stringToName("destAbsPath"), Values.pathToValue(toPath));
-            moveNodeEvent.setInfo(info);
+                Map<Name, QValue> info = new HashMap<Name, QValue>();
+                info.put(Paths.stringToName("srcAbsPath"), Values.pathToValue(fromPath));
+                info.put(Paths.stringToName("destAbsPath"), Values.pathToValue(toPath));
+                moveNodeEvent.setInfo(info);
 
-            events.add(moveNodeEvent.buildEvent());
+                events.add(moveNodeEvent.buildEvent());
+            }
+            catch (RepositoryException e) {
+                throw new WrappedRepositoryException(e);
+            }
         }
 
-        private String getString(JSONObject jsonObject, String key, boolean allowNull) {
-            Object o = jsonObject.get(key);
-            if (o instanceof String || allowNull && o == null) {
-                return (String) o;
+        private String getString(JsonObject jsonObject, String key, boolean allowNull) {
+            JsonValue o = jsonObject.get(key);
+            if (allowNull && o == null) {
+                return null;
+            }
+            else if (!o.type().compound()) {
+                return o.value().toString();
             }
             else {
                 IllegalArgumentException e = new IllegalArgumentException("Not a string:
" + jsonObject);
@@ -498,10 +494,10 @@ public class SubscriptionImpl implements
             }
         }
 
-        private long getLong(JSONObject jsonObject, String key) {
-            Object o = jsonObject.get(key);
-            if (o instanceof Long) {
-                return (Long) o;
+        private long getLong(JsonObject jsonObject, String key) {
+            JsonValue o = jsonObject.get(key);
+            if (o.type() == Type.NUMBER) {
+                return Long.parseLong(o.value().toString());
             }
             else {
                 IllegalArgumentException e = new IllegalArgumentException("Not a long: "
+ jsonObject);

Added: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/WrappedRepositoryException.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/WrappedRepositoryException.java?rev=1190709&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/WrappedRepositoryException.java
(added)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/WrappedRepositoryException.java
Sat Oct 29 00:20:23 2011
@@ -0,0 +1,15 @@
+package org.apache.jackrabbit.spi2microkernel.util;
+
+import javax.jcr.RepositoryException;
+
+public class WrappedRepositoryException extends RuntimeException {
+    private final RepositoryException wrapped;
+
+    public WrappedRepositoryException(RepositoryException e) {
+        wrapped = e;
+    }
+
+    public RepositoryException wrapped() {
+        return wrapped;
+    }
+}

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=1190709&r1=1190708&r2=1190709&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
Sat Oct 29 00:20:23 2011
@@ -24,11 +24,13 @@ import org.apache.jackrabbit.mk.MicroKer
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
+import org.apache.jackrabbit.spi2microkernel.json.FullJsonParser;
+import org.apache.jackrabbit.spi2microkernel.json.JsonValue;
+import org.apache.jackrabbit.spi2microkernel.json.JsonValue.JsonArray;
+import org.apache.jackrabbit.spi2microkernel.json.JsonValue.JsonObject;
+import org.apache.jackrabbit.spi2microkernel.json.JsonValue.Type;
+import org.apache.jackrabbit.spi2microkernel.json.UnescapingJsonTokenizer;
 import org.apache.jackrabbit.spi2microkernel.util.NumberStream;
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
@@ -36,7 +38,9 @@ import org.junit.Test;
 
 import java.io.IOException;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 public class MicrokernelTest {
 
@@ -193,50 +197,50 @@ public class MicrokernelTest {
     }
 
     @Test
-    public void getStringProperty() throws ParseException {
+    public void getStringProperty() {
         MicroKernel mk = getMicroKernel();
         String head = mk.getHeadRevision();
 
         String json = mk.getNodes("/test", head);
-        JSONObject result = (JSONObject) new JSONParser().parse(json);
-        Object stringProp = result.get("stringProp");
-        assertTrue(stringProp instanceof String);
-        assertEquals("stringVal", stringProp);
+        JsonObject result = FullJsonParser.parseObject(new UnescapingJsonTokenizer(json));
+        JsonValue stringProp = result.get("stringProp");
+        assertEquals(Type.STRING, stringProp.type());
+        assertEquals("stringVal", stringProp.value());
     }
 
     @Test
-    public void getIntProperty() throws ParseException {
+    public void getIntProperty() {
         MicroKernel mk = getMicroKernel();
         String head = mk.getHeadRevision();
 
         String json = mk.getNodes("/test", head);
-        JSONObject result = (JSONObject) new JSONParser().parse(json);
-        Object intProp = result.get("intProp");
-        assertTrue(intProp instanceof Long);
-        assertEquals(42L, intProp);
+        JsonObject result = FullJsonParser.parseObject(new UnescapingJsonTokenizer(json));
+        JsonValue intProp = result.get("intProp");
+        assertEquals(Type.NUMBER, intProp.type());
+        assertEquals(42L, Long.parseLong(intProp.value().toString()));
     }
 
     @Test
-    public void getFloatProperty() throws ParseException {
+    public void getFloatProperty() {
         MicroKernel mk = getMicroKernel();
         String head = mk.getHeadRevision();
 
         String json = mk.getNodes("/test", head);
-        JSONObject result = (JSONObject) new JSONParser().parse(json);
-        Object floatProp = result.get("floatProp");
-        assertTrue(floatProp instanceof Double);
-        assertEquals(42.2, floatProp);
+        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);
     }
 
     @Test
-    public void getMultiIntProperty() throws ParseException {
+    public void getMultiIntProperty() {
         MicroKernel mk = getMicroKernel();
         String head = mk.getHeadRevision();
 
         String json = mk.getNodes("/test", head);
-        JSONObject result = (JSONObject) new JSONParser().parse(json);
-        Object multiIntProp = result.get("multiIntProp");
-        assertTrue(multiIntProp instanceof JSONArray);
+        JsonObject result = FullJsonParser.parseObject(new UnescapingJsonTokenizer(json));
+        JsonValue multiIntProp = result.get("multiIntProp");
+        assertEquals(Type.ARRAY, multiIntProp.type());
     }
 
     @Test
@@ -256,7 +260,7 @@ public class MicrokernelTest {
     }
 
     @Test
-    public void journalAddNode() throws ParseException {
+    public void journalAddNode() {
         MicroKernel mk = getMicroKernel();
         String init = mk.getHeadRevision();
 
@@ -266,9 +270,10 @@ public class MicrokernelTest {
 
         String journal = mk.getJournal(head, head);
 
-        JSONArray jsonArray = (JSONArray) new JSONParser().parse(journal);
-        JSONObject jsonObject = (JSONObject) jsonArray.get(0);
-        String changes = (String) jsonObject.get("changes");
+        JsonArray jsonArray = FullJsonParser.parseArray(new UnescapingJsonTokenizer(journal));
+        JsonValue jsonObject = jsonArray.get(0);
+        assertEquals(Type.OBJECT, jsonObject.type());
+        String changes = ((JsonObject) jsonObject).get("changes").value().toString();
 
         JsopTokenizer tokenizer = new JsopTokenizer(changes);
         tokenizer.read('+');
@@ -284,7 +289,7 @@ public class MicrokernelTest {
     }
 
     @Test
-    public void journalSetProperty() throws ParseException {
+    public void journalSetProperty() {
         MicroKernel mk = getMicroKernel();
         String init = mk.getHeadRevision();
 
@@ -298,9 +303,10 @@ public class MicrokernelTest {
 
         String journal = mk.getJournal(head, head);
 
-        JSONArray jsonArray = (JSONArray) new JSONParser().parse(journal);
-        JSONObject jsonObject = (JSONObject) jsonArray.get(0);
-        String changes = (String) jsonObject.get("changes");
+        JsonArray jsonArray = FullJsonParser.parseArray(new UnescapingJsonTokenizer(journal));
+        JsonValue jsonObject = jsonArray.get(0);
+        assertEquals(Type.OBJECT, jsonObject.type());
+        String changes = ((JsonObject) jsonObject).get("changes").value().toString();
 
         JsopTokenizer tokenizer = new JsopTokenizer(changes);
         tokenizer.read('^');
@@ -312,7 +318,7 @@ public class MicrokernelTest {
     }
 
     @Test
-    public void journalSetProperty2() throws ParseException {
+    public void journalSetProperty2() {
         MicroKernel mk = getMicroKernel();
         String init = mk.getHeadRevision();
 
@@ -326,9 +332,10 @@ public class MicrokernelTest {
 
         String journal = mk.getJournal(head, head);
 
-        JSONArray jsonArray = (JSONArray) new JSONParser().parse(journal);
-        JSONObject jsonObject = (JSONObject) jsonArray.get(0);
-        String changes = (String) jsonObject.get("changes");
+        JsonArray jsonArray = FullJsonParser.parseArray(new UnescapingJsonTokenizer(journal));
+        JsonValue jsonObject = jsonArray.get(0);
+        assertEquals(Type.OBJECT, jsonObject.type());
+        String changes = ((JsonObject) jsonObject).get("changes").value().toString();
 
         JsopTokenizer tokenizer = new JsopTokenizer(changes);
         tokenizer.read('^');



Mime
View raw message