jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1133929 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/util/ test/java/org/apache/jackrabbit/spi2microkernel/
Date Thu, 09 Jun 2011 15:25:56 GMT
Author: mduerig
Date: Thu Jun  9 15:25:56 2011
New Revision: 1133929

URL: http://svn.apache.org/viewvc?rev=1133929&view=rev
Log:
spi2microkernel prototype (WIP)
simplify array handling

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java?rev=1133929&r1=1133928&r2=1133929&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
Thu Jun  9 15:25:56 2011
@@ -35,7 +35,6 @@ import org.json.simple.parser.ParseExcep
 
 import javax.jcr.RepositoryException;
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedList;
 
@@ -127,7 +126,7 @@ public final class ItemInfos {
             return propertyInfos[0];
         }
         catch (ParseException e) {
-            throw new RepositoryException(json + " " + e.getMessage(), e);
+            throw new RepositoryException(json + ' ' + e.getMessage(), e);
         }
     }
 
@@ -147,9 +146,8 @@ public final class ItemInfos {
 
         private String currentKey;
         private boolean isObjectEmpty;
-        private boolean isArray;
         private NodeInfoBuilder nodeInfoBuilder;
-        private ArrayList<Object> values;
+        private PropertyInfoBuilder propertyInfoBuilder;
 
         public JsonHandler(Path parent, InfoListener infoListener) {
             this.infoListener = infoListener;
@@ -200,15 +198,6 @@ public final class ItemInfos {
 
         @Override
         public boolean primitive(Object value) throws ParseException, IOException {
-            if (isArray) {
-                values.add(value);
-                return true;
-            } else {
-                return handleValue(value, null);
-            }
-        }
-
-        private boolean handleValue(Object value, ArrayList<Object> values) throws
ParseException {
             if (":name".equals(currentKey)) {
                 Name name = Paths.translateName((String) value);
                 nodeInfoBuilder.setName(name);
@@ -220,19 +209,18 @@ public final class ItemInfos {
             }
 
             try {
-                PropertyInfoBuilder propertyInfoBuilder = nodeInfoBuilder.createPropertyInfo();
-                Name name = Paths.translateName(currentKey);
-                propertyInfoBuilder.setName(name);
-                if (value != null) {
+                if (propertyInfoBuilder == null) {
+                    nodeInfoBuilder.createPropertyInfo()
+                        .setName(Paths.translateName(currentKey))
+                        .addValue(Values.create(value))
+                        .build();
+
+                    return !infoListener.done();
+                }
+                else {
                     propertyInfoBuilder.addValue(Values.create(value));
-                } else {
-                    propertyInfoBuilder.setMultivalued(true);
-                    for (Object o : values) {
-                        propertyInfoBuilder.addValue(Values.create(o));
-                    }
+                    return true;
                 }
-                propertyInfoBuilder.build();
-                return !infoListener.done();
             }
             catch (RepositoryException e) {
                 throw setCause(new ParseException(ParseException.ERROR_UNEXPECTED_EXCEPTION),
e);
@@ -241,17 +229,23 @@ public final class ItemInfos {
 
         @Override
         public boolean startArray() throws ParseException, IOException {
-            isArray = true;
-            values = new ArrayList<Object>();
+            propertyInfoBuilder = nodeInfoBuilder.createPropertyInfo()
+                .setName(Paths.translateName(currentKey))
+                .setMultivalued(true);
+            
             return true;
         }
 
         @Override
         public boolean endArray() throws ParseException, IOException {
-            boolean result = handleValue(null, values);
-            isArray = false;
-            values = null;
-            return result;
+            try {
+                propertyInfoBuilder.build();
+                propertyInfoBuilder = null;
+                return !infoListener.done();
+            }
+            catch (RepositoryException e) {
+                throw setCause(new ParseException(ParseException.ERROR_UNEXPECTED_EXCEPTION),
e);
+            }
         }
 
     }

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java?rev=1133929&r1=1133928&r2=1133929&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/MicrokernelTest.java
Thu Jun  9 15:25:56 2011
@@ -34,7 +34,7 @@ import static org.junit.Assert.assertTru
 
 public class MicrokernelTest {
 
-    private static final String URL = "fs:target/repository-test/repository;clean";
+    private static final String URL = "fs:target/microkernel-test/repository;clean";
     // private static final String URL = "mem:test";
 
     private MicroKernel microkernel;

Modified: jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java?rev=1133929&r1=1133928&r2=1133929&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Thu Jun  9 15:25:56 2011
@@ -48,7 +48,6 @@ import static org.junit.Assert.*;
 public class RepositoryTest {
 
     private static final String URL = "fs:target/repository-test/repository";
-    // private static final String URL = "mem:";
 
     private final String testNode = "node_" + System.currentTimeMillis();
     private final String testPath = '/' + testNode;
@@ -62,16 +61,16 @@ public class RepositoryTest {
 
         if (!mk.nodeExists("/default", head)) {
             head = mk.commit("/",
-                "+\"default\" : {" +
+                "+default : {" +
                     "\"{}foo\" : {" +
                         "\"{}stringProp\":\"stringVal\"," +
                         "\"{}intProp\":42," +
-                        "\"{}mvProp\":[1,2,3]}, " +
+                        "\"{}mvProp\":[1,2,3]} " +
                     "\"{}bar\" : {}}", head);
         }
 
         if (!mk.nodeExists("/default/{}" + testNode, head)) {
-            mk.commit("/default", "+\"{}" + testNode + "\" : {}", head);
+            mk.commit("/default", "+{}" + testNode + " : {}", head);
         }
 
         mk.dispose();
@@ -286,6 +285,27 @@ public class RepositoryTest {
         }
     }
 
+    @Ignore // todo set element type 
+    @Test
+    public void addEmptyMultiValuedProperty() throws RepositoryException {
+        Node parentNode = getNode(testPath);
+        Value[] values = new Value[0];
+
+        parentNode.setProperty("multi empty", values);
+        parentNode.getSession().save();
+
+        Session session2 = getRepository().login();
+        try {
+            Property property = session2.getProperty(testPath + "/multi empty");
+            assertTrue(property.isMultiple());
+            Value[] values2 = property.getValues();
+            assertEquals(0, values.length);
+        }
+        finally {
+            session2.logout();
+        }
+    }
+
     @Test
     public void setStringProperty() throws RepositoryException {
         Node parentNode = getNode(testPath);



Mime
View raw message