Author: mduerig
Date: Fri Aug 24 09:56:25 2012
New Revision: 1376877
URL: http://svn.apache.org/viewvc?rev=1376877&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=1376877&r1=1376876&r2=1376877&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 09:56:25 2012
@@ -53,9 +53,13 @@ public class NodeDelegate extends ItemDe
private TreeLocation location;
NodeDelegate(SessionDelegate sessionDelegate, Tree tree) {
+ this(sessionDelegate, tree.getLocation());
+ }
+
+ NodeDelegate(SessionDelegate sessionDelegate, TreeLocation location) {
super(sessionDelegate);
- assert tree != null;
- this.location = tree.getLocation();
+ assert location != null;
+ this.location = location;
}
@Override
@@ -70,8 +74,10 @@ public class NodeDelegate extends ItemDe
@Override
public NodeDelegate getParent() throws InvalidItemStateException {
- Tree parent = getTree().getParent();
- return parent == null ? null : new NodeDelegate(sessionDelegate, parent);
+ TreeLocation parentLocation = getLocation().getParent();
+ return parentLocation.getTree() == null
+ ? null
+ : new NodeDelegate(sessionDelegate, parentLocation);
}
@Override
@@ -153,8 +159,10 @@ public class NodeDelegate extends ItemDe
*/
@CheckForNull
public NodeDelegate getChild(String relPath) {
- Tree tree = getChildLocation(relPath).getTree();
- return tree == null ? null : new NodeDelegate(sessionDelegate, tree);
+ TreeLocation childLocation = getChildLocation(relPath);
+ return childLocation.getTree() == null
+ ? null
+ : new NodeDelegate(sessionDelegate, childLocation);
}
/**
@@ -193,9 +201,9 @@ public class NodeDelegate extends ItemDe
for (CoreValue value : order.getValues()) {
String name = value.getString();
- Tree child = tree.getChild(name);
- if (child != null && !name.startsWith(":")) {
- ordered.put(name, new NodeDelegate(sessionDelegate, child));
+ TreeLocation childLocation = tree.getLocation().getChild(name);
+ if (childLocation.getTree() != null && !name.startsWith(":"))
{
+ ordered.put(name, new NodeDelegate(sessionDelegate, childLocation));
}
}
@@ -276,8 +284,8 @@ public class NodeDelegate extends ItemDe
if (old != null && old.isArray()) {
throw new ValueFormatException("Attempt to set a single value to multi-valued
property.");
}
- PropertyState propertyState = tree.setProperty(name, value);
- return new PropertyDelegate(sessionDelegate, tree, propertyState);
+ tree.setProperty(name, value);
+ return new PropertyDelegate(sessionDelegate, tree.getLocation().getChild(name));
}
public void removeProperty(String name) throws InvalidItemStateException {
@@ -297,8 +305,8 @@ public class NodeDelegate extends ItemDe
if (old != null && ! old.isArray()) {
throw new ValueFormatException("Attempt to set multiple values to single valued
property.");
}
- PropertyState propertyState = tree.setProperty(name, value);
- return new PropertyDelegate(sessionDelegate, tree, propertyState);
+ tree.setProperty(name, value);
+ return new PropertyDelegate(sessionDelegate, tree.getLocation().getChild(name));
}
/**
@@ -358,9 +366,9 @@ public class NodeDelegate extends ItemDe
}
private Iterator<NodeDelegate> nodeDelegateIterator(
- Iterator<Tree> childNodeStates) {
+ Iterator<Tree> children) {
return Iterators.transform(
- Iterators.filter(childNodeStates, new Predicate<Tree>() {
+ Iterators.filter(children, new Predicate<Tree>() {
@Override
public boolean apply(Tree tree) {
return !tree.getName().startsWith(":");
@@ -368,8 +376,8 @@ public class NodeDelegate extends ItemDe
}),
new Function<Tree, NodeDelegate>() {
@Override
- public NodeDelegate apply(Tree state) {
- return new NodeDelegate(sessionDelegate, state);
+ public NodeDelegate apply(Tree tree) {
+ return new NodeDelegate(sessionDelegate, tree);
}
});
}
@@ -386,8 +394,7 @@ public class NodeDelegate extends ItemDe
new Function<PropertyState, PropertyDelegate>() {
@Override
public PropertyDelegate apply(PropertyState propertyState) {
- return new PropertyDelegate(sessionDelegate, location.getTree(),
- propertyState);
+ return new PropertyDelegate(sessionDelegate, location.getChild(propertyState.getName()));
}
});
}
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=1376877&r1=1376876&r2=1376877&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 09:56:25 2012
@@ -43,14 +43,6 @@ public class PropertyDelegate extends It
/** The underlying {@link TreeLocation} of this node. */
private TreeLocation location;
- PropertyDelegate(SessionDelegate sessionDelegate, Tree parent, PropertyState propertyState)
{
- super(sessionDelegate);
-
- assert parent != null;
- assert propertyState != null;
- this.location = parent.getLocation().getChild(propertyState.getName());
- }
-
PropertyDelegate(SessionDelegate sessionDelegate, TreeLocation location) {
super(sessionDelegate);
assert location != null;
@@ -75,7 +67,7 @@ public class PropertyDelegate extends It
@Override
@CheckForNull
public NodeDelegate getParent() throws InvalidItemStateException {
- return new NodeDelegate(sessionDelegate, getParentTree());
+ return new NodeDelegate(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=1376877&r1=1376876&r2=1376877&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 09:56:25 2012
@@ -172,11 +172,11 @@ public class SessionDelegate {
@CheckForNull
public NodeDelegate getRoot() {
- Tree root = getTree("/");
- if (root == null) {
+ TreeLocation rootLocation = getLocation("/");
+ if (rootLocation.getTree() == null) {
return null;
} else {
- return new NodeDelegate(this, root);
+ return new NodeDelegate(this, rootLocation);
}
}
@@ -188,8 +188,8 @@ public class SessionDelegate {
*/
@CheckForNull
public NodeDelegate getNode(String path) {
- Tree tree = getTree(path);
- return tree == null ? null : new NodeDelegate(this, tree);
+ TreeLocation location = getLocation(path);
+ return location.getTree() == null ? null : new NodeDelegate(this, location);
}
@CheckForNull
|