You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by md...@apache.org on 2012/08/24 12:28:58 UTC
svn commit: r1376885 - in
/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr:
NodeDelegate.java PropertyDelegate.java SessionDelegate.java
Author: mduerig
Date: Fri Aug 24 10:28:58 2012
New Revision: 1376885
URL: http://svn.apache.org/viewvc?rev=1376885&view=rev
Log:
OAK-275 Introduce TreeLocation interface
cleanup, refactor
Modified:
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
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
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=1376885&r1=1376884&r2=1376885&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 Aug 24 10:28:58 2012
@@ -52,11 +52,24 @@ public class NodeDelegate extends ItemDe
/** The underlying {@link TreeLocation} of this node. */
private TreeLocation location;
+ /**
+ * Create a new {@code NodeDelegate} instance for a valid {@code TreeLocation}. That
+ * is for one where {@code getTree() != null}.
+ * @param sessionDelegate
+ * @param location
+ * @return
+ */
+ static NodeDelegate create(SessionDelegate sessionDelegate, TreeLocation location) {
+ return location.getTree() == null
+ ? null
+ : new NodeDelegate(sessionDelegate, location);
+ }
+
NodeDelegate(SessionDelegate sessionDelegate, Tree tree) {
this(sessionDelegate, tree.getLocation());
}
- NodeDelegate(SessionDelegate sessionDelegate, TreeLocation location) {
+ private NodeDelegate(SessionDelegate sessionDelegate, TreeLocation location) {
super(sessionDelegate);
assert location != null;
this.location = location;
@@ -75,9 +88,7 @@ public class NodeDelegate extends ItemDe
@Override
public NodeDelegate getParent() throws InvalidItemStateException {
TreeLocation parentLocation = getLocation().getParent();
- return parentLocation.getTree() == null
- ? null
- : new NodeDelegate(sessionDelegate, parentLocation);
+ return create(sessionDelegate, parentLocation);
}
@Override
@@ -160,9 +171,7 @@ public class NodeDelegate extends ItemDe
@CheckForNull
public NodeDelegate getChild(String relPath) {
TreeLocation childLocation = getChildLocation(relPath);
- return childLocation.getTree() == null
- ? null
- : new NodeDelegate(sessionDelegate, childLocation);
+ return create(sessionDelegate, childLocation);
}
/**
@@ -201,9 +210,9 @@ public class NodeDelegate extends ItemDe
for (CoreValue value : order.getValues()) {
String name = value.getString();
- TreeLocation childLocation = tree.getLocation().getChild(name);
- if (childLocation.getTree() != null && !name.startsWith(":")) {
- ordered.put(name, new NodeDelegate(sessionDelegate, childLocation));
+ Tree child = tree.getChild(name);
+ if (child != null && !name.startsWith(":")) {
+ ordered.put(name, new NodeDelegate(sessionDelegate, child));
}
}
@@ -338,9 +347,7 @@ public class NodeDelegate extends ItemDe
if (tree == null) {
throw new InvalidItemStateException("Node is stale");
}
- else {
- return tree;
- }
+ return tree;
}
// -----------------------------------------------------------< private >---
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=1376885&r1=1376884&r2=1376885&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 Aug 24 10:28:58 2012
@@ -18,7 +18,6 @@ package org.apache.jackrabbit.oak.jcr;
import java.util.List;
-import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.jcr.InvalidItemStateException;
import javax.jcr.Value;
@@ -65,9 +64,8 @@ public class PropertyDelegate extends It
}
@Override
- @CheckForNull
public NodeDelegate getParent() throws InvalidItemStateException {
- return new NodeDelegate(sessionDelegate, location.getParent());
+ return NodeDelegate.create(sessionDelegate, location.getParent());
}
@Override
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java?rev=1376885&r1=1376884&r2=1376885&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java Fri Aug 24 10:28:58 2012
@@ -172,12 +172,7 @@ public class SessionDelegate {
@CheckForNull
public NodeDelegate getRoot() {
- TreeLocation rootLocation = getLocation("/");
- if (rootLocation.getTree() == null) {
- return null;
- } else {
- return new NodeDelegate(this, rootLocation);
- }
+ return getNode("/");
}
/**
@@ -188,8 +183,7 @@ public class SessionDelegate {
*/
@CheckForNull
public NodeDelegate getNode(String path) {
- TreeLocation location = getLocation(path);
- return location.getTree() == null ? null : new NodeDelegate(this, location);
+ return NodeDelegate.create(this, getLocation(path));
}
@CheckForNull