jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1329741 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/ oak-core/src/main/java/org/apache/jac...
Date Tue, 24 Apr 2012 14:17:11 GMT
Author: angela
Date: Tue Apr 24 14:17:10 2012
New Revision: 1329741

URL: http://svn.apache.org/viewvc?rev=1329741&view=rev
Log:
OAK-16 : Proper ValueFactory implementation and Value handling (WIP)
OAK-33 : Values in oak-core (WIP)

- replacing query/CoreValue and query/CoreValueFactory by oak-api

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/AbstractOakTest.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/PropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Scalar.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/KernelContentRepository.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRoot.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelTree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/ScalarImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelRootFuzzIT.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelRootTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ValueFactoryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/ValueConverter.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/PropertyState.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/PropertyState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/PropertyState.java Tue Apr 24 14:17:10 2012
@@ -46,12 +46,12 @@ public interface PropertyState {
      * @return  the single value of this property or {@code null} if this is a multi
      * valued property.
      */
-    Scalar getScalar();
+    CoreValue getValue();
 
     /**
      * @return  an iterable of the values of this multi valued property or
      * {@code null} if this is not a multi valued property.
      */
-    Iterable<Scalar> getArray();
+    Iterable<CoreValue> getValues();
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Scalar.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Scalar.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Scalar.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Scalar.java Tue Apr 24 14:17:10 2012
@@ -20,6 +20,8 @@ import java.io.InputStream;
 
 /**
  * An immutable, typed scalar value.
+ *
+ * TODO: remove if really not needed any more
  */
 public interface Scalar {
     enum Type {BOOLEAN, LONG, DOUBLE, BINARY, STRING, NULL}

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java Tue Apr 24 14:17:10 2012
@@ -184,7 +184,7 @@ public interface Tree {
      * @param name The name of this property
      * @param value The value of this property
      */
-    void setProperty(String name, Scalar value);
+    void setProperty(String name, CoreValue value);
 
     /**
      * Set a multivalued valued property state
@@ -192,7 +192,7 @@ public interface Tree {
      * @param name The name of this property
      * @param values The value of this property
      */
-    void setProperty(String name, List<Scalar> values);
+    void setProperty(String name, List<CoreValue> values);
 
     /**
      * Remove a property

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/KernelContentRepository.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/KernelContentRepository.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/KernelContentRepository.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/KernelContentRepository.java Tue Apr 24 14:17:10 2012
@@ -52,8 +52,8 @@ public class KernelContentRepository imp
 
     public KernelContentRepository(MicroKernel mk) {
         microKernel = mk;
-        nodeStore = new KernelNodeStore(microKernel);
         valueFactory = new CoreValueFactoryImpl(microKernel);
+        nodeStore = new KernelNodeStore(microKernel, valueFactory);
         queryEngine = new QueryEngineImpl(microKernel, valueFactory);
 
         // FIXME: workspace setup must be done elsewhere...
@@ -95,8 +95,7 @@ public class KernelContentRepository imp
             throw new NoSuchWorkspaceException(workspaceName);
         }
 
-        return new KernelContentSession(
-                sc, workspaceName, nodeStore, queryEngine, valueFactory);
+        return new KernelContentSession(sc, workspaceName, nodeStore, queryEngine, valueFactory);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractPropertyState.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractPropertyState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/AbstractPropertyState.java Tue Apr 24 14:17:10 2012
@@ -18,8 +18,8 @@ package org.apache.jackrabbit.oak.kernel
 
 import java.util.Iterator;
 
+import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Scalar;
 
 /**
  * Abstract base class for {@link PropertyState} implementations.
@@ -54,15 +54,15 @@ public abstract class AbstractPropertySt
         if (isArray() != other.isArray()) {
             return false;
         } else if (isArray()) {
-            Iterator<Scalar> iterator = other.getArray().iterator();
-            for (Scalar scalar : getArray()) {
-                if (!iterator.hasNext() || !scalar.equals(iterator.next())) {
+            Iterator<CoreValue> iterator = other.getValues().iterator();
+            for (CoreValue value : getValues()) {
+                if (!iterator.hasNext() || !value.equals(iterator.next())) {
                     return false;
                 }
             }
             return !iterator.hasNext();
         } else {
-            return getScalar().equals(other.getScalar());
+            return getValue().equals(other.getValue());
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java Tue Apr 24 14:17:10 2012
@@ -21,8 +21,9 @@ package org.apache.jackrabbit.oak.kernel
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.json.JsopReader;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
+import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Scalar;
 
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -42,6 +43,7 @@ class KernelNodeState extends AbstractNo
     static final int MAX_CHILD_NODE_NAMES = 1000;
 
     private final MicroKernel kernel;
+    private final CoreValueFactory valueFactory;
 
     private final String path;
 
@@ -59,11 +61,13 @@ class KernelNodeState extends AbstractNo
      * underlying Microkernel does not contain such a node.
      *
      * @param kernel
+     * @param valueFactory
      * @param path
      * @param revision
      */
-    public KernelNodeState(MicroKernel kernel, String path, String revision) {
+    public KernelNodeState(MicroKernel kernel, CoreValueFactory valueFactory, String path, String revision) {
         this.kernel = kernel;
+        this.valueFactory = valueFactory;
         this.path = path;
         this.revision = revision;
     }
@@ -89,25 +93,12 @@ class KernelNodeState extends AbstractNo
                     if ("/".equals(path)) {
                         childPath = '/' + name;
                     }
-                    childNodes.put(name, new KernelNodeState(
-                            kernel, childPath, revision));
-                } else if (reader.matches(JsopTokenizer.NUMBER)) {
-                    properties.put(name, new KernelPropertyState(
-                            name, ScalarImpl.numberScalar(reader.getToken())));
-                } else if (reader.matches(JsopTokenizer.STRING)) {
-                    properties.put(name, new KernelPropertyState(
-                            name, ScalarImpl.stringScalar(reader.getToken())));
-                } else if (reader.matches(JsopTokenizer.TRUE)) {
-                    properties.put(name, new KernelPropertyState(
-                            name, ScalarImpl.booleanScalar(true)));
-                } else if (reader.matches(JsopTokenizer.FALSE)) {
-                    properties.put(name, new KernelPropertyState(
-                            name, ScalarImpl.booleanScalar(false)));
+                    childNodes.put(name, new KernelNodeState(kernel, valueFactory, childPath, revision));
                 } else if (reader.matches('[')) {
-                    properties.put(name, new KernelPropertyState(
-                            name, readArray(reader)));
+                    properties.put(name, new KernelPropertyState(name, readArray(reader)));
                 } else {
-                    throw new IllegalArgumentException("Unexpected token: " + reader.getToken());
+                    CoreValue cv = readValue(reader);
+                    properties.put(name, new KernelPropertyState(name, cv));
                 }
             } while (reader.matches(','));
             reader.read('}');
@@ -146,7 +137,7 @@ class KernelNodeState extends AbstractNo
         if (child == null && childNodeCount > MAX_CHILD_NODE_NAMES) {
             String childPath = getChildPath(name);
             if (kernel.nodeExists(childPath, revision)) {
-                child = new KernelNodeState(kernel, childPath, revision);
+                child = new KernelNodeState(kernel, valueFactory, childPath, revision);
             }
         }
         return child;
@@ -194,7 +185,7 @@ class KernelNodeState extends AbstractNo
                     reader.read('}');
                     String childPath = getChildPath(name);
                     NodeState child =
-                            new KernelNodeState(kernel, childPath, revision);
+                            new KernelNodeState(kernel, valueFactory, childPath, revision);
                     entries.add(new KernelChildNodeEntry(name, child));
                 } else {
                     reader.read();
@@ -225,23 +216,37 @@ class KernelNodeState extends AbstractNo
         }
     }
 
-    private static List<Scalar> readArray(JsopReader reader) {
-        List<Scalar> values = new ArrayList<Scalar>();
+    private List<CoreValue> readArray(JsopReader reader) {
+        List<CoreValue> values = new ArrayList<CoreValue>();
         while (!reader.matches(']')) {
-            if (reader.matches(JsopTokenizer.NUMBER)) {
-                values.add(ScalarImpl.numberScalar(reader.getToken()));
-            } else if (reader.matches(JsopTokenizer.STRING)) {
-                values.add(ScalarImpl.stringScalar(reader.getToken()));
-            } else if (reader.matches(JsopTokenizer.TRUE)) {
-                values.add(ScalarImpl.booleanScalar(true));
-            } else if (reader.matches(JsopTokenizer.FALSE)) {
-                values.add(ScalarImpl.booleanScalar(false));
-            } else {
-                throw new IllegalArgumentException("Unexpected token: " + reader.getToken());
-            }
+            values.add(readValue(reader));
             reader.matches(',');
         }
         return values;
     }
 
+    private CoreValue readValue(JsopReader reader) {
+        CoreValue value;
+        // TODO properly handle property types not covered by JSON: Binary, double, decimal, date, name, path, (weak)ref, uri
+        if (reader.matches(JsopTokenizer.NUMBER)) {
+            String number = reader.getToken();
+            // TODO: property deal with different number types (double, BigDecimal)
+            if (number.indexOf('.') > -1) {
+                value = valueFactory.createValue(Double.valueOf(number));
+            } else {
+                value = valueFactory.createValue(Long.valueOf(number));
+            }
+        } else if (reader.matches(JsopTokenizer.TRUE)) {
+            value = valueFactory.createValue(true);
+        } else if (reader.matches(JsopTokenizer.FALSE)) {
+            value = valueFactory.createValue(false);
+        } else if (reader.matches(JsopTokenizer.STRING)) {
+            // TODO: deal with other property types
+            value = valueFactory.createValue(reader.getToken());
+        }  else {
+            throw new IllegalArgumentException("Unexpected token: " + reader.getToken());
+        }
+        return value;
+    }
+
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java Tue Apr 24 14:17:10 2012
@@ -19,21 +19,24 @@
 package org.apache.jackrabbit.oak.kernel;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.oak.api.CoreValueFactory;
 
 /**
  * {@link MicroKernel}-based {@link NodeStore} implementation.
  */
 public class KernelNodeStore implements NodeStore {
 
-    final MicroKernel kernel;  // FIXME make private
+    final MicroKernel kernel;
+    final CoreValueFactory valueFactory;
 
-    public KernelNodeStore(MicroKernel kernel) {
+    public KernelNodeStore(MicroKernel kernel, CoreValueFactory valueFactory) {
         this.kernel = kernel;
+        this.valueFactory = valueFactory;
     }
 
     @Override
     public NodeState getRoot() {
-        return new KernelNodeState(kernel, "/", kernel.getHeadRevision());
+        return new KernelNodeState(kernel, valueFactory, "/", kernel.getHeadRevision());
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelPropertyState.java Tue Apr 24 14:17:10 2012
@@ -21,20 +21,20 @@ package org.apache.jackrabbit.oak.kernel
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.jackrabbit.oak.api.Scalar;
+import org.apache.jackrabbit.oak.api.CoreValue;
 
 class KernelPropertyState extends AbstractPropertyState {
     private final String name;
-    private final Scalar value;
-    private final List<Scalar> values;
+    private final CoreValue value;
+    private final List<CoreValue> values;
 
-    public KernelPropertyState(String name, Scalar value) {
+    public KernelPropertyState(String name, CoreValue value) {
         this.name = name;
         this.value = value;
         this.values = null;
     }
 
-    public KernelPropertyState(String name, List<Scalar> values) {
+    public KernelPropertyState(String name, List<CoreValue> values) {
         this.name = name;
         this.value = null;
         this.values = Collections.unmodifiableList(values);
@@ -51,12 +51,12 @@ class KernelPropertyState extends Abstra
     }
     
     @Override
-    public Scalar getScalar() {
+    public CoreValue getValue() {
         return value;
     }
 
     @Override
-    public Iterable<Scalar> getArray() {
+    public Iterable<CoreValue> getValues() {
         return values;
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRoot.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRoot.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRoot.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRoot.java Tue Apr 24 14:17:10 2012
@@ -21,12 +21,13 @@ package org.apache.jackrabbit.oak.kernel
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.mk.json.JsonBuilder;
+import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.api.Scalar;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.kernel.KernelTree.Listener;
 
+import javax.jcr.PropertyType;
 import java.util.List;
 
 import static org.apache.jackrabbit.mk.util.PathUtils.elements;
@@ -156,23 +157,24 @@ public class KernelRoot implements Root 
         return path.isEmpty() ? name : path + '/' + name;
     }
 
-    private static String encode(Scalar scalar) {
-        switch (scalar.getType()) {
-            case BOOLEAN: return JsonBuilder.encode(scalar.getBoolean());
-            case LONG:    return JsonBuilder.encode(scalar.getLong());
-            case DOUBLE:  return JsonBuilder.encode(scalar.getDouble());
-            case BINARY:  return null; // TODO implement encoding of binaries
-            case STRING:  return JsonBuilder.encode(scalar.getString());
-            case NULL:    return "null";
+    private static String encode(CoreValue value) {
+        switch (value.getType()) {
+            // TODO: deal with all property types.
+            case PropertyType.BOOLEAN: return JsonBuilder.encode(value.getBoolean());
+            case PropertyType.LONG:    return JsonBuilder.encode(value.getLong());
+            case PropertyType.DOUBLE:  return JsonBuilder.encode(value.getDouble());
+            case PropertyType.BINARY:  return null; // TODO implement encoding of binaries
+            case PropertyType.STRING:  return JsonBuilder.encode(value.getString());
+            default: return JsonBuilder.encode(value.getString());
+            //case NULL:    return "null"; // TODO
         }
-        throw new IllegalStateException("unreachable");  // Make javac happy
     }
 
-    private static String encode(Iterable<Scalar> scalars) {
+    private static String encode(Iterable<CoreValue> values) {
         StringBuilder sb = new StringBuilder();
         sb.append('[');
-        for (Scalar scalar : scalars) {
-            sb.append(encode(scalar));
+        for (CoreValue cv : values) {
+            sb.append(encode(cv));
             sb.append(',');
         }
         if (sb.length() > 1) {
@@ -200,12 +202,12 @@ public class KernelRoot implements Root 
         }
 
         @Override
-        public void setProperty(KernelTree tree, String name, Scalar value) {
+        public void setProperty(KernelTree tree, String name, CoreValue value) {
             jsop.append("^\"").append(path(tree, name)).append("\":").append(encode(value));
         }
 
         @Override
-        public void setProperty(KernelTree tree, String name, List<Scalar> values) {
+        public void setProperty(KernelTree tree, String name, List<CoreValue> values) {
             jsop.append("^\"").append(path(tree, name)).append("\":").append(encode(values));
         }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelTree.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelTree.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelTree.java Tue Apr 24 14:17:10 2012
@@ -18,9 +18,9 @@
  */
 package org.apache.jackrabbit.oak.kernel;
 
+import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Scalar;
 import org.apache.jackrabbit.oak.util.Function1;
 import org.apache.jackrabbit.oak.util.Iterators;
 import org.apache.jackrabbit.oak.util.PagedIterator;
@@ -100,7 +100,7 @@ public class KernelTree implements Tree 
          * @param name  name of the property
          * @param value  value of the property
          */
-        void setProperty(KernelTree tree, String name, Scalar value);
+        void setProperty(KernelTree tree, String name, CoreValue value);
 
         /**
          * The property of the given {@code name} and {@code values} has been set.
@@ -108,7 +108,7 @@ public class KernelTree implements Tree 
          * @param name  name of the property
          * @param values  values of the property
          */
-        void setProperty(KernelTree tree, String name, List<Scalar> values);
+        void setProperty(KernelTree tree, String name, List<CoreValue> values);
 
         /**
          * The property of the given {@code name} has been removed.
@@ -441,7 +441,7 @@ public class KernelTree implements Tree 
     }
 
     @Override
-    public void setProperty(String name, Scalar value) {
+    public void setProperty(String name, CoreValue value) {
         PropertyState propertyState = new KernelPropertyState(name, value);
         setProperty(propertyState);
         if (listener != null) {
@@ -450,7 +450,7 @@ public class KernelTree implements Tree 
     }
 
     @Override
-    public void setProperty(String name, List<Scalar> values) {
+    public void setProperty(String name, List<CoreValue> values) {
         PropertyState propertyState = new KernelPropertyState(name, values);
         setProperty(propertyState);
         if (listener != null) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/ScalarImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/ScalarImpl.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/ScalarImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/ScalarImpl.java Tue Apr 24 14:17:10 2012
@@ -23,6 +23,9 @@ import java.util.concurrent.Callable;
 
 import org.apache.jackrabbit.oak.api.Scalar;
 
+/**
+ * TODO: remove if really not needed any more
+ */
 public abstract class ScalarImpl implements Scalar {
 
     private static final NullScalar NULL_SCALAR = new NullScalar();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java Tue Apr 24 14:17:10 2012
@@ -20,8 +20,8 @@ import java.util.Collections;
 import java.util.Set;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Scalar;
 import org.apache.jackrabbit.oak.kernel.NodeState;
 import org.apache.jackrabbit.oak.kernel.Validator;
 
@@ -35,14 +35,14 @@ class TypeValidator implements Validator
 
     private void checkTypeExists(PropertyState after)
             throws CommitFailedException {
-        Iterable<Scalar> scalars = Collections.emptyList();
+        Iterable<CoreValue> coreValues = Collections.emptyList();
         if ("jcr:primaryType".equals(after.getName())) {
-            scalars = Collections.singletonList(after.getScalar());
+            coreValues = Collections.singletonList(after.getValue());
         } else if ("jcr:mixinTypes".equals(after.getName())) {
-            scalars = after.getArray();
+            coreValues = after.getValues();
         }
-        for (Scalar scalar : scalars) {
-            String value = scalar.getString();
+        for (CoreValue cv : coreValues) {
+            String value = cv.getString();
             if (!types.contains(value)) {
                 throw new CommitFailedException("Unknown node type: " + value);
             }

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/AbstractOakTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/AbstractOakTest.java?rev=1329741&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/AbstractOakTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/AbstractOakTest.java Tue Apr 24 14:17:10 2012
@@ -0,0 +1,52 @@
+/*
+ * 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.oak.kernel;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.simple.SimpleKernelImpl;
+import org.apache.jackrabbit.oak.api.CoreValueFactory;
+import org.apache.jackrabbit.oak.core.CoreValueFactoryImpl;
+import org.junit.Before;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * AbstractOakTest...
+ */
+public abstract class AbstractOakTest {
+
+    /**
+     * logger instance
+     */
+    private static final Logger log = LoggerFactory.getLogger(AbstractOakTest.class);
+
+    // TODO: use regular oak-repo setup
+    protected MicroKernel microKernel;
+    protected CoreValueFactory valueFactory;
+
+    protected KernelNodeState state;
+
+    @Before
+    public void setUp() {
+        microKernel = new SimpleKernelImpl("mem:" + getClass().getName());
+        valueFactory = new CoreValueFactoryImpl(microKernel);
+
+        state = createInitialState();
+    }
+
+    abstract KernelNodeState createInitialState();
+}
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateTest.java Tue Apr 24 14:17:10 2012
@@ -18,35 +18,29 @@
  */
 package org.apache.jackrabbit.oak.kernel;
 
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertNull;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.junit.Test;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.mk.simple.SimpleKernelImpl;
-import org.apache.jackrabbit.oak.api.PropertyState;
-import org.junit.Before;
-import org.junit.Test;
-
-public class KernelNodeStateTest {
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
 
-    private NodeState state;
+public class KernelNodeStateTest extends AbstractOakTest {
 
-    @Before
-    public void setUp() {
-        MicroKernel kernel = new SimpleKernelImpl("mem:KernelNodeStateTest");
+    @Override
+    KernelNodeState createInitialState() {
         String jsop =
                 "+\"test\":{\"a\":1,\"b\":2,\"c\":3,"
                 + "\"x\":{},\"y\":{},\"z\":{}}";
-        String revision = kernel.commit(
-                "/", jsop, kernel.getHeadRevision(), "test data");
-        state = new KernelNodeState(kernel, "/test", revision);
+        String revision = microKernel.commit(
+                "/", jsop, microKernel.getHeadRevision(), "test data");
+        return new KernelNodeState(microKernel, valueFactory, "/test", revision);
     }
 
     @Test
@@ -57,11 +51,11 @@ public class KernelNodeStateTest {
     @Test
     public void testGetProperty() {
         assertEquals("a", state.getProperty("a").getName());
-        assertEquals(1, state.getProperty("a").getScalar().getLong());
+        assertEquals(1, state.getProperty("a").getValue().getLong());
         assertEquals("b", state.getProperty("b").getName());
-        assertEquals(2, state.getProperty("b").getScalar().getLong());
+        assertEquals(2, state.getProperty("b").getValue().getLong());
         assertEquals("c", state.getProperty("c").getName());
-        assertEquals(3, state.getProperty("c").getScalar().getLong());
+        assertEquals(3, state.getProperty("c").getValue().getLong());
         assertNull(state.getProperty("x"));
     }
 
@@ -71,7 +65,7 @@ public class KernelNodeStateTest {
         List<Long> values = new ArrayList<Long>();
         for (PropertyState property : state.getProperties()) {
             names.add(property.getName());
-            values.add(property.getScalar().getLong());
+            values.add(property.getValue().getLong());
         }
         Collections.sort(names);
         Collections.sort(values);
@@ -128,5 +122,4 @@ public class KernelNodeStateTest {
         // Zero count
         assertFalse(state.getChildNodeEntries(0, 0).iterator().hasNext());
     }
-
 }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelRootFuzzIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelRootFuzzIT.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelRootFuzzIT.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelRootFuzzIT.java Tue Apr 24 14:17:10 2012
@@ -21,9 +21,11 @@ package org.apache.jackrabbit.oak.kernel
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.simple.SimpleKernelImpl;
 import org.apache.jackrabbit.mk.util.PathUtils;
+import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Scalar;
 import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.core.CoreValueFactoryImpl;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -62,6 +64,8 @@ public class KernelRootFuzzIT {
 
     private int counter;
 
+    private CoreValueFactory vf;
+
     @Parameters
     public static List<Object[]> seeds() {
         // todo use random sees, log seed, provide means to start with specific seed
@@ -83,12 +87,13 @@ public class KernelRootFuzzIT {
         counter = 0;
 
         MicroKernel mk1 = new SimpleKernelImpl("mem:");
-        store1 = new KernelNodeStore(mk1);
+        vf = new CoreValueFactoryImpl(mk1);
+        store1 = new KernelNodeStore(mk1, vf);
         mk1.commit("", "+\"/test\":{} +\"/test/root\":{}", mk1.getHeadRevision(), "");
         root1 = new KernelRoot(store1, "test");
 
         MicroKernel mk2 = new SimpleKernelImpl("mem:");
-        store2 = new KernelNodeStore(mk2);
+        store2 = new KernelNodeStore(mk2, vf);
         mk2.commit("", "+\"/test\":{} +\"/test/root\":{}", mk2.getHeadRevision(), "");
         root2 = new KernelRoot(store2, "test");
     }
@@ -221,9 +226,9 @@ public class KernelRootFuzzIT {
         static class SetProperty extends Operation {
             private final String parentPath;
             private String propertyName;
-            private Scalar propertyValue;
+            private CoreValue propertyValue;
 
-            SetProperty(String parentPath, String name, Scalar value) {
+            SetProperty(String parentPath, String name, CoreValue value) {
                 this.parentPath = parentPath;
                 this.propertyName = name;
                 this.propertyValue = value;
@@ -344,7 +349,7 @@ public class KernelRootFuzzIT {
     private Operation createAddProperty() {
         String parent = chooseNodePath();
         String name = createPropertyName();
-        Scalar value = createValue();
+        CoreValue value = createValue();
         return new SetProperty(parent, name, value);
     }
 
@@ -353,7 +358,7 @@ public class KernelRootFuzzIT {
         if (path == null) {
             return null;
         }
-        Scalar value = createValue();
+        CoreValue value = createValue();
         return new SetProperty(PathUtils.getParentPath(path), PathUtils.getName(path), value);
     }
 
@@ -414,8 +419,8 @@ public class KernelRootFuzzIT {
         return null;
     }
 
-    private Scalar createValue() {
-        return ScalarImpl.stringScalar("V" + counter++);
+    private CoreValue createValue() {
+        return vf.createValue("V" + counter++);
     }
 
     private static void checkEqual(Tree tree1, Tree tree2) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelRootTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelRootTest.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelRootTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelRootTest.java Tue Apr 24 14:17:10 2012
@@ -18,15 +18,14 @@
  */
 package org.apache.jackrabbit.oak.kernel;
 
-import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.mk.simple.SimpleKernelImpl;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Scalar;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.junit.Before;
 import org.junit.Test;
 
+import javax.jcr.PropertyType;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -39,17 +38,23 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-public class KernelRootTest {
+public class KernelRootTest extends AbstractOakTest {
 
-    private final MicroKernel microkernel = new SimpleKernelImpl("mem:");
-    private final KernelNodeStore store = new KernelNodeStore(microkernel);
+    private KernelNodeStore store;
 
     @Before
     public void setUp() {
+        super.setUp();
+        store = new KernelNodeStore(microKernel, valueFactory);
+    }
+
+    @Override
+    KernelNodeState createInitialState() {
         String jsop =
                 "+\"test\":{\"a\":1,\"b\":2,\"c\":3,"
                         + "\"x\":{},\"y\":{},\"z\":{}}";
-        microkernel.commit("/", jsop, microkernel.getHeadRevision(), "test data");
+        String revision = microKernel.commit("/", jsop, microKernel.getHeadRevision(), "test data");
+        return new KernelNodeState(microKernel, valueFactory, "/test", revision);
     }
 
     @Test
@@ -75,8 +80,8 @@ public class KernelRootTest {
         propertyState = tree.getProperty("a");
         assertNotNull(propertyState);
         assertFalse(propertyState.isArray());
-        assertEquals(Scalar.Type.LONG, propertyState.getScalar().getType());
-        assertEquals(1, propertyState.getScalar().getLong());
+        assertEquals(PropertyType.LONG, propertyState.getValue().getType());
+        assertEquals(1, propertyState.getValue().getLong());
     }
 
     @Test
@@ -102,17 +107,17 @@ public class KernelRootTest {
         KernelRoot root = new KernelRoot(store, "test");
         Tree tree = root.getTree("/");
 
-        Map<String, Scalar> expectedProperties = new HashMap<String, Scalar>();
-        expectedProperties.put("a", ScalarImpl.longScalar(1));
-        expectedProperties.put("b", ScalarImpl.longScalar(2));
-        expectedProperties.put("c", ScalarImpl.longScalar(3));
+        Map<String, CoreValue> expectedProperties = new HashMap<String, CoreValue>();
+        expectedProperties.put("a", valueFactory.createValue(1));
+        expectedProperties.put("b", valueFactory.createValue(2));
+        expectedProperties.put("c", valueFactory.createValue(3));
 
         Iterable<PropertyState> properties = tree.getProperties();
         for (PropertyState property : properties) {
-            Scalar value = expectedProperties.remove(property.getName());
+            CoreValue value = expectedProperties.remove(property.getName());
             assertNotNull(value);
             assertFalse(property.isArray());
-            assertEquals(value, property.getScalar());
+            assertEquals(value, property.getValue());
         }
 
         assertTrue(expectedProperties.isEmpty());
@@ -175,12 +180,12 @@ public class KernelRootTest {
         Tree tree = root.getTree("/");
 
         assertFalse(tree.hasProperty("new"));
-        Scalar value = ScalarImpl.stringScalar("value");
+        CoreValue value = valueFactory.createValue("value");
         tree.setProperty("new", value);
         PropertyState property = tree.getProperty("new");
         assertNotNull(property);
         assertEquals("new", property.getName());
-        assertEquals(value, property.getScalar());
+        assertEquals(value, property.getValue());
 
         root.commit();
         tree = root.getTree("/");
@@ -188,7 +193,7 @@ public class KernelRootTest {
         property = tree.getProperty("new");
         assertNotNull(property);
         assertEquals("new", property.getName());
-        assertEquals(value, property.getScalar());
+        assertEquals(value, property.getValue());
     }
 
     @Test
@@ -312,7 +317,7 @@ public class KernelRootTest {
 
         assertEquals(3, tree.getPropertyCount());
 
-        Scalar value = ScalarImpl.stringScalar("foo");
+        CoreValue value = valueFactory.createValue("foo");
         tree.setProperty("a", value);
         assertEquals(3, tree.getPropertyCount());
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/LargeKernelNodeStateTest.java Tue Apr 24 14:17:10 2012
@@ -18,34 +18,27 @@
  */
 package org.apache.jackrabbit.oak.kernel;
 
+import org.junit.Test;
+
 import static junit.framework.Assert.assertEquals;
 import static junit.framework.Assert.assertFalse;
 import static junit.framework.Assert.assertNotNull;
 import static junit.framework.Assert.assertNull;
 
-import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.mk.simple.SimpleKernelImpl;
-import org.junit.Before;
-import org.junit.Test;
-
-public class LargeKernelNodeStateTest {
+public class LargeKernelNodeStateTest extends AbstractOakTest {
 
     private final int N = KernelNodeState.MAX_CHILD_NODE_NAMES;
 
-    private NodeState state;
-
-    @Before
-    public void setUp() {
-        MicroKernel kernel =
-                new SimpleKernelImpl("mem:LargeKernelNodeStateTest");
+    @Override
+    KernelNodeState createInitialState() {
         StringBuilder jsop = new StringBuilder("+\"test\":{\"a\":1");
         for (int i = 0; i <= N; i++) {
             jsop.append(",\"x" + i + "\":{}");
         }
-        jsop.append("}");
-        String revision = kernel.commit(
-                "/", jsop.toString(), kernel.getHeadRevision(), "test data");
-        state = new KernelNodeState(kernel, "/test", revision);
+        jsop.append('}');
+        String revision = microKernel.commit(
+                "/", jsop.toString(), microKernel.getHeadRevision(), "test data");
+        return new KernelNodeState(microKernel, valueFactory, "/test", revision);
     }
 
     @Test

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java Tue Apr 24 14:17:10 2012
@@ -20,13 +20,13 @@ import org.apache.jackrabbit.JcrConstant
 import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
 import org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter;
 import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Tree.Status;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.jcr.util.ItemNameMatcher;
 import org.apache.jackrabbit.oak.jcr.util.LogUtil;
 import org.apache.jackrabbit.oak.jcr.util.ValueConverter;
-import org.apache.jackrabbit.oak.kernel.ScalarImpl;
 import org.apache.jackrabbit.oak.namepath.Paths;
 import org.apache.jackrabbit.oak.util.Function1;
 import org.apache.jackrabbit.oak.util.Iterators;
@@ -226,7 +226,7 @@ public class NodeImpl extends ItemImpl i
     public Property setProperty(String name, Value value, int type) throws RepositoryException {
         checkStatus();
 
-        getState().setProperty(name, ValueConverter.toScalar(value));
+        getState().setProperty(name, sessionContext.getValueFactory().getCoreValue(value));
         return getProperty(name);
     }
 
@@ -248,7 +248,7 @@ public class NodeImpl extends ItemImpl i
     public Property setProperty(String name, Value[] values, int type) throws RepositoryException {
         checkStatus();
 
-        getState().setProperty(name, ValueConverter.toScalar(values));
+        getState().setProperty(name, ValueConverter.toCoreValues(values, sessionContext));
         return getProperty(name);
     }
 
@@ -627,7 +627,8 @@ public class NodeImpl extends ItemImpl i
     public void setPrimaryType(String nodeTypeName) throws RepositoryException {
         checkStatus();
 
-        getState().setProperty(JcrConstants.JCR_PRIMARYTYPE, ScalarImpl.stringScalar(nodeTypeName));
+        CoreValue cv = ValueConverter.toCoreValue(nodeTypeName, PropertyType.NAME, sessionContext);
+        getState().setProperty(JcrConstants.JCR_PRIMARYTYPE, cv);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java Tue Apr 24 14:17:10 2012
@@ -340,7 +340,7 @@ public class PropertyImpl extends ItemIm
             throw new ValueFormatException(LogUtil.safeGetJCRPath(this) + " is multi-valued.");
         }
 
-        return ValueConverter.toValue(getValueFactory(), getPropertyState().getScalar());
+        return ValueConverter.toValue(getPropertyState().getValue(), sessionContext);
     }
 
     @Override
@@ -350,7 +350,7 @@ public class PropertyImpl extends ItemIm
             throw new ValueFormatException(LogUtil.safeGetJCRPath(this) + " is not multi-valued.");
         }
 
-        return ValueConverter.toValues(getValueFactory(), getPropertyState().getArray());
+        return ValueConverter.toValues(getPropertyState().getValues(), sessionContext);
     }
 
     /**
@@ -566,7 +566,7 @@ public class PropertyImpl extends ItemIm
             remove();
         }
         else {
-            getParentContentTree().setProperty(name(), ValueConverter.toScalar(value));
+            getParentContentTree().setProperty(name(), ValueConverter.toCoreValue(value, sessionContext));
         }
     }
 
@@ -586,7 +586,7 @@ public class PropertyImpl extends ItemIm
             remove();
         }
         else {
-            getParentContentTree().setProperty(name(), ValueConverter.toScalar(values));
+            getParentContentTree().setProperty(name(), ValueConverter.toCoreValues(values, sessionContext));
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ValueFactoryImpl.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ValueFactoryImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ValueFactoryImpl.java Tue Apr 24 14:17:10 2012
@@ -66,12 +66,25 @@ public class ValueFactoryImpl implements
     }
 
     public CoreValue getCoreValue(Value jcrValue) {
+        ValueImpl v;
         if (jcrValue instanceof ValueImpl) {
-            return ((ValueImpl) jcrValue).unwrap();
+            v = (ValueImpl) jcrValue;
         } else {
-            // TODO
-            throw new UnsupportedOperationException("Unsupported Value implementation.");
+            // TODO add proper implementation
+            try {
+            switch (jcrValue.getType()) {
+                case PropertyType.BINARY:
+                    v = (ValueImpl) createValue(jcrValue.getStream());
+                    break;
+                default:
+                    v = (ValueImpl) createValue(jcrValue.getString(), jcrValue.getType());
+            }
+            } catch (RepositoryException e) {
+                throw new UnsupportedOperationException("Not implemented yet...");
+            }
         }
+
+        return v.unwrap();
     }
 
     //-------------------------------------------------------< ValueFactory >---

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java Tue Apr 24 14:17:10 2012
@@ -22,7 +22,7 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.api.security.user.Query;
 import org.apache.jackrabbit.api.security.user.User;
 import org.apache.jackrabbit.api.security.user.UserManager;
-import org.apache.jackrabbit.oak.api.Scalar;
+import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.jcr.NodeImpl;
 import org.apache.jackrabbit.oak.jcr.SessionContext;
 import org.apache.jackrabbit.oak.jcr.SessionImpl;
@@ -39,7 +39,6 @@ import javax.jcr.UnsupportedRepositoryOp
 import java.io.UnsupportedEncodingException;
 import java.security.NoSuchAlgorithmException;
 import java.security.Principal;
-import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
@@ -328,22 +327,16 @@ public class UserManagerImpl implements 
     }
 
     void setInternalProperty(NodeImpl userNode, String name, String value, int type) throws RepositoryException {
-        // TODO: check again if this really makes a transient modification with marking the property modified/new
-        Scalar scalar = ValueConverter.toScalar(value, type);
-        sessionContext.getContentTree(userNode).setProperty(name, scalar);
+        CoreValue cv = ValueConverter.toCoreValue(value, type, sessionContext);
+        sessionContext.getContentTree(userNode).setProperty(name, cv);
     }
 
     void setInternalProperty(NodeImpl userNode, String name, String[] values, int type) throws RepositoryException {
-        // TODO: check again if this really makes a transient modification with marking the property modified/new
-        List<Scalar> scalarList = new ArrayList<Scalar>(values.length);
-        for (String value : values) {
-            scalarList.add(ValueConverter.toScalar(value, PropertyType.STRING));
-        }
-        sessionContext.getContentTree(userNode).setProperty(name, scalarList);
+        List<CoreValue> cvs = ValueConverter.toCoreValues(values, type, sessionContext);
+        sessionContext.getContentTree(userNode).setProperty(name, cvs);
     }
 
     void removeInternalProperty(NodeImpl userNode, String name) {
-        // TODO: check again if this really makes a transient modification with marking the property modified
         sessionContext.getContentTree(userNode).removeProperty(name);
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/ValueConverter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/ValueConverter.java?rev=1329741&r1=1329740&r2=1329741&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/ValueConverter.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/ValueConverter.java Tue Apr 24 14:17:10 2012
@@ -19,14 +19,13 @@
 
 package org.apache.jackrabbit.oak.jcr.util;
 
-import org.apache.jackrabbit.oak.api.Scalar;
-import org.apache.jackrabbit.oak.kernel.ScalarImpl; // FIXME: Use only the API
+import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.jcr.SessionContext;
+import org.apache.jackrabbit.oak.jcr.SessionImpl;
+import org.apache.jackrabbit.oak.jcr.ValueFactoryImpl;
 
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
-import javax.jcr.ValueFactory;
+import javax.jcr.ValueFormatException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -38,99 +37,42 @@ import java.util.List;
 public final class ValueConverter {
     private ValueConverter() {}
 
-    public static Scalar toScalar(String value, int propertyType) throws RepositoryException {
-        switch (propertyType) {
-            case PropertyType.STRING: {
-                return ScalarImpl.stringScalar(value);
-            }
-            case PropertyType.DOUBLE: {
-                return ScalarImpl.doubleScalar(Double.parseDouble(value));
-            }
-            case PropertyType.LONG: {
-                return ScalarImpl.longScalar(Long.parseLong(value));
-            }
-            case PropertyType.BOOLEAN: {
-                return ScalarImpl.booleanScalar(Boolean.parseBoolean(value));
-            }
-            case PropertyType.BINARY: {
-                return ScalarImpl.binaryScalar(value);
-            }
-            case PropertyType.DECIMAL:
-            case PropertyType.DATE:
-            case PropertyType.NAME:
-            case PropertyType.PATH:
-            case PropertyType.REFERENCE:
-            case PropertyType.WEAKREFERENCE:
-            case PropertyType.URI:
-            default: {
-                // todo implement toScalar
-                throw new UnsupportedRepositoryOperationException("toScalar");
-            }
-        }
+    public static CoreValue toCoreValue(String value, int propertyType, SessionContext<SessionImpl> sessionContext) throws ValueFormatException {
+        return toCoreValue(sessionContext.getValueFactory().createValue(value, propertyType), sessionContext);
     }
 
-    public static Scalar toScalar(Value value) throws RepositoryException {
-        switch (value.getType()) {
-            case PropertyType.STRING: {
-                return ScalarImpl.stringScalar(value.getString());
-            }
-            case PropertyType.DOUBLE: {
-                return ScalarImpl.doubleScalar(value.getDouble());
-            }
-            case PropertyType.LONG: {
-                return ScalarImpl.longScalar(value.getLong());
-            }
-            case PropertyType.BOOLEAN: {
-                return ScalarImpl.booleanScalar(value.getBoolean());
-            }
-            case PropertyType.DECIMAL:
-            case PropertyType.BINARY:
-            case PropertyType.DATE:
-            case PropertyType.NAME:
-            case PropertyType.PATH:
-            case PropertyType.REFERENCE:
-            case PropertyType.WEAKREFERENCE:
-            case PropertyType.URI:
-            default: {
-                throw new UnsupportedRepositoryOperationException("toScalar"); // todo implement toScalar
-            }
+    public static CoreValue toCoreValue(Value value, SessionContext<SessionImpl> sessionContext) {
+        ValueFactoryImpl vf = sessionContext.getValueFactory();
+        return vf.getCoreValue(value);
+    }
+
+    public static List<CoreValue> toCoreValues(String[] values, int propertyType, SessionContext<SessionImpl> sessionContext) throws ValueFormatException {
+        Value[] vs = new Value[values.length];
+        for (int i = 0; i < values.length; i++) {
+            vs[i] = sessionContext.getValueFactory().createValue(values[i], propertyType);
         }
+        return toCoreValues(vs, sessionContext);
     }
-    
-    public static List<Scalar> toScalar(Value[] values) throws RepositoryException {
-        List<Scalar> scalars = new ArrayList<Scalar>();
-        for (Value value : values) {
-            if (value != null) {
-                scalars.add(toScalar(value));
+
+    public static List<CoreValue> toCoreValues(Value[] values, SessionContext<SessionImpl> sessionContext) {
+        List<CoreValue> cvs = new ArrayList<CoreValue>(values.length);
+        for (Value jcrValue : values) {
+            if (jcrValue != null) {
+                cvs.add(toCoreValue(jcrValue, sessionContext));
             }
         }
-        return scalars;
+        return cvs;
     }
 
-    public static Value toValue(ValueFactory valueFactory, Scalar scalar)
-            throws UnsupportedRepositoryOperationException {
-
-        switch (scalar.getType()) {
-            case BOOLEAN:
-                return valueFactory.createValue(scalar.getBoolean());
-            case LONG:
-                return valueFactory.createValue(scalar.getLong());
-            case DOUBLE:
-                return valueFactory.createValue(scalar.getDouble());
-            case STRING:
-                return valueFactory.createValue(scalar.getString());
-            default:
-                throw new UnsupportedRepositoryOperationException("toValue"); // todo implement toValue
-        }
+    public static Value toValue(CoreValue coreValue, SessionContext<SessionImpl> sessionContext) {
+        return sessionContext.getValueFactory().createValue(coreValue);
     }
 
-    public static Value[] toValues(ValueFactory valueFactory, Iterable<Scalar> scalars)
-            throws UnsupportedRepositoryOperationException {
+    public static Value[] toValues(Iterable<CoreValue> coreValues, SessionContext<SessionImpl> sessionContext) {
         List<Value> values = new ArrayList<Value>();
-        for (Scalar scalar : scalars) {
-            values.add(toValue(valueFactory, scalar));
+        for (CoreValue cv : coreValues) {
+            values.add(toValue(cv, sessionContext));
         }
         return values.toArray(new Value[values.size()]);
     }
-
 }



Mime
View raw message