You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by an...@apache.org on 2012/04/25 16:26:05 UTC

svn commit: r1330308 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: NodeImpl.java PropertyImpl.java

Author: angela
Date: Wed Apr 25 14:26:05 2012
New Revision: 1330308

URL: http://svn.apache.org/viewvc?rev=1330308&view=rev
Log:
OAK-16 : Proper ValueFactory implementation and Value handling (WIP)

- Fix JCR methods that set value with target type hint (conversion got lost at some point...)

Modified:
    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

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=1330308&r1=1330307&r2=1330308&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 Wed Apr 25 14:26:05 2012
@@ -226,7 +226,9 @@ public class NodeImpl extends ItemImpl i
     public Property setProperty(String name, Value value, int type) throws RepositoryException {
         checkStatus();
 
-        getState().setProperty(name, sessionContext.getValueFactory().getCoreValue(value));
+        int targetType = getTargetType(value,  type);
+        Value targetValue = ValueHelper.convert(value, targetType, getValueFactory());
+        getState().setProperty(name, ValueConverter.toCoreValue(targetValue, sessionContext));
         return getProperty(name);
     }
 
@@ -248,7 +250,9 @@ public class NodeImpl extends ItemImpl i
     public Property setProperty(String name, Value[] values, int type) throws RepositoryException {
         checkStatus();
 
-        getState().setProperty(name, ValueConverter.toCoreValues(values, sessionContext));
+        int targetType = getTargetType(values, type);
+        Value[] targetValues = ValueHelper.convert(values, targetType, getValueFactory());
+        getState().setProperty(name, ValueConverter.toCoreValues(targetValues, sessionContext));
         return getProperty(name);
     }
 
@@ -917,4 +921,21 @@ public class NodeImpl extends ItemImpl i
             ? null
             : new PropertyImpl(sessionContext, parent, propertyState);
     }
+
+    private int getTargetType(Value value, int type) {
+        if (value == null) {
+            return PropertyType.STRING; // TODO: review again. rather use property definition
+        } else {
+            return value.getType();
+        }
+    }
+
+    private int getTargetType(Value[] values, int type) {
+        if (values == null || values.length == 0) {
+            return PropertyType.STRING; // TODO: review again. rather use property definition
+        } else {
+            // TODO deal with values array containing a null value in the first position
+            return getTargetType(values[0], type);
+        }
+    }
 }
\ No newline at end of file

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=1330308&r1=1330307&r2=1330308&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 Wed Apr 25 14:26:05 2012
@@ -535,6 +535,7 @@ public class PropertyImpl extends ItemIm
      *
      * @param defaultType
      * @return the required type for this property.
+     * @throws javax.jcr.RepositoryException
      */
     private int getRequiredType(int defaultType) throws RepositoryException {
         // check type according to definition of this property
@@ -564,9 +565,9 @@ public class PropertyImpl extends ItemIm
 
         if (value == null) {
             remove();
-        }
-        else {
-            getParentContentTree().setProperty(name(), ValueConverter.toCoreValue(value, sessionContext));
+        } else {
+            Value targetValue = ValueHelper.convert(value, requiredType, getValueFactory());
+            getParentContentTree().setProperty(name(), ValueConverter.toCoreValue(targetValue, sessionContext));
         }
     }
 
@@ -584,9 +585,9 @@ public class PropertyImpl extends ItemIm
 
         if (values == null) {
             remove();
-        }
-        else {
-            getParentContentTree().setProperty(name(), ValueConverter.toCoreValues(values, sessionContext));
+        } else {
+            Value[] targetValues = ValueHelper.convert(values, requiredType, getValueFactory());
+            getParentContentTree().setProperty(name(), ValueConverter.toCoreValues(targetValues, sessionContext));
         }
     }