jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r776757 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueHelper.java
Date Wed, 20 May 2009 16:32:35 GMT
Author: stefan
Date: Wed May 20 16:32:35 2009
New Revision: 776757

URL: http://svn.apache.org/viewvc?rev=776757&view=rev
Log:
JCR-1609:  new Property Types (WIP...)
JCR-2061: References and Dereferencing of Property Values (WIP...)


Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueHelper.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java?rev=776757&r1=776756&r2=776757&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NodeImpl.java
Wed May 20 16:32:35 2009
@@ -4590,9 +4590,10 @@
         // check state of this instance
         sanityCheck();
 
+        // TODO tweak query implemention in order to support WEAKREFERENCE reverse lookup

         try {
             Query q = session.getWorkspace().getQueryManager().createQuery(
-                    "//*[jcr:contains[., '" + data.getId() + "']",
+                    "//*[jcr:contains(., '" + data.getId() + "')]",
                     Query.XPATH);
             QueryResult result = q.execute();
             ArrayList l = new ArrayList<Property>();

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueHelper.java?rev=776757&r1=776756&r2=776757&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueHelper.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/ValueHelper.java
Wed May 20 16:32:35 2009
@@ -37,6 +37,7 @@
 import java.io.FilterInputStream;
 import java.io.OutputStream;
 import java.io.BufferedOutputStream;
+import java.net.URI;
 
 /**
  * The <code>ValueHelper</code> class provides several <code>Value</code>
@@ -245,7 +246,7 @@
     /**
      * 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.
+     * "3.6.4 Property Type Conversion" in the JSR 283 specification.
      *
      * @param srcValue
      * @param targetType
@@ -336,6 +337,17 @@
                 }
                 break;
 
+            case PropertyType.DECIMAL:
+                // convert to DECIMAL
+                try {
+                    val = factory.createValue(srcValue.getDecimal());
+                } catch (RepositoryException re) {
+                    throw new ValueFormatException("conversion failed: "
+                            + PropertyType.nameFromValue(srcType) + " to "
+                            + PropertyType.nameFromValue(targetType), re);
+                }
+                break;
+
             case PropertyType.PATH:
                 // convert to PATH
                 switch (srcType) {
@@ -360,11 +372,35 @@
                         val = factory.createValue(path, targetType);
                         break;
 
+                    case PropertyType.URI:
+                        URI uri;
+                        try {
+                            uri = URI.create(srcValue.getString());
+                        } catch (RepositoryException re) {
+                            // should never happen
+                            throw new ValueFormatException("failed to convert source value
to PATH value",
+                                    re);
+                        }
+                        if (uri.isAbsolute()) {
+                            // uri contains scheme...
+                            throw new ValueFormatException("failed to convert URI value to
PATH value");
+                        }
+                        String p = uri.getPath();
+
+                        if (p.startsWith("./")) {
+                            p = p.substring(2);
+                        }
+
+                        val = factory.createValue(p, targetType);
+                        break;
+
                     case PropertyType.BOOLEAN:
                     case PropertyType.DATE:
                     case PropertyType.DOUBLE:
+                    case PropertyType.DECIMAL:
                     case PropertyType.LONG:
                     case PropertyType.REFERENCE:
+                    case PropertyType.WEAKREFERENCE:
                         throw new ValueFormatException("conversion failed: "
                                 + PropertyType.nameFromValue(srcType) + " to "
                                 + PropertyType.nameFromValue(targetType));
@@ -401,8 +437,10 @@
                     case PropertyType.BOOLEAN:
                     case PropertyType.DATE:
                     case PropertyType.DOUBLE:
+                    case PropertyType.DECIMAL:
                     case PropertyType.LONG:
                     case PropertyType.REFERENCE:
+                    case PropertyType.WEAKREFERENCE:
                         throw new ValueFormatException("conversion failed: "
                                 + PropertyType.nameFromValue(srcType) + " to "
                                 + PropertyType.nameFromValue(targetType));
@@ -422,6 +460,7 @@
 
                     case PropertyType.BINARY:
                     case PropertyType.STRING:
+                    case PropertyType.WEAKREFERENCE:
                         // try conversion via string
                         String uuid;
                         try {
@@ -438,6 +477,46 @@
                     case PropertyType.DATE:
                     case PropertyType.DOUBLE:
                     case PropertyType.LONG:
+                    case PropertyType.DECIMAL:
+                    case PropertyType.PATH:
+                    case PropertyType.NAME:
+                        throw new ValueFormatException("conversion failed: "
+                                + PropertyType.nameFromValue(srcType) + " to "
+                                + PropertyType.nameFromValue(targetType));
+
+                    default:
+                        throw new IllegalArgumentException("not a valid type constant: "
+ srcType);
+                }
+                break;
+
+            case PropertyType.WEAKREFERENCE:
+                // convert to WEAKREFERENCE
+                switch (srcType) {
+                    case PropertyType.WEAKREFERENCE:
+                        // no conversion needed, return original value
+                        // (redundant code, just here for the sake of clarity)
+                        return srcValue;
+
+                    case PropertyType.BINARY:
+                    case PropertyType.STRING:
+                    case PropertyType.REFERENCE:
+                        // try conversion via string
+                        String uuid;
+                        try {
+                            // get string value
+                            uuid = srcValue.getString();
+                        } catch (RepositoryException re) {
+                            // should never happen
+                            throw new ValueFormatException("failed to convert source value
to WEAKREFERENCE value", re);
+                        }
+                        val = factory.createValue(uuid, targetType);
+                        break;
+
+                    case PropertyType.BOOLEAN:
+                    case PropertyType.DATE:
+                    case PropertyType.DOUBLE:
+                    case PropertyType.LONG:
+                    case PropertyType.DECIMAL:
                     case PropertyType.PATH:
                     case PropertyType.NAME:
                         throw new ValueFormatException("conversion failed: "
@@ -449,6 +528,73 @@
                 }
                 break;
 
+            case PropertyType.URI:
+                // convert to URI
+                switch (srcType) {
+                    case PropertyType.URI:
+                        // no conversion needed, return original value
+                        // (redundant code, just here for the sake of clarity)
+                        return srcValue;
+
+                    case PropertyType.BINARY:
+                    case PropertyType.STRING:
+                        // try conversion via string
+                        String uuid;
+                        try {
+                            // get string value
+                            uuid = srcValue.getString();
+                        } catch (RepositoryException re) {
+                            // should never happen
+                            throw new ValueFormatException("failed to convert source value
to URI value", re);
+                        }
+                        val = factory.createValue(uuid, targetType);
+                        break;
+
+                    case PropertyType.NAME:
+                        String name;
+                        try {
+                            // get string value
+                            name = srcValue.getString();
+                        } catch (RepositoryException re) {
+                            // should never happen
+                            throw new ValueFormatException("failed to convert source value
to URI value", re);
+                        }
+                        // prefix name with "./" (jsr 283 spec 3.6.4.8)
+                        val = factory.createValue("./" + name, targetType);
+                        break;
+
+                    case PropertyType.PATH:
+                        String path;
+                        try {
+                            // get string value
+                            path = srcValue.getString();
+                        } catch (RepositoryException re) {
+                            // should never happen
+                            throw new ValueFormatException("failed to convert source value
to URI value", re);
+                        }
+                        if (!path.startsWith("/")) {
+                            // prefix non-absolute path with "./" (jsr 283 spec 3.6.4.9)
+                            path = "./" + path;
+                        }
+                        val = factory.createValue(path, targetType);
+                        break;
+
+                    case PropertyType.BOOLEAN:
+                    case PropertyType.DATE:
+                    case PropertyType.DOUBLE:
+                    case PropertyType.LONG:
+                    case PropertyType.DECIMAL:
+                    case PropertyType.REFERENCE:
+                    case PropertyType.WEAKREFERENCE:
+                        throw new ValueFormatException("conversion failed: "
+                                + PropertyType.nameFromValue(srcType) + " to "
+                                + PropertyType.nameFromValue(targetType));
+
+                    default:
+                        throw new IllegalArgumentException("not a valid type constant: "
+ srcType);
+                }
+                break;
+
             default:
                 throw new IllegalArgumentException("not a valid type constant: " + targetType);
         }



Mime
View raw message