jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1136045 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java
Date Wed, 15 Jun 2011 13:53:47 GMT
Author: mduerig
Date: Wed Jun 15 13:53:47 2011
New Revision: 1136045

URL: http://svn.apache.org/viewvc?rev=1136045&view=rev
Log:
spi2microkernel prototype (WIP)
value types: binary

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.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/Values.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java?rev=1136045&r1=1136044&r2=1136045&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
Wed Jun 15 13:53:47 2011
@@ -155,10 +155,20 @@ public final class Values {
         };
         put(TYPES[PropertyType.PATH], valueFactory);
 
-        // todo handle other value types
-    }};
+        valueFactory = new ValueFactory() {
+            public QValue create(Object value) throws RepositoryException {
+                throw new RepositoryException("Invalid value " + value);
+            }
 
-    private Values() {}
+            public QValue create(String value) throws RepositoryException {
+                return FACTORY.create(value, PropertyType.BINARY);
+            }
+        };
+        put(TYPES[PropertyType.BINARY], valueFactory);
+
+        // todo handle reference values
+        // todo handle weak reference values
+    }};
 
     public static QValue create(Object value) throws RepositoryException {
         // Type encoded value
@@ -210,11 +220,12 @@ public final class Values {
             case PropertyType.NAME:
             case PropertyType.PATH:
                 return typeEncode(type, value.getString());
-
-            // todo implement support for the other value types
+            
             case PropertyType.BINARY:
-            case PropertyType.REFERENCE:
-            case PropertyType.WEAKREFERENCE:
+                return typeEncode(type, value.getString());  // todo improve handling of
binary values
+
+            case PropertyType.REFERENCE:      // todo handle reference values
+            case PropertyType.WEAKREFERENCE:  // todo handle weak reference values
             default:
                 throw new RepositoryException("Cannot handle value of type " +
                         PropertyType.nameFromValue(value.getType()));

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=1136045&r1=1136044&r2=1136045&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
Wed Jun 15 13:53:47 2011
@@ -26,6 +26,7 @@ import org.junit.Ignore;
 import org.junit.Test;
 
 import javax.imageio.spi.ServiceRegistry;
+import javax.jcr.Binary;
 import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.Node;
 import javax.jcr.PathNotFoundException;
@@ -36,6 +37,8 @@ import javax.jcr.RepositoryException;
 import javax.jcr.RepositoryFactory;
 import javax.jcr.Session;
 import javax.jcr.Value;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
 import java.math.BigDecimal;
 import java.util.Calendar;
 import java.util.Collections;
@@ -506,6 +509,44 @@ public class RepositoryTest {
         }
     }
 
+    @Test
+    public void addBinaryProperty() throws RepositoryException {
+        Node parentNode = getNode(testPath);
+        InputStream is = new ByteArrayInputStream("foo".getBytes());
+        Binary bin = getSession().getValueFactory().createBinary(is);
+        addProperty(parentNode, "binary", getSession().getValueFactory().createValue(bin));
+    }
+
+    @Test
+    public void addMultiValuedBinary() throws RepositoryException {
+        Node parentNode = getNode(testPath);
+        Value[] values = new Value[2];
+
+        InputStream is = new ByteArrayInputStream("foo".getBytes());
+        Binary bin = getSession().getValueFactory().createBinary(is);
+        values[0] = getSession().getValueFactory().createValue(bin);
+
+        is = new ByteArrayInputStream("bar".getBytes());
+        bin = getSession().getValueFactory().createBinary(is);
+        values[1] = getSession().getValueFactory().createValue(bin);
+
+        parentNode.setProperty("multi binary", values);
+        parentNode.getSession().save();
+
+        Session session2 = getRepository().login();
+        try {
+            Property property = session2.getProperty(testPath + "/multi binary");
+            assertTrue(property.isMultiple());
+            Value[] values2 = property.getValues();
+            assertEquals(2, values.length);
+            assertEquals(values[0], values2[0]);
+            assertEquals(values[1], values2[1]);
+        }
+        finally {
+            session2.logout();
+        }
+    }
+
     @Ignore // todo set element type
     @Test
     public void addEmptyMultiValuedProperty() throws RepositoryException {



Mime
View raw message