jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1384001 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java oak-jcr/pom.xml
Date Wed, 12 Sep 2012 15:40:34 GMT
Author: mduerig
Date: Wed Sep 12 15:40:34 2012
New Revision: 1384001

URL: http://svn.apache.org/viewvc?rev=1384001&view=rev
Log:
OAK-66: JCR Node Type Management
property type validation

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
    jackrabbit/oak/trunk/oak-jcr/pom.xml

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java?rev=1384001&r1=1384000&r2=1384001&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/NodeTypeImpl.java
Wed Sep 12 15:40:34 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.plugins.type;
 
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.security.AccessController;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -25,7 +27,9 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Queue;
 import java.util.Set;
+import java.util.UUID;
 
+import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
@@ -275,11 +279,8 @@ class NodeTypeImpl implements NodeType {
             if ((propertyName.equals(name) && !isProtected(definition))
                     || "*".equals(name)) {
                 if (!definition.isMultiple()) {
-                    if (!meetsValueConstraints(value, definition.getValueConstraints()))
{
-                        return false;
-                    }
-                    // TODO: Check value type, etc.
-                    return true;
+                    return meetsTypeConstraints(value, definition.getRequiredType()) &&
+                           meetsValueConstraints(value, definition.getValueConstraints());
                 }
             }
         }
@@ -297,17 +298,82 @@ class NodeTypeImpl implements NodeType {
             if ((propertyName.equals(name) && !isProtected(definition))
                     || "*".equals(name)) {
                 if (definition.isMultiple()) {
-                    if (!meetsValueConstraints(values, definition.getValueConstraints()))
{
-                        return false;
-                    }
-                    // TODO: Check value type, etc.
-                    return true;
+                    return meetsTypeConstraints(values, definition.getRequiredType()) &&
+                           meetsValueConstraints(values, definition.getValueConstraints());
                 }
             }
         }
         return false;
     }
 
+    private static boolean meetsTypeConstraints(Value value, int requiredType) {
+        try {
+            switch (requiredType) {
+                case PropertyType.STRING:
+                    value.getString();
+                    return true;
+                case PropertyType.BINARY:
+                    value.getBinary();
+                    return true;
+                case PropertyType.LONG:
+                    value.getLong();
+                    return true;
+                case PropertyType.DOUBLE:
+                    value.getDouble();
+                    return true;
+                case PropertyType.DATE:
+                    value.getDate();
+                    return true;
+                case PropertyType.BOOLEAN:
+                    value.getBoolean();
+                    return true;
+                case PropertyType.NAME:
+                    // TODO check type constraint for name
+                    value.getString();
+                    return true;
+                case PropertyType.PATH:
+                    // TODO check type constraint for path
+                    value.getString();
+                    return true;
+                case PropertyType.REFERENCE:
+                case PropertyType.WEAKREFERENCE:
+                    UUID.fromString(value.getString());
+                    return true;
+                case PropertyType.URI:
+                    new URI(value.getString());
+                    return true;
+                case PropertyType.DECIMAL:
+                    value.getDecimal();
+                    return true;
+                case PropertyType.UNDEFINED:
+                    return true;
+                default:
+                    log.warn("Invalid property type value: " + requiredType);
+                    return false;
+            }
+        }
+        catch (RepositoryException e) {
+            return false;
+        }
+        catch (URISyntaxException e) {
+            return false;
+        }
+        catch (IllegalArgumentException e) {
+            return false;
+        }
+    }
+
+    private static boolean meetsTypeConstraints(Value[] values, int requiredType) {
+        // Constraints must be met by all values
+        for (Value value : values) {
+            if (!meetsTypeConstraints(value, requiredType)) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
     private static boolean meetsValueConstraints(Value value, String[] constraints) {
         if (constraints == null || constraints.length == 0) {
             return true;

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1384001&r1=1384000&r2=1384001&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Wed Sep 12 15:40:34 2012
@@ -69,7 +69,6 @@ org.apache.jackrabbit.test.api.HasPermis
 org.apache.jackrabbit.test.api.lock.LockManagerTest#testAddInvalidLockToken
 org.apache.jackrabbit.test.api.lock.LockManagerTest#testLockNonLockable
 org.apache.jackrabbit.test.api.nodetype.PropertyDefTest#testIsMandatory
-org.apache.jackrabbit.test.api.nodetype.CanSetPropertyDateTest#testConversions
 org.apache.jackrabbit.test.api.nodetype.CanSetPropertyPathTest#testConversions
 org.apache.jackrabbit.test.api.LifecycleTest
 org.apache.jackrabbit.test.api.query.ElementTest#testElementTestNameTestSomeNTWithSNS<!--
OAK-203 -->



Mime
View raw message