jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r419916 - in /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit: core/ core/nodetype/ core/nodetype/compact/ core/nodetype/xml/ core/value/ core/xml/ value/
Date Fri, 07 Jul 2006 16:13:04 GMT
Author: stefan
Date: Fri Jul  7 09:13:03 2006
New Revision: 419916

URL: http://svn.apache.org/viewvc?rev=419916&view=rev
Log:
- decouple InternalValue from ValueHelper
- some javadoc improvements

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeImpl.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/BufferedStringValue.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/StringValue.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/value/ValueHelper.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java?rev=419916&r1=419915&r2=419916&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
Fri Jul  7 09:13:03 2006
@@ -29,6 +29,7 @@
 import org.apache.jackrabbit.value.DateValue;
 import org.apache.jackrabbit.value.DoubleValue;
 import org.apache.jackrabbit.value.LongValue;
+import org.apache.jackrabbit.value.ValueHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -347,9 +348,10 @@
         InternalValue internalValue;
         if (reqType != PropertyType.NAME) {
             // type conversion required
-            internalValue =
-                    InternalValue.create(InternalValue.create(name).toJCRValue(session.getNamespaceResolver()),
-                            reqType, session.getNamespaceResolver());
+            Value targetValue = ValueHelper.convert(
+                    InternalValue.create(name).toJCRValue(session.getNamespaceResolver()),
+                    reqType);
+            internalValue = InternalValue.create(targetValue, session.getNamespaceResolver());
         } else {
             // no type conversion required
             internalValue = InternalValue.create(name);
@@ -396,9 +398,10 @@
                 if (name != null) {
                     if (reqType != PropertyType.NAME) {
                         // type conversion required
-                        internalValue =
-                                InternalValue.create(InternalValue.create(name).toJCRValue(session.getNamespaceResolver()),
-                                        reqType, session.getNamespaceResolver());
+                        Value targetValue = ValueHelper.convert(
+                                InternalValue.create(name).toJCRValue(session.getNamespaceResolver()),
+                                reqType);
+                        internalValue = InternalValue.create(targetValue, session.getNamespaceResolver());
                     } else {
                         // no type conversion required
                         internalValue = InternalValue.create(name);
@@ -686,7 +689,8 @@
         InternalValue value;
         if (reqType != PropertyType.DATE) {
             // type conversion required
-            value = InternalValue.create(new DateValue(date), reqType, session.getNamespaceResolver());
+            Value targetVal = ValueHelper.convert(new DateValue(date), reqType);
+            value = InternalValue.create(targetVal, session.getNamespaceResolver());
         } else {
             // no type conversion required
             value = InternalValue.create(date);
@@ -717,7 +721,8 @@
         InternalValue value;
         if (reqType != PropertyType.DOUBLE) {
             // type conversion required
-            value = InternalValue.create(new DoubleValue(number), reqType, session.getNamespaceResolver());
+            Value targetVal = ValueHelper.convert(new DoubleValue(number), reqType);
+            value = InternalValue.create(targetVal, session.getNamespaceResolver());
         } else {
             // no type conversion required
             value = InternalValue.create(number);
@@ -754,7 +759,8 @@
         try {
             if (reqType != PropertyType.BINARY) {
                 // type conversion required
-                value = InternalValue.create(new BLOBFileValue(stream), reqType, session.getNamespaceResolver());
+                Value targetVal = ValueHelper.convert(new BLOBFileValue(stream), reqType);
+                value = InternalValue.create(targetVal, session.getNamespaceResolver());
             } else {
                 // no type conversion required
                 value = InternalValue.create(stream);
@@ -795,7 +801,8 @@
         InternalValue internalValue;
         if (reqType != PropertyType.STRING) {
             // type conversion required
-            internalValue = InternalValue.create(string, reqType, session.getNamespaceResolver());
+            Value targetValue = ValueHelper.convert(string, reqType);
+            internalValue = InternalValue.create(targetValue, session.getNamespaceResolver());
         } else {
             // no type conversion required
             internalValue = InternalValue.create(string);
@@ -832,7 +839,8 @@
                 if (string != null) {
                     if (reqType != PropertyType.STRING) {
                         // type conversion required
-                        internalValue = InternalValue.create(string, reqType, session.getNamespaceResolver());
+                        Value targetValue = ValueHelper.convert(string, reqType);
+                        internalValue = InternalValue.create(targetValue, session.getNamespaceResolver());
                     } else {
                         // no type conversion required
                         internalValue = InternalValue.create(string);
@@ -867,7 +875,8 @@
         InternalValue value;
         if (reqType != PropertyType.BOOLEAN) {
             // type conversion required
-            value = InternalValue.create(new BooleanValue(b), reqType, session.getNamespaceResolver());
+            Value targetVal = ValueHelper.convert(new BooleanValue(b), reqType);
+            value = InternalValue.create(targetVal, session.getNamespaceResolver());
         } else {
             // no type conversion required
             value = InternalValue.create(b);
@@ -940,7 +949,8 @@
         InternalValue value;
         if (reqType != PropertyType.LONG) {
             // type conversion required
-            value = InternalValue.create(new LongValue(number), reqType, session.getNamespaceResolver());
+            Value targetVal = ValueHelper.convert(new LongValue(number), reqType);
+            value = InternalValue.create(targetVal, session.getNamespaceResolver());
         } else {
             // no type conversion required
             value = InternalValue.create(number);
@@ -980,7 +990,8 @@
         InternalValue internalValue;
         if (reqType != value.getType()) {
             // type conversion required
-            internalValue = InternalValue.create(value, reqType, session.getNamespaceResolver());
+            Value targetVal = ValueHelper.convert(value, reqType);
+            internalValue = InternalValue.create(targetVal, session.getNamespaceResolver());
         } else {
             // no type conversion required
             internalValue = InternalValue.create(value, session.getNamespaceResolver());
@@ -1035,10 +1046,10 @@
                         // use the value's type as property type
                         reqType = value.getType();
                     }
-                    if (reqType != PropertyType.UNDEFINED
-                            && reqType != value.getType()) {
+                    if (reqType != value.getType()) {
                         // type conversion required
-                        internalValue = InternalValue.create(value, reqType, session.getNamespaceResolver());
+                        Value targetVal = ValueHelper.convert(value, reqType);
+                        internalValue = InternalValue.create(targetVal, session.getNamespaceResolver());
                     } else {
                         // no type conversion required
                         internalValue = InternalValue.create(value, session.getNamespaceResolver());

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeImpl.java?rev=419916&r1=419915&r2=419916&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeImpl.java
Fri Jul  7 09:13:03 2006
@@ -23,6 +23,7 @@
 import org.apache.jackrabbit.name.NoPrefixDeclaredException;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.UnknownPrefixException;
+import org.apache.jackrabbit.value.ValueHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -375,10 +376,17 @@
                 // no type conversion required
                 targetType = value.getType();
             }
-            // create InternalValue from Value and perform
-            // type conversion as necessary
-            InternalValue internalValue = InternalValue.create(value, targetType,
-                    nsResolver);
+            // perform type conversion as necessary and create InternalValue
+            // from (converted) Value
+            InternalValue internalValue;
+            if (targetType != value.getType()) {
+                // type conversion required
+                Value targetVal = ValueHelper.convert(value, targetType);
+                internalValue = InternalValue.create(targetVal, nsResolver);
+            } else {
+                // no type conversion required
+                internalValue = InternalValue.create(value, nsResolver);
+            }
             EffectiveNodeType.checkSetPropertyValueConstraints(
                     def, new InternalValue[]{internalValue});
             return true;
@@ -444,11 +452,17 @@
             // convert values and compact array (purge null entries)
             for (int i = 0; i < values.length; i++) {
                 if (values[i] != null) {
-                    // create InternalValue from Value and perform
-                    // type conversion as necessary
-                    InternalValue internalValue =
-                            InternalValue.create(values[i], targetType,
-                                    nsResolver);
+                    // perform type conversion as necessary and create InternalValue
+                    // from (converted) Value
+                    InternalValue internalValue;
+                    if (targetType != type) {
+                        // type conversion required
+                        Value targetVal = ValueHelper.convert(values[i], targetType);
+                        internalValue = InternalValue.create(targetVal, nsResolver);
+                    } else {
+                        // no type conversion required
+                        internalValue = InternalValue.create(values[i], nsResolver);
+                    }
                     list.add(internalValue);
                 }
             }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java?rev=419916&r1=419915&r2=419916&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/compact/CompactNodeTypeDefReader.java
Fri Jul  7 09:13:03 2006
@@ -30,6 +30,7 @@
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.UnknownPrefixException;
 import org.apache.jackrabbit.util.name.NamespaceMapping;
+import org.apache.jackrabbit.value.ValueHelper;
 
 import javax.jcr.NamespaceException;
 import javax.jcr.PropertyType;
@@ -484,7 +485,7 @@
             nextToken();
             InternalValue value = null;
             try {
-                value = InternalValue.create(currentToken, pdi.getRequiredType(), nsMapping);
+                value = InternalValue.create(ValueHelper.convert(currentToken, pdi.getRequiredType()),
nsMapping);
             } catch (ValueFormatException e) {
                 lexer.fail("'" + currentToken + "' is not a valid string representation of
a value of type " + pdi.getRequiredType());
             } catch (RepositoryException e) {

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java?rev=419916&r1=419915&r2=419916&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/xml/NodeTypeReader.java
Fri Jul  7 09:13:03 2006
@@ -31,6 +31,7 @@
 import org.apache.jackrabbit.name.NamespaceResolver;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.UnknownPrefixException;
+import org.apache.jackrabbit.value.ValueHelper;
 
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
@@ -255,7 +256,7 @@
             while (walker.iterateElements(Constants.DEFAULTVALUE_ELEMENT)) {
                 String value = walker.getContent();
                 try {
-                    values.add(InternalValue.create(value, type, resolver));
+                    values.add(InternalValue.create(ValueHelper.convert(value, type), resolver));
                 } catch (RepositoryException e) {
                     throw new InvalidNodeTypeDefException(
                             "Unable to create default value: " + value, e);

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java?rev=419916&r1=419915&r2=419916&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
Fri Jul  7 09:13:03 2006
@@ -35,7 +35,6 @@
 import org.apache.jackrabbit.value.PathValue;
 import org.apache.jackrabbit.value.ReferenceValue;
 import org.apache.jackrabbit.value.StringValue;
-import org.apache.jackrabbit.value.ValueHelper;
 
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
@@ -144,40 +143,6 @@
 
     /**
      * @param value
-     * @param targetType
-     * @param nsResolver
-     * @return
-     * @throws ValueFormatException
-     * @throws RepositoryException
-     */
-    public static InternalValue create(Value value, int targetType,
-                                       NamespaceResolver nsResolver)
-            throws ValueFormatException, RepositoryException {
-        if (value == null) {
-            throw new IllegalArgumentException("null value");
-        }
-        return create(ValueHelper.convert(value, targetType), nsResolver);
-    }
-
-    /**
-     * @param value
-     * @param targetType
-     * @param nsResolver
-     * @return
-     * @throws ValueFormatException
-     * @throws RepositoryException
-     */
-    public static InternalValue create(String value, int targetType,
-                                       NamespaceResolver nsResolver)
-            throws ValueFormatException, RepositoryException {
-        if (value == null) {
-            throw new IllegalArgumentException("null value");
-        }
-        return create(ValueHelper.convert(value, targetType), nsResolver);
-    }
-
-    /**
-     * @param value
      * @return
      */
     public static InternalValue create(String value) {
@@ -383,47 +348,42 @@
      * @throws RepositoryException
      */
     public InternalValue createCopy() throws RepositoryException {
-        switch (type) {
-            case PropertyType.BINARY:
+        if (type == PropertyType.BINARY) {
+            // return a copy since the wrapped BLOBFileValue instance is mutable
+            try {
+                InputStream stream = ((BLOBFileValue) val).getStream();
                 try {
-                    InputStream stream = ((BLOBFileValue) val).getStream();
+                    return new InternalValue(new BLOBFileValue(stream));
+                } finally {
                     try {
-                        return new InternalValue(new BLOBFileValue(stream));
-                    } finally {
-                        try {
-                            stream.close();
-                        } catch (IOException e) {
-                            // ignore
-                        }
+                        stream.close();
+                    } catch (IOException e) {
+                        // ignore
                     }
-                } catch (IOException ioe) {
-                    throw new RepositoryException("failed to copy binary value", ioe);
                 }
-            case PropertyType.BOOLEAN:
-                return new InternalValue(((Boolean) val).booleanValue());
-            case PropertyType.DATE:
-                return new InternalValue((Calendar) val);
-            case PropertyType.DOUBLE:
-                return new InternalValue(((Double) val).doubleValue());
-            case PropertyType.LONG:
-                return new InternalValue(((Long) val).longValue());
-            case PropertyType.REFERENCE:
-                return new InternalValue((UUID) val);
-            case PropertyType.PATH:
-                return new InternalValue((Path) val);
-            case PropertyType.NAME:
-                return new InternalValue((QName) val);
-            case PropertyType.STRING:
-                return new InternalValue((String) val);
-            default:
-                throw new RepositoryException("illegal internal value type");
+            } catch (IOException ioe) {
+                throw new RepositoryException("failed to copy binary value", ioe);
+            }
+        } else {
+            // for all other types it's safe to return 'this' because the
+            // wrapped value is immutable (and therefore this instance as well)
+            return this;
         }
     }
 
     /**
-     * @param s
+     * Parses the given string as an <code>InternalValue</code> of the
+     * specified type. The string must be in the format returned by the
+     * <code>InternalValue.toString()</code> method.
+     *
+     * @param s a <code>String</code> containing the <code>InternalValue</code>
+     *          representation to be parsed.
      * @param type
-     * @return
+     * @return the <code>InternalValue</code> represented by the arguments
+     * @throws IllegalArgumentException if the specified string can not be parsed
+     *                                  as an <code>InternalValue</code> of the
+     *                                  specified type.
+     * @see #toString()
      */
     public static InternalValue valueOf(String s, int type) {
         switch (type) {
@@ -445,7 +405,8 @@
                 return new InternalValue(s);
 
             case PropertyType.BINARY:
-                throw new IllegalArgumentException("this method does not support the type
PropertyType.BINARY");
+                throw new IllegalArgumentException(
+                        "this method does not support the type PropertyType.BINARY");
             default:
                 throw new IllegalArgumentException("illegal type");
         }

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/BufferedStringValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/BufferedStringValue.java?rev=419916&r1=419915&r2=419916&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/BufferedStringValue.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/BufferedStringValue.java
Fri Jul  7 09:13:03 2006
@@ -238,7 +238,7 @@
                 // convert serialized value to InternalValue using
                 // current namespace context of xml document
                 InternalValue ival =
-                    InternalValue.create(retrieve(), targetType, nsContext);
+                    InternalValue.create(ValueHelper.convert(retrieve(), targetType), nsContext);
                 // convert InternalValue to Value using this
                 // session's namespace mappings
                 return ival.toJCRValue(resolver);
@@ -297,7 +297,7 @@
             } else {
                 // convert serialized value to InternalValue using
                 // current namespace context of xml document
-                return InternalValue.create(retrieve(), type, nsContext);
+                return InternalValue.create(ValueHelper.convert(retrieve(), type), nsContext);
             }
         } catch (IOException e) {
             throw new RepositoryException("Error accessing property value", e);

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/StringValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/StringValue.java?rev=419916&r1=419915&r2=419916&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/StringValue.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/xml/StringValue.java
Fri Jul  7 09:13:03 2006
@@ -60,7 +60,8 @@
             
             // convert serialized value to InternalValue using
             // current namespace context of xml document
-            InternalValue ival = InternalValue.create(value, type, nsContext);
+            InternalValue ival =
+                    InternalValue.create(ValueHelper.convert(value, type), nsContext);
             // convert InternalValue to Value using this
             // session's namespace mappings
             return ival.toJCRValue(resolver);
@@ -84,7 +85,7 @@
             } else {
                 // convert serialized value to InternalValue using
                 // current namespace context of xml document
-                return InternalValue.create(value, targetType, nsContext);
+                return InternalValue.create(ValueHelper.convert(value, targetType), nsContext);
             }
         } catch (IOException e) {
             throw new RepositoryException("Error decoding Base64 content", e);

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/value/ValueHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/value/ValueHelper.java?rev=419916&r1=419915&r2=419916&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/value/ValueHelper.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/value/ValueHelper.java
Fri Jul  7 09:13:03 2006
@@ -53,6 +53,7 @@
      * @return
      * @throws ValueFormatException
      * @throws IllegalArgumentException
+     * @see #convert(Value, int)
      */
     public static Value convert(String srcValue, int targetType)
             throws ValueFormatException, IllegalArgumentException {
@@ -69,6 +70,7 @@
      * @return
      * @throws ValueFormatException
      * @throws IllegalArgumentException
+     * @see #convert(Value, int)
      */
     public static Value[] convert(String[] srcValues, int targetType)
             throws ValueFormatException, IllegalArgumentException {
@@ -88,6 +90,7 @@
      * @return
      * @throws ValueFormatException
      * @throws IllegalArgumentException
+     * @see #convert(Value, int)
      */
     public static Value[] convert(Value[] srcValues, int targetType)
             throws ValueFormatException, IllegalArgumentException {
@@ -117,6 +120,10 @@
     }
 
     /**
+     * Converts the given value to a value of the specified target type.
+     * The conversion is performed according to the rules described in
+     * "6.2.6 Property Type Conversion" in the JSR 170 specification.
+     *
      * @param srcValue
      * @param targetType
      * @return



Mime
View raw message