jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r581165 - /jackrabbit/branches/1.3/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
Date Tue, 02 Oct 2007 09:14:06 GMT
Author: jukka
Date: Tue Oct  2 02:14:05 2007
New Revision: 581165

URL: http://svn.apache.org/viewvc?rev=581165&view=rev
Log:
1.3: Merged utility methods that the JCR-1110 fix uses

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

Modified: jackrabbit/branches/1.3/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.3/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java?rev=581165&r1=581164&r2=581165&view=diff
==============================================================================
--- jackrabbit/branches/1.3/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
(original)
+++ jackrabbit/branches/1.3/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/AbstractJCRTest.java
Tue Oct  2 02:14:05 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;
@@ -583,6 +585,56 @@
         if (! canSetIt) {
             throw new NotExecutableException("configured property name " + propertyName +
" can not be set on node " + node.getPath());
         }
+    }
+
+    private boolean canSetProperty(NodeType nodeType, String propertyName, int propertyType,
boolean isMultiple) {
+        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)
+                    && propDefs[i].isMultiple() == isMultiple) {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+
+    private boolean canSetProperty(Node node, String propertyName, int propertyType, boolean
isMultiple) throws RepositoryException {
+
+        if (canSetProperty(node.getPrimaryNodeType(), propertyName, propertyType, isMultiple))
{
+            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, isMultiple);
+            }
+            return canSetIt;
+        }
+    }
+
+    /**
+     * Checks that the repository can set the property to the required type, otherwise aborts
with
+     * {@link NotExecutableException}.
+     * @throws NotExecutableException when setting the property to the required
+     * type is not supported
+     */
+    protected void ensureCanSetProperty(Node node, String propertyName, int propertyType,
boolean isMultiple) throws NotExecutableException, RepositoryException {
+
+        if (! canSetProperty(node, propertyName, propertyType, isMultiple)) {
+            throw new NotExecutableException("configured property name " + propertyName +
" can not be set on node " + node.getPath());
+        }
+    }
+
+    /**
+     * Checks whether the node already has the specified mixin node type
+     */
+    protected boolean needsMixin(Node node, String mixin) throws RepositoryException {
+        return ! node.getSession().getWorkspace().getNodeTypeManager().getNodeType(node.getPrimaryNodeType().getName()).isNodeType(mixin);
     }
 
     /**



Mime
View raw message