jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1136463 - in /jackrabbit/sandbox/spi2microkernel/src: main/java/org/apache/jackrabbit/spi2microkernel/ main/java/org/apache/jackrabbit/spi2microkernel/util/ main/resources/org/apache/jackrabbit/spi2microkernel/ test/java/org/apache/jackrab...
Date Thu, 16 Jun 2011 14:46:11 GMT
Author: mduerig
Date: Thu Jun 16 14:46:11 2011
New Revision: 1136463

URL: http://svn.apache.org/viewvc?rev=1136463&view=rev
Log:
spi2microkernel prototype (WIP)
write: reference, weak reference

Added:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Arrays.java
Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/ItemInfos.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Values.java
    jackrabbit/sandbox/spi2microkernel/src/main/resources/org/apache/jackrabbit/spi2microkernel/default-nodetypes.cnd
    jackrabbit/sandbox/spi2microkernel/src/test/java/org/apache/jackrabbit/spi2microkernel/RepositoryTest.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1136463&r1=1136462&r2=1136463&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Thu Jun 16 14:46:11 2011
@@ -63,6 +63,8 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import static org.apache.jackrabbit.spi2microkernel.util.Arrays.contains;
+
 public class RepositoryServiceImpl extends AbstractRepositoryService {
     private static final Map<String, QValue[]> DESCRIPTORS = new HashMap<String,
QValue[]>() {{
         QValue[] FALSE = new QValue[]{Values.FALSE};
@@ -454,6 +456,10 @@ public class RepositoryServiceImpl exten
             else {
                 setProperty(nodeId, NameConstants.JCR_MIXINTYPES, Values.create(mixinNodeTypeNames));
             }
+
+            if (contains(mixinNodeTypeNames, NameConstants.MIX_REFERENCEABLE)) {
+                setProperty(nodeId, NameConstants.JCR_UUID, Values.create(nodeId.getPath()));
+            }
         }
 
         public void setPrimaryType(NodeId nodeId, Name primaryNodeTypeName) throws RepositoryException
{

Added: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Arrays.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Arrays.java?rev=1136463&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Arrays.java
(added)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/util/Arrays.java
Thu Jun 16 14:46:11 2011
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.spi2microkernel.util;
+
+public final class Arrays {
+    private Arrays() {}
+
+    public static <T> boolean contains(T[] array, T element) {
+        for (T t : array) {
+            if (element == null && t == null || element != null && element.equals(t))
{
+                return true;
+            }
+        }
+        return false;
+    }
+    
+}

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=1136463&r1=1136462&r2=1136463&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 16 14:46:11 2011
@@ -216,6 +216,9 @@ public final class ItemInfos {
                 else if (Paths.translateQName(NameConstants.JCR_MIXINTYPES).equals(currentKey))
{
                     nodeInfoBuilder.addMixin(Values.create(value).getName());
                 }
+                else if (Paths.translateQName(NameConstants.JCR_UUID).equals(currentKey))
{
+                    nodeInfoBuilder.setUUID(Values.create(value).getString());
+                }
                 else if (currentKey.startsWith(":")) {  // ignore other internal values
                     return !infoListener.done();
                 }

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=1136463&r1=1136462&r2=1136463&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
Thu Jun 16 14:46:11 2011
@@ -21,6 +21,7 @@ package org.apache.jackrabbit.spi2microk
 
 import org.apache.jackrabbit.mk.json.JsonBuilder;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
@@ -167,8 +168,27 @@ public final class Values {
         };
         put(TYPES[PropertyType.BINARY], valueFactory);
 
-        // todo handle reference values
-        // todo handle weak reference values
+        valueFactory = new ValueFactory() {
+            public QValue create(Object value) throws RepositoryException {
+                throw new RepositoryException("Invalid value " + value);
+            }
+
+            public QValue create(String value) throws RepositoryException {
+                return FACTORY.create(value, PropertyType.REFERENCE);
+            }
+        };
+        put(TYPES[PropertyType.REFERENCE], valueFactory);
+
+        valueFactory = new ValueFactory() {
+            public QValue create(Object value) throws RepositoryException {
+                throw new RepositoryException("Invalid value " + value);
+            }
+
+            public QValue create(String value) throws RepositoryException {
+                return FACTORY.create(value, PropertyType.WEAKREFERENCE);
+            }
+        };
+        put(TYPES[PropertyType.WEAKREFERENCE], valueFactory);
     }};
 
     public static QValue create(Object value) throws RepositoryException {
@@ -196,6 +216,10 @@ public final class Values {
         }
     }
 
+    public static String create(Path path) {
+        return typeEncode(PropertyType.PATH, JsonBuilder.escape(path.getString()));
+    }
+
     public static String create(Name name) {
         return typeEncode(PropertyType.NAME, JsonBuilder.escape(name.toString()));
     }
@@ -249,8 +273,10 @@ public final class Values {
             case PropertyType.BINARY:
                 return typeEncode(type, JsonBuilder.escape(value.getString()));  // todo
improve handling of binary values
 
-            case PropertyType.REFERENCE:      // todo handle reference values
-            case PropertyType.WEAKREFERENCE:  // todo handle weak reference values
+            case PropertyType.REFERENCE:
+            case PropertyType.WEAKREFERENCE:
+                return typeEncode(type, JsonBuilder.escape(value.getString()));
+            
             default:
                 throw new RepositoryException("Cannot handle value of type " +
                         PropertyType.nameFromValue(value.getType()));

Modified: jackrabbit/sandbox/spi2microkernel/src/main/resources/org/apache/jackrabbit/spi2microkernel/default-nodetypes.cnd
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/resources/org/apache/jackrabbit/spi2microkernel/default-nodetypes.cnd?rev=1136463&r1=1136462&r2=1136463&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/resources/org/apache/jackrabbit/spi2microkernel/default-nodetypes.cnd
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/resources/org/apache/jackrabbit/spi2microkernel/default-nodetypes.cnd
Thu Jun 16 14:46:11 2011
@@ -39,3 +39,6 @@
 
 [rep:root] > nt:unstructured
 
+[mix:referenceable]
+mixin
+  - jcr:uuid (STRING) mandatory autocreated protected
\ No newline at end of file

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=1136463&r1=1136462&r2=1136463&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 16 14:46:11 2011
@@ -557,6 +557,82 @@ public class RepositoryTest {
         }
     }
 
+    @Test
+    public void addReferenceProperty() throws RepositoryException {
+        Node parentNode = getNode(testPath);
+        Node referee = getSession().getNode("/foo");
+        referee.addMixin("mix:referenceable");
+        getSession().save();
+
+        addProperty(parentNode, "reference", getSession().getValueFactory().createValue(referee));
+    }
+
+    @Test
+    public void addMultiValuedReference() throws RepositoryException {
+        Node parentNode = getNode(testPath);
+        Node referee = getSession().getNode("/foo");
+        referee.addMixin("mix:referenceable");
+        getSession().save();
+
+        Value[] values = new Value[2];
+        values[0] = getSession().getValueFactory().createValue(referee);
+        values[1] = getSession().getValueFactory().createValue(referee);
+
+        parentNode.setProperty("multi reference", values);
+        parentNode.getSession().save();
+
+        Session session2 = getRepository().login();
+        try {
+            Property property = session2.getProperty(testPath + "/multi reference");
+            assertTrue(property.isMultiple());
+            Value[] values2 = property.getValues();
+            assertEquals(values.length, values2.length);
+            assertEquals(values[0], values2[0]);
+            assertEquals(values[1], values2[1]);
+        }
+        finally {
+            session2.logout();
+        }
+    }
+
+    @Test
+    public void addWeakReferenceProperty() throws RepositoryException {
+        Node parentNode = getNode(testPath);
+        Node referee = getSession().getNode("/foo");
+        referee.addMixin("mix:referenceable");
+        getSession().save();
+
+        addProperty(parentNode, "weak reference", getSession().getValueFactory().createValue(referee,
true));
+    }
+
+    @Test
+    public void addMultiValuedWeakReference() throws RepositoryException {
+        Node parentNode = getNode(testPath);
+        Node referee = getSession().getNode("/foo");
+        referee.addMixin("mix:referenceable");
+        getSession().save();
+
+        Value[] values = new Value[2];
+        values[0] = getSession().getValueFactory().createValue(referee, true);
+        values[1] = getSession().getValueFactory().createValue(referee, true);
+
+        parentNode.setProperty("multi weak reference", values);
+        parentNode.getSession().save();
+
+        Session session2 = getRepository().login();
+        try {
+            Property property = session2.getProperty(testPath + "/multi weak reference");
+            assertTrue(property.isMultiple());
+            Value[] values2 = property.getValues();
+            assertEquals(values.length, values2.length);
+            assertEquals(values[0], values2[0]);
+            assertEquals(values[1], values2[1]);
+        }
+        finally {
+            session2.logout();
+        }
+    }
+
     @Ignore // todo set element type, but see JCR-2992
     @Test
     public void addEmptyMultiValuedProperty() throws RepositoryException {



Mime
View raw message