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

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Wed Apr 22 05:22:16 EDT 2009


Author: rhauch
Date: 2009-04-22 05:22:16 -0400 (Wed, 22 Apr 2009)
New Revision: 843

Modified:
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
Log:
DNA-377 AbstractJcrNode.addNode(String relPath) Throws Wrong Exception if relPath Has Form PropertyName/NodeName

Applied the patch that handles a path of exactly 2 segments, so that the proper exception is thrown.

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java	2009-04-22 08:49:23 UTC (rev 842)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java	2009-04-22 09:22:16 UTC (rev 843)
@@ -963,23 +963,30 @@
                 editor = cache.getEditorFor(parentInfo.getUuid());
             } catch (PathNotFoundException e) {
                 // We're going to throw an exception ... the question is which one ...
-                if (parentPath.size() > 1) {
-                    // Per the TCK, if relPath references a property, then we have to throw a ConstraintViolationException
-                    // So, if we can't find the parent, try for the parent's parent and see if the last segment of the parent's
-                    // path contains a property ...
-                    Path grandparentPath = parentPath.getParent();
-                    assert grandparentPath != null;
-                    try {
-                        NodeInfo grandparentInfo = cache.findNodeInfo(nodeUuid, grandparentPath); // throws PathNotFoundException
-                        if (grandparentInfo.getProperty(parentPath.getLastSegment().getName()) != null) {
-                            // Need to throw a ConstraintViolationException since the request was to add a child to
-                            // a property ...
-                            throw new ConstraintViolationException(JcrI18n.invalidPathParameter.text(relPath, "relPath"));
-                        }
-                    } catch (PathNotFoundException e2) {
-                        // eat, since the original exception is what we want ...
+                try {
+                    NodeInfo grandparentInfo;
+                    if (parentPath.size() > 1) {
+                        // Per the TCK, if relPath references a property, then we have to throw a ConstraintViolationException
+                        // So, if we can't find the parent, try for the parent's parent and see if the last segment of the parent's
+                        // path contains a property ...
+                        Path grandparentPath = parentPath.getParent();
+                        assert grandparentPath != null;
+                        
+                        grandparentInfo = cache.findNodeInfo(nodeUuid, grandparentPath); // throws PathNotFoundException
                     }
+                    else {
+                        grandparentInfo = this.nodeInfo();
+                    }
+                    
+                    if (grandparentInfo.getProperty(parentPath.getLastSegment().getName()) != null) {
+                        // Need to throw a ConstraintViolationException since the request was to add a child to
+                        // a property ...
+                        throw new ConstraintViolationException(JcrI18n.invalidPathParameter.text(relPath, "relPath"));
+                    }
+                } catch (PathNotFoundException e2) {
+                    // eat, since the original exception is what we want ...
                 }
+
                 // Otherwise, just throw the PathNotFoundException ...
                 throw e;
             }




More information about the dna-commits mailing list