jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1331409 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Date Fri, 27 Apr 2012 13:01:45 GMT
Author: mduerig
Date: Fri Apr 27 13:01:45 2012
New Revision: 1331409

URL: http://svn.apache.org/viewvc?rev=1331409&view=rev
Log:
OAK-15: Clean up oak-jcr
simplify, remove unused method

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/Paths.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/Paths.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/Paths.java?rev=1331409&r1=1331408&r2=1331409&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/Paths.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/Paths.java
Fri Apr 27 13:01:45 2012
@@ -16,14 +16,12 @@
 */
 package org.apache.jackrabbit.oak.namepath;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-
 import org.apache.jackrabbit.mk.util.PathUtils;
 import org.apache.jackrabbit.oak.namepath.JcrNameParser.Listener;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * All path in the Oak API have the following form
  * <p>
@@ -109,6 +107,17 @@ public final class Paths {
         return PathUtils.getDepth(path);
     }
 
+    /**
+     * Split a path into elements. The root path ("/") and the empty path ("")
+     * is zero elements.
+     *
+     * @param path the path
+     * @return an Iterable for the path elements
+     */
+    public static Iterable<String> elements(String path) {
+        return PathUtils.elements(path);
+    }
+
     public static String toOakName(String name, final NameMapper mapper) {
         final StringBuilder element = new StringBuilder();
         
@@ -286,59 +295,4 @@ public final class Paths {
         return jcrPath.toString();
     }
 
-    //------------------------------------------------------------< private >--- 
-
-    private static Iterable<String> split(final String string, final char separator)
{
-        return new Iterable<String>() {
-            @Override
-            public Iterator<String> iterator() {
-                return new Iterator<String>() {
-                    int pos = !string.isEmpty() && string.charAt(0) == separator
? 1 : 0;
-                    String next;
-
-                    @Override
-                    public boolean hasNext() {
-                        if (next == null) {
-                            if (pos >= string.length()) {
-                                return false;
-                            }
-                            else {
-                                int i = string.indexOf(separator, pos);
-                                if (i < 0) {
-                                    next = string.substring(pos);
-                                    pos = string.length();
-                                }
-                                else {
-                                    next = string.substring(pos, i);
-                                    pos = i + 1;
-                                }
-                                return true;
-                            }
-                        }
-                        else {
-                            return true;
-                        }
-                    }
-
-                    @Override
-                    public String next() {
-                        if (hasNext()) {
-                            String next = this.next;
-                            this.next = null;
-                            return next;
-                        }
-                        else {
-                            throw new NoSuchElementException();
-                        }
-                    }
-
-                    @Override
-                    public void remove() {
-                        throw new UnsupportedOperationException("remove");
-                    }
-                };
-            }
-        };
-    }
-
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java?rev=1331409&r1=1331408&r2=1331409&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
Fri Apr 27 13:01:45 2012
@@ -18,7 +18,6 @@ package org.apache.jackrabbit.oak.jcr;
 
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Tree.Status;
 import org.apache.jackrabbit.oak.namepath.Paths;
@@ -42,8 +41,7 @@ public class NodeDelegate extends ItemDe
     }
 
     NodeDelegate addNode(String relPath) throws RepositoryException {
-        String parentPath = Paths.concat(getPath(), Paths.getParentPath(relPath));
-        Tree parentState = getRoot().getTree(parentPath);
+        Tree parentState = getTree(Paths.getParentPath(relPath));
         if (parentState == null) {
             throw new PathNotFoundException(relPath);
         }
@@ -89,8 +87,7 @@ public class NodeDelegate extends ItemDe
     }
 
     NodeDelegate getNodeOrNull(String relOakPath) {
-        String absPath = Paths.concat(getPath(), relOakPath);
-        Tree tree = getRoot().getTree(absPath);
+        Tree tree = getTree(relOakPath);
         return tree == null ? null : new NodeDelegate(sessionContext, tree);
     }
 
@@ -118,9 +115,7 @@ public class NodeDelegate extends ItemDe
     PropertyDelegate getPropertyOrNull(String relOakPath)
             throws RepositoryException {
 
-        String absPath = Paths.concat(getPath(),
-                Paths.getParentPath(relOakPath));
-        Tree parent = getRoot().getTree(absPath);
+        Tree parent = getTree(Paths.getParentPath(relOakPath));
         if (parent == null) {
             return null;
         }
@@ -155,8 +150,15 @@ public class NodeDelegate extends ItemDe
 
     // ------------------------------------------------------------< private >---
 
-    private Root getRoot() {
-        return sessionContext.getRoot();
+    private Tree getTree(String relPath) {
+        Tree tree = getTree();
+        for (String name : Paths.elements(relPath)) {
+            if (tree == null) {
+                return null;
+            }
+            tree = tree.getChild(name);
+        }
+        return tree;
     }
 
     private synchronized Tree getTree() {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java?rev=1331409&r1=1331408&r2=1331409&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
Fri Apr 27 13:01:45 2012
@@ -18,7 +18,6 @@ package org.apache.jackrabbit.oak.jcr;
 
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.namepath.Paths;
 
@@ -166,12 +165,8 @@ public class PropertyDelegate extends It
 
     //------------------------------------------------------------< private >---
 
-    private Root getBranch() {
-        return sessionContext.getRoot();
-    }
-
     private synchronized void resolve() {
-        parent = getBranch().getTree(parent.getPath());
+        parent = sessionContext.getTree(parent.getPath());
         String path = Paths.concat(parent.getPath(), propertyState.getName());
 
         if (parent == null) {



Mime
View raw message