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 2013/05/01 18:32:28 UTC
svn commit: r1478082 - in /jackrabbit/oak/trunk:
oak-core/src/main/java/org/apache/jackrabbit/oak/core/
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/
oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/
oak-core/src/main/jav...
Author: mduerig
Date: Wed May 1 16:32:27 2013
New Revision: 1478082
URL: http://svn.apache.org/r1478082
Log:
OAK-798: Review / refactor TreeImpl and related classes
reduce usage of deprecated methods
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeTypeProviderImpl.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeDefinitionImpl.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/ImmutableTreeTest.java
jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/http/OakServlet.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java?rev=1478082&r1=1478081&r2=1478082&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableTree.java Wed May 1 16:32:27 2013
@@ -65,7 +65,7 @@ import org.apache.jackrabbit.oak.spi.sta
* <li>{@link ParentProvider#ROOTPROVIDER}: the default parent provider for
* the root tree. All children will get {@link DefaultParentProvider}</li>
* <li>{@link ParentProvider#UNSUPPORTED}: throws {@code UnsupportedOperationException}
- * upon hierarchy related methods like {@link #getParentOrNull()}, {@link #getPath()} and
+ * upon hierarchy related methods like {@link #getParent()}, {@link #getPath()} and
* {@link #getIdentifier()}</li>
* </ul>
*
@@ -129,7 +129,7 @@ public final class ImmutableTree extends
if (root instanceof RootImpl) {
return new ImmutableTree(((RootImpl) root).getBaseState(), typeProvider);
} else if (root instanceof ImmutableRoot) {
- return ((ImmutableRoot) root).getTreeOrNull("/");
+ return ((ImmutableRoot) root).getTree("/");
} else {
throw new IllegalArgumentException("Unsupported Root implementation.");
}
@@ -149,7 +149,7 @@ public final class ImmutableTree extends
path = "/";
} else {
StringBuilder sb = new StringBuilder();
- ImmutableTree parent = getParentOrNull();
+ ImmutableTree parent = getParent();
sb.append(parent.getPath());
if (!parent.isRoot()) {
sb.append('/');
@@ -161,6 +161,14 @@ public final class ImmutableTree extends
return path;
}
+ // FIXME this in contrast to @NonNull of the Tree contract this method might return null.
+ // revisit Tree contract and implementation
+ @CheckForNull
+ @Override
+ public ImmutableTree getParent() {
+ return parentProvider.getParent();
+ }
+
@Override
@Deprecated
public ImmutableTree getParentOrNull() {
@@ -266,10 +274,10 @@ public final class ImmutableTree extends
PropertyState property = state.getProperty(JcrConstants.JCR_UUID);
if (property != null) {
return property.getValue(STRING);
- } else if (getParentOrNull().isRoot()) {
+ } else if (isRoot()) {
return "/";
} else {
- return PathUtils.concat(getParentOrNull().getIdentifier(), getName());
+ return PathUtils.concat(getParent().getIdentifier(), getName());
}
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeTypeProviderImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeTypeProviderImpl.java?rev=1478082&r1=1478081&r2=1478082&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeTypeProviderImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeTypeProviderImpl.java Wed May 1 16:32:27 2013
@@ -36,11 +36,11 @@ public final class TreeTypeProviderImpl
@Override
public int getType(ImmutableTree tree) {
- ImmutableTree parent = tree.getParentOrNull();
- if (parent == null) {
+ if (tree.isRoot()) {
return TYPE_DEFAULT;
}
+ ImmutableTree parent = tree.getParent();
int type;
switch (parent.getType()) {
case TYPE_HIDDEN:
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeDefinitionImpl.java?rev=1478082&r1=1478081&r2=1478082&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeDefinitionImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeDefinitionImpl.java Wed May 1 16:32:27 2013
@@ -62,10 +62,10 @@ class NodeDefinitionImpl extends ItemDef
}
NodeType[] types = new NodeType[oakNames.length];
- Tree root = definition.getParentOrNull().getParentOrNull();
+ Tree root = definition.getParent().getParent();
for (int i = 0; i < oakNames.length; i++) {
- Tree type = root.getChildOrNull(oakNames[i]);
- checkState(type != null);
+ Tree type = root.getChild(oakNames[i]);
+ checkState(type.exists());
types[i] = new NodeTypeImpl(type, mapper);
}
return types;
@@ -85,9 +85,8 @@ class NodeDefinitionImpl extends ItemDef
public NodeType getDefaultPrimaryType() {
String oakName = getName(JcrConstants.JCR_DEFAULTPRIMARYTYPE);
if (oakName != null) {
- Tree root = definition.getParentOrNull().getParentOrNull();
- Tree type = root.getChildOrNull(oakName);
- checkState(type != null);
+ Tree type = definition.getParent().getParent().getChild(oakName);
+ checkState(type.exists());
return new NodeTypeImpl(type, mapper);
} else {
return null;
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java?rev=1478082&r1=1478081&r2=1478082&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java Wed May 1 16:32:27 2013
@@ -16,6 +16,21 @@
*/
package org.apache.jackrabbit.oak.plugins.nodetype;
+import static com.google.common.base.Preconditions.checkState;
+import static org.apache.jackrabbit.JcrConstants.JCR_CHILDNODEDEFINITION;
+import static org.apache.jackrabbit.JcrConstants.JCR_HASORDERABLECHILDNODES;
+import static org.apache.jackrabbit.JcrConstants.JCR_ISMIXIN;
+import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
+import static org.apache.jackrabbit.JcrConstants.JCR_NODETYPENAME;
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYITEMNAME;
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
+import static org.apache.jackrabbit.JcrConstants.JCR_PROPERTYDEFINITION;
+import static org.apache.jackrabbit.JcrConstants.JCR_SUPERTYPES;
+import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_IS_ABSTRACT;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_IS_QUERYABLE;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.RESIDUAL_NAME;
+
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
@@ -37,39 +52,23 @@ import javax.jcr.nodetype.NodeType;
import javax.jcr.nodetype.NodeTypeIterator;
import javax.jcr.nodetype.PropertyDefinition;
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
import org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.core.IdentifierManager;
import org.apache.jackrabbit.oak.namepath.JcrNameParser;
import org.apache.jackrabbit.oak.namepath.JcrPathParser;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
-import org.apache.jackrabbit.oak.core.IdentifierManager;
import org.apache.jackrabbit.oak.plugins.nodetype.constraint.Constraints;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Function;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
-import static com.google.common.base.Preconditions.checkState;
-import static org.apache.jackrabbit.JcrConstants.JCR_CHILDNODEDEFINITION;
-import static org.apache.jackrabbit.JcrConstants.JCR_HASORDERABLECHILDNODES;
-import static org.apache.jackrabbit.JcrConstants.JCR_ISMIXIN;
-import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
-import static org.apache.jackrabbit.JcrConstants.JCR_NODETYPENAME;
-import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYITEMNAME;
-import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
-import static org.apache.jackrabbit.JcrConstants.JCR_PROPERTYDEFINITION;
-import static org.apache.jackrabbit.JcrConstants.JCR_SUPERTYPES;
-import static org.apache.jackrabbit.JcrConstants.JCR_UUID;
-import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_IS_ABSTRACT;
-import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_IS_QUERYABLE;
-import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.RESIDUAL_NAME;
-
/**
* <pre>
* [nt:nodeType]
@@ -197,11 +196,11 @@ class NodeTypeImpl extends AbstractTypeD
private void addSupertypes(Tree type, Map<String, NodeType> supertypes) {
PropertyState property = type.getProperty(JCR_SUPERTYPES);
if (property != null) {
- Tree root = definition.getParentOrNull();
+ Tree root = definition.getParent();
for (String oakName : property.getValue(Type.NAMES)) {
if (!supertypes.containsKey(oakName)) {
- Tree supertype = root.getChildOrNull(oakName);
- checkState(supertype != null);
+ Tree supertype = root.getChild(oakName);
+ checkState(supertype.exists());
supertypes.put(
oakName, new NodeTypeImpl(supertype, mapper));
addSupertypes(supertype, supertypes);
@@ -216,10 +215,10 @@ class NodeTypeImpl extends AbstractTypeD
String[] oakNames = getNames(JCR_SUPERTYPES);
if (oakNames != null && oakNames.length > 0) {
supertypes = new NodeType[oakNames.length];
- Tree root = definition.getParentOrNull();
+ Tree root = definition.getParent();
for (int i = 0; i < oakNames.length; i++) {
- Tree type = root.getChildOrNull(oakNames[i]);
- checkState(type != null);
+ Tree type = root.getChild(oakNames[i]);
+ checkState(type.exists());
supertypes[i] = new NodeTypeImpl(type, mapper);
}
}
@@ -230,7 +229,7 @@ class NodeTypeImpl extends AbstractTypeD
public NodeTypeIterator getSubtypes() {
Map<String, Set<String>> inheritance = Maps.newHashMap();
- Tree root = definition.getParentOrNull();
+ Tree root = definition.getParent();
for (Tree child : root.getChildren()) {
String oakName = getOakName(child);
PropertyState supertypes = child.getProperty(JCR_SUPERTYPES);
@@ -258,7 +257,7 @@ class NodeTypeImpl extends AbstractTypeD
if (subnames != null) {
for (String subname : subnames) {
if (!subtypes.containsKey(subname)) {
- Tree tree = root.getChildOrNull(subname);
+ Tree tree = root.getChild(subname);
subtypes.put(subname, new NodeTypeImpl(tree, mapper));
}
}
@@ -270,7 +269,7 @@ class NodeTypeImpl extends AbstractTypeD
List<NodeType> subtypes = Lists.newArrayList();
String oakName = getOakName();
- Tree root = definition.getParentOrNull();
+ Tree root = definition.getParent();
for (Tree child : root.getChildren()) {
PropertyState supertypes = child.getProperty(JCR_SUPERTYPES);
if (supertypes != null) {
@@ -429,7 +428,7 @@ class NodeTypeImpl extends AbstractTypeD
}
private ReadOnlyNodeTypeManager getManager() {
- final Tree types = definition.getParentOrNull();
+ final Tree types = definition.getParent();
return new ReadOnlyNodeTypeManager() {
@Override @CheckForNull
protected Tree getTypes() {
@@ -471,8 +470,8 @@ class NodeTypeImpl extends AbstractTypeD
}
Iterable<PropertyDefinition> getDeclaredNamedPropertyDefinitions(String oakName) {
- Tree named = definition.getChildOrNull("oak:namedPropertyDefinitions");
- if (named != null) {
+ Tree named = definition.getChild("oak:namedPropertyDefinitions");
+ if (named.exists()) {
String escapedName;
if (JCR_PRIMARYTYPE.equals(oakName)) {
escapedName = "oak:primaryType";
@@ -483,25 +482,7 @@ class NodeTypeImpl extends AbstractTypeD
} else {
escapedName = oakName;
}
- Tree definitions = named.getChildOrNull(escapedName);
- if (definitions != null) {
- return Iterables.transform(
- definitions.getChildren(),
- new Function<Tree, PropertyDefinition>() {
- @Override
- public PropertyDefinition apply(Tree input) {
- return new PropertyDefinitionImpl(
- input, NodeTypeImpl.this, mapper);
- }
- });
- }
- }
- return Collections.emptyList();
- }
-
- Iterable<PropertyDefinition> getDeclaredResidualPropertyDefinitions() {
- Tree definitions = definition.getChildOrNull("oak:residualPropertyDefinitions");
- if (definitions != null) {
+ Tree definitions = named.getChild(escapedName);
return Iterables.transform(
definitions.getChildren(),
new Function<Tree, PropertyDefinition>() {
@@ -515,39 +496,43 @@ class NodeTypeImpl extends AbstractTypeD
return Collections.emptyList();
}
+ Iterable<PropertyDefinition> getDeclaredResidualPropertyDefinitions() {
+ Tree definitions = definition.getChild("oak:residualPropertyDefinitions");
+ return Iterables.transform(
+ definitions.getChildren(),
+ new Function<Tree, PropertyDefinition>() {
+ @Override
+ public PropertyDefinition apply(Tree input) {
+ return new PropertyDefinitionImpl(
+ input, NodeTypeImpl.this, mapper);
+ }
+ });
+ }
+
Iterable<NodeDefinition> getDeclaredNamedNodeDefinitions(String oakName) {
- Tree named = definition.getChildOrNull("oak:namedChildNodeDefinitions");
- if (named != null) {
- Tree definitions = named.getChildOrNull(oakName);
- if (definitions != null) {
- return Iterables.transform(
- definitions.getChildren(),
- new Function<Tree, NodeDefinition>() {
- @Override
- public NodeDefinition apply(Tree input) {
- return new NodeDefinitionImpl(
- input, NodeTypeImpl.this, mapper);
- }
- });
- }
- }
- return Collections.emptyList();
+ Tree definitions = definition.getChild("oak:namedChildNodeDefinitions").getChild(oakName);
+ return Iterables.transform(
+ definitions.getChildren(),
+ new Function<Tree, NodeDefinition>() {
+ @Override
+ public NodeDefinition apply(Tree input) {
+ return new NodeDefinitionImpl(
+ input, NodeTypeImpl.this, mapper);
+ }
+ });
}
Iterable<NodeDefinition> getDeclaredResidualNodeDefinitions() {
- Tree definitions = definition.getChildOrNull("oak:residualChildNodeDefinitions");
- if (definitions != null) {
- return Iterables.transform(
- definitions.getChildren(),
- new Function<Tree, NodeDefinition>() {
- @Override
- public NodeDefinition apply(Tree input) {
- return new NodeDefinitionImpl(
- input, NodeTypeImpl.this, mapper);
- }
- });
- }
- return Collections.emptyList();
+ Tree definitions = definition.getChild("oak:residualChildNodeDefinitions");
+ return Iterables.transform(
+ definitions.getChildren(),
+ new Function<Tree, NodeDefinition>() {
+ @Override
+ public NodeDefinition apply(Tree input) {
+ return new NodeDefinitionImpl(
+ input, NodeTypeImpl.this, mapper);
+ }
+ });
}
//--------------------------------------------------------------------------
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java?rev=1478082&r1=1478081&r2=1478082&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java Wed May 1 16:32:27 2013
@@ -281,11 +281,11 @@ public class SelectorImpl extends Source
return null;
}
if (p.equals("..")) {
- t = t.getParentOrNull();
+ t = t.isRoot() ? null : t.getParent();
} else if (p.equals(".")) {
// same node
} else {
- t = t.getChildOrNull(p);
+ t = t.getChild(p);
}
}
propertyName = PathUtils.getName(propertyName);
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java?rev=1478082&r1=1478081&r2=1478082&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java Wed May 1 16:32:27 2013
@@ -84,7 +84,7 @@ public class NodeUtil {
@CheckForNull
public NodeUtil getParent() {
- return new NodeUtil(tree.getParentOrNull(), mapper);
+ return new NodeUtil(tree.getParent(), mapper);
}
public boolean isRoot() {
@@ -92,13 +92,13 @@ public class NodeUtil {
}
public boolean hasChild(String name) {
- return tree.getChildOrNull(name) != null;
+ return tree.hasChild(name);
}
@CheckForNull
public NodeUtil getChild(String name) {
- Tree child = tree.getChildOrNull(name);
- return (child == null) ? null : new NodeUtil(child, mapper);
+ Tree child = tree.getChild(name);
+ return child.exists() ? new NodeUtil(child, mapper) : null;
}
@Nonnull
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/ImmutableTreeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/ImmutableTreeTest.java?rev=1478082&r1=1478081&r2=1478082&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/ImmutableTreeTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/ImmutableTreeTest.java Wed May 1 16:32:27 2013
@@ -18,6 +18,11 @@
*/
package org.apache.jackrabbit.oak.core;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import org.apache.jackrabbit.oak.OakBaseTest;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.ContentSession;
@@ -27,11 +32,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
public class ImmutableTreeTest extends OakBaseTest {
private Root root;
@@ -42,7 +42,7 @@ public class ImmutableTreeTest extends O
// Add test content
root = session.getLatestRoot();
- Tree tree = root.getTreeOrNull("/");
+ Tree tree = root.getTree("/");
Tree x = tree.addChild("x");
Tree y = x.addChild("y");
Tree z = y.addChild("z");
@@ -59,18 +59,18 @@ public class ImmutableTreeTest extends O
@Test
public void testGetPath() {
- TreeImpl tree = (TreeImpl) root.getTreeOrNull("/");
+ TreeImpl tree = (TreeImpl) root.getTree("/");
ImmutableTree immutable = new ImmutableTree(tree.getNodeState());
assertEquals("/", immutable.getPath());
- immutable = immutable.getChildOrNull("x");
+ immutable = immutable.getChild("x");
assertEquals("/x", immutable.getPath());
- immutable = immutable.getChildOrNull("y");
+ immutable = immutable.getChild("y");
assertEquals("/x/y", immutable.getPath());
- immutable = immutable.getChildOrNull("z");
+ immutable = immutable.getChild("z");
assertEquals("/x/y/z", immutable.getPath());
}
@@ -89,7 +89,7 @@ public class ImmutableTreeTest extends O
public void testRoot() {
ImmutableTree tree = ImmutableTree.createFromRoot(root, TreeTypeProvider.EMPTY);
assertTrue(tree.isRoot());
- assertNull(tree.getParentOrNull());
+ assertNull(tree.getParent());
assertEquals("", tree.getName());
assertEquals(TreeTypeProvider.TYPE_DEFAULT, tree.getType());
}
@@ -97,15 +97,15 @@ public class ImmutableTreeTest extends O
@Test
public void testGetParent() {
ImmutableTree tree = ImmutableTree.createFromRoot(root, TreeTypeProvider.EMPTY);
- assertNull(tree.getParentOrNull());
+ assertNull(tree.getParent());
- ImmutableTree child = tree.getChildOrNull("x");
- assertNotNull(child.getParentOrNull());
- assertEquals("/", child.getParentOrNull().getPath());
+ ImmutableTree child = tree.getChild("x");
+ assertNotNull(child.getParent());
+ assertEquals("/", child.getParent().getPath());
ImmutableTree disconnected = new ImmutableTree(ImmutableTree.ParentProvider.UNSUPPORTED, child.getName(), child.getNodeState(), TreeTypeProvider.EMPTY);
try {
- disconnected.getParentOrNull();
+ disconnected.getParent();
} catch (UnsupportedOperationException e) {
// success
}
Modified: jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/http/OakServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/http/OakServlet.java?rev=1478082&r1=1478081&r2=1478082&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/http/OakServlet.java (original)
+++ jackrabbit/oak/trunk/oak-http/src/main/java/org/apache/jackrabbit/oak/http/OakServlet.java Wed May 1 16:32:27 2013
@@ -171,14 +171,14 @@ public class OakServlet extends HttpServ
if (tree.hasProperty(name)) {
tree.removeProperty(name);
}
- Tree child = tree.getChildOrNull(name);
- if (child == null) {
+ Tree child = tree.getChild(name);
+ if (!child.exists()) {
child = tree.addChild(name);
}
post(value, child);
} else {
- Tree child = tree.getChildOrNull(name);
- if (child != null) {
+ Tree child = tree.getChild(name);
+ if (child.exists()) {
child.remove();
}
if (value.isNull()) {
@@ -205,10 +205,10 @@ public class OakServlet extends HttpServ
try {
Root root = (Root) request.getAttribute("root");
Tree tree = (Tree) request.getAttribute("tree");
- Tree parent = tree.getParentOrNull();
- if (parent != null) {
- Tree child = parent.getChildOrNull(tree.getName());
- if (child != null) {
+ if (!tree.isRoot()) {
+ Tree parent = tree.getParent();
+ Tree child = parent.getChild(tree.getName());
+ if (child.exists()) {
child.remove();
}
root.commit();