jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1327076 - in /jackrabbit/oak/trunk: oak-it/jcr/pom.xml oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Date Tue, 17 Apr 2012 12:57:26 GMT
Author: reschke
Date: Tue Apr 17 12:57:26 2012
New Revision: 1327076

URL: http://svn.apache.org/viewvc?rev=1327076&view=rev
Log:
fix Node.getDepth, implement Node.getAncestor

Modified:
    jackrabbit/oak/trunk/oak-it/jcr/pom.xml
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java

Modified: jackrabbit/oak/trunk/oak-it/jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/jcr/pom.xml?rev=1327076&r1=1327075&r2=1327076&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-it/jcr/pom.xml Tue Apr 17 12:57:26 2012
@@ -44,7 +44,6 @@
             <property>
               <name>known.issues</name>
               <value>
-org.apache.jackrabbit.test.api.RootNodeTest#testGetDepth
 org.apache.jackrabbit.test.api.NodeReadMethodsTest
 org.apache.jackrabbit.test.api.NamespaceRegistryReadMethodsTest
 org.apache.jackrabbit.test.api.PropertyReadMethodsTest

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1327076&r1=1327075&r2=1327076&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Tue Apr 17 12:57:26 2012
@@ -118,8 +118,16 @@ public class NodeImpl extends ItemImpl i
      */
     @Override
     public Item getAncestor(int depth) throws RepositoryException {
-        // todo implement getAncestor
-        return null;
+        int current = getDepth();
+        if (depth < 0 || depth > current) {
+            throw new ItemNotFoundException("ancestor at depth " + depth + " does not exist");
+        }
+        TransientNodeState ancestor = getTransientNodeState();
+        while (depth < current) {
+            ancestor = ancestor.getParent();
+            current -= 1;
+        }
+        return new NodeImpl(sessionContext, ancestor);
     }
 
     /**
@@ -127,7 +135,7 @@ public class NodeImpl extends ItemImpl i
      */
     @Override
     public int getDepth() throws RepositoryException {
-        return Paths.getDepth(path());
+        return Paths.getDepth(getPath());
     }
 
     /**



Mime
View raw message