jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1415668 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/nodetype/
Date Fri, 30 Nov 2012 14:55:04 GMT
Author: mduerig
Date: Fri Nov 30 14:55:03 2012
New Revision: 1415668

URL: http://svn.apache.org/viewvc?rev=1415668&view=rev
Log:
OAK-479: Adding a node to a node that doesn't accept children doesn't fail with ConstraintViolationException
Throw ConstraintViolationException instead of generic RepositoryException when during node
type validation  no child node definition can be found

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java?rev=1415668&r1=1415667&r2=1415668&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
Fri Nov 30 14:55:03 2012
@@ -362,7 +362,23 @@ public abstract class ReadOnlyNodeTypeMa
     }
 
     @Override
-    public NodeDefinition getDefinition(Iterable<NodeType> parentNodeTypes, String
nodeName, NodeType nodeType) throws RepositoryException {
+    public NodeDefinition getDefinition(Iterable<NodeType> parentNodeTypes, String
nodeName, NodeType nodeType)
+            throws RepositoryException {
+
+        NodeDefinition def = getDefinitionOrNull(parentNodeTypes, nodeName, nodeType);
+        if (def == null) {
+            throw new RepositoryException("No matching node definition found for " + this);
+        }
+
+        return def;
+    }
+
+    /**
+     * Same as {@link #getDefinition(Iterable, String, javax.jcr.nodetype.NodeType)} but
returns
+     * {@code null} if no matching definition could be found instead of throwing a
+     * {@code RepositoryException}.
+     */
+    public NodeDefinition getDefinitionOrNull(Iterable<NodeType> parentNodeTypes, String
nodeName, NodeType nodeType) {
         List<NodeDefinition> residualDefs = new ArrayList<NodeDefinition>();
         // TODO: This may need to be optimized
         // TODO: cleanup redundancy with getDefinition(Node, Node)
@@ -403,7 +419,7 @@ public abstract class ReadOnlyNodeTypeMa
             }
         }
 
-        throw new RepositoryException("No matching node definition found for " + this);
+        return null;
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java?rev=1415668&r1=1415667&r2=1415668&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidator.java
Fri Nov 30 14:55:03 2012
@@ -236,6 +236,10 @@ class TypeValidator implements Validator
 
         public void checkRemoveNode(String name, NodeType nodeType) throws RepositoryException
{
             NodeDefinition definition = getDefinition(name, nodeType);
+            if (definition == null) {
+                throw new ConstraintViolationException("No matching node definition found
for " + name);
+            }
+
             if (definition.isProtected()) {
                 return;
             }
@@ -247,6 +251,10 @@ class TypeValidator implements Validator
 
         public void checkAddChildNode(String name, NodeType nodeType) throws RepositoryException
{
             NodeDefinition definition = getDefinition(name, nodeType);
+            if (definition == null) {
+                throw new ConstraintViolationException("No matching node definition found
for " + name);
+            }
+
             if (definition.isProtected()) {
                 return;
             }
@@ -290,7 +298,7 @@ class TypeValidator implements Validator
             return ntm.getDefinition(allTypes, propertyName, isMultiple, propertyType, true);
         }
 
-        private NodeDefinition getDefinition(String nodeName, NodeType nodeType) throws RepositoryException
{
+        private NodeDefinition getDefinition(String nodeName, NodeType nodeType) {
             // FIXME: ugly hack to workaround sns-hack that was used to map sns-item definitions
with node types.
             String nameToCheck = nodeName;
             if (nodeName.startsWith("jcr:childNodeDefinition") && !nodeName.equals("jcr:childNodeDefinition"))
{
@@ -299,7 +307,7 @@ class TypeValidator implements Validator
             if (nodeName.startsWith("jcr:propertyDefinition") && !nodeName.equals("jcr:propertyDefinition"))
{
                 nameToCheck = nodeName.substring(0, "jcr:propertyDefinition".length());
             }
-            return ntm.getDefinition(allTypes, nameToCheck, nodeType);
+            return ntm.getDefinitionOrNull(allTypes, nameToCheck, nodeType);
         }
 
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeTest.java?rev=1415668&r1=1415667&r2=1415668&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/nodetype/NodeTypeTest.java
Fri Nov 30 14:55:03 2012
@@ -23,16 +23,14 @@ import javax.jcr.Session;
 import javax.jcr.nodetype.ConstraintViolationException;
 
 import org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class NodeTypeTest extends AbstractRepositoryTest {
 
     /**
      * Add a node to a node type that does not accept child nodes
-     * FIXME OAK-479
+     * See OAK-479
      */
-    @Ignore("OAK-479")
     @Test(expected = ConstraintViolationException.class)
     public void illegalAddNode() throws Exception {
         Session session = getAdminSession();



Mime
View raw message