[dna-commits] DNA SVN: r830 - trunk/dna-jcr/src/main/java/org/jboss/dna/jcr.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Thu Apr 16 09:58:49 EDT 2009


Author: rhauch
Date: 2009-04-16 09:58:49 -0400 (Thu, 16 Apr 2009)
New Revision: 830

Modified:
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
Log:
DNA-356 Need to Throw ItemExistsException if addNode Call Fails Due to SNS

Added a patch that changes SessionCache.NodeEditor.addNode(...) to throw an ItemExistsException if the node cannot be added because an item at the specified path already exists and same-name siblings are not allowed, per the specification (see the JIRA issue for the details).  An additional lookup of the child node definition is performed, but this isn't a problem since it is already an error case and the extra work is justified to provide more useful information in the exception.

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java	2009-04-15 22:42:18 UTC (rev 829)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/SessionCache.java	2009-04-16 13:58:49 UTC (rev 830)
@@ -37,6 +37,7 @@
 import java.util.UUID;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.Item;
+import javax.jcr.ItemExistsException;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.Node;
 import javax.jcr.PathNotFoundException;
@@ -842,7 +843,7 @@
             if (desiredUuid == null) desiredUuid = UUID.randomUUID();
 
             // Verify that this node accepts a child of the supplied name (given any existing SNS nodes) ...
-            int numSns = node.getChildren().getCountOfSameNameSiblingsWithName(name);
+            int numSns = node.getChildren().getCountOfSameNameSiblingsWithName(name) + 1;
             JcrNodeDefinition definition = nodeTypes().findChildNodeDefinition(node.getPrimaryTypeName(),
                                                                                node.getMixinTypeNames(),
                                                                                name,
@@ -851,6 +852,21 @@
                                                                                true);
             // Make sure there was a valid child node definition ...
             if (definition == null) {
+
+                // Check if the definition would have worked with less SNS
+                definition = nodeTypes().findChildNodeDefinition(node.getPrimaryTypeName(),
+                                                                 node.getMixinTypeNames(),
+                                                                 name,
+                                                                 primaryTypeName,
+                                                                 numSns - 1,
+                                                                 true);
+                if (definition != null) {
+                    // Only failed because there was no SNS definition - throw ItemExistsException per 7.1.4 of 1.0.1 spec
+                    Path pathForChild = pathFactory.create(getPathFor(node), name, numSns + 1);
+                    String msg = JcrI18n.noSnsDefinitionForNode.text(pathForChild, workspaceName());
+                    throw new ItemExistsException(msg);
+                }
+                // Didn't work for other reasons - throw ConstraintViolationException
                 Path pathForChild = pathFactory.create(getPathFor(node), name, numSns + 1);
                 String msg = JcrI18n.nodeDefinitionCouldNotBeDeterminedForNode.text(pathForChild, workspaceName());
                 throw new ConstraintViolationException(msg);




More information about the dna-commits mailing list