jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r551616 - /jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
Date Thu, 28 Jun 2007 16:35:26 GMT
Author: reschke
Date: Thu Jun 28 09:35:25 2007
New Revision: 551616

URL: http://svn.apache.org/viewvc?view=rev&rev=551616
Log:
JCR-817: fix ensureCanSetProperty so that value conversions are not allowed anymore.

Modified:
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java?view=diff&rev=551616&r1=551615&r2=551616
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
Thu Jun 28 09:35:25 2007
@@ -19,6 +19,7 @@
 import junit.framework.TestResult;
 
 import javax.jcr.Node;
+import javax.jcr.PropertyType;
 import javax.jcr.Session;
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
@@ -30,6 +31,7 @@
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.PropertyDefinition;
 
 import java.util.StringTokenizer;
 import java.util.Random;
@@ -540,7 +542,37 @@
             throw new NotExecutableException("This repository does not seem to support multiple
workspaces.");
         }
     }
-    
+
+
+    private boolean canSetProperty(NodeType nodeType, String propertyName, int propertyType)
{
+        PropertyDefinition propDefs[] = nodeType.getPropertyDefinitions();
+
+        for (int i = 0; i < propDefs.length; i++) {
+            if (propDefs[i].getName().equals(propertyName) || propDefs[i].getName().equals("*"))
{
+                if (propDefs[i].getRequiredType() == propertyType || propDefs[i].getRequiredType()
== PropertyType.UNDEFINED) {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+
+    private boolean canSetProperty(Node node, String propertyName, int propertyType) throws
RepositoryException {
+
+        if (canSetProperty(node.getPrimaryNodeType(), propertyName, propertyType)) {
+            return true;
+        }
+        else {
+            NodeType mixins[] = node.getMixinNodeTypes();
+            boolean canSetIt = false;
+            for (int i = 0; i < mixins.length && !canSetIt; i++) {
+                canSetIt |= canSetProperty(mixins[i], propertyName, propertyType);
+            }
+            return canSetIt;
+        }
+    }
+
     /**
      * Checks that the repository can set the property to the required type, otherwise aborts
with
      * {@link NotExecutableException}.
@@ -548,21 +580,12 @@
      * type is not supported
      */
     protected void ensureCanSetProperty(Node node, String propertyName, Value value) throws
NotExecutableException, RepositoryException {
-        
-        boolean canSetIt = node.getPrimaryNodeType().canSetProperty(propertyName, value);
-        if (! canSetIt) {
-            // check mixins
-            NodeType mixins[] = node.getMixinNodeTypes();
-            for (int i = 0; i < mixins.length && !canSetIt; i++) {
-                canSetIt |= mixins[i].canSetProperty(propertyName, value);
-            }
-        }
-      
-        if (! canSetIt) {
+
+        if (! canSetProperty(node, propertyName, value.getType())) {
             throw new NotExecutableException("configured property name " + propertyName +
" can not be set on node " + node.getPath());
         }
     }
-    
+
     /**
      * Checks that the repository can set the property to the required type, otherwise aborts
with
      * {@link NotExecutableException}.
@@ -571,16 +594,9 @@
      */
     protected void ensureCanSetProperty(Node node, String propertyName, Value[] values) throws
NotExecutableException, RepositoryException {
       
-        boolean canSetIt = node.getPrimaryNodeType().canSetProperty(propertyName, values);
-        if (! canSetIt) {
-            // check mixins
-            NodeType mixins[] = node.getMixinNodeTypes();
-            for (int i = 0; i < mixins.length && !canSetIt; i++) {
-                canSetIt |= mixins[i].canSetProperty(propertyName, values);
-            }
-        }
-      
-        if (! canSetIt) {
+        int propertyType = values.length == 0 ? PropertyType.UNDEFINED : values[0].getType();
+        
+        if (! canSetProperty(node, propertyName, propertyType)) {
             throw new NotExecutableException("configured property name " + propertyName +
" can not be set on node " + node.getPath());
         }
     }



Mime
View raw message