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 15:57:37 UTC
svn commit: r1376913 - in /jackrabbit/oak/trunk:
oak-core/src/main/java/org/apache/jackrabbit/oak/core/
oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Author: mduerig
Date: Fri Aug 24 13:57:36 2012
New Revision: 1376913
URL: http://svn.apache.org/viewvc?rev=1376913&view=rev
Log:
OAK-275 Introduce TreeLocation interface
OAK-220 PropertyState can only be accessed from parent tree
write access for properties
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.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/core/TreeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java?rev=1376913&r1=1376912&r2=1376913&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java Fri Aug 24 13:57:36 2012
@@ -610,7 +610,7 @@ public class TreeImpl implements Tree, P
}
}
- private class PropertyLocation implements TreeLocation {
+ public class PropertyLocation implements TreeLocation {
private final NodeLocation parent;
private final PropertyState property;
@@ -652,6 +652,59 @@ public class TreeImpl implements Tree, P
public Status getStatus() {
return parent.tree.internalGetPropertyStatus(property.getName());
}
+
+ /**
+ * Set the value of the underlying property
+ * @param value the value to set
+ * @return {@code true} on success false otherwise
+ */
+ public boolean setValue(CoreValue value) {
+ if (canWrite()) {
+ parent.tree.setProperty(property.getName(), value);
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ /**
+ * Set the values of the underlying property
+ * @param values the values to set
+ * @return {@code true} on success false otherwise
+ */
+ public boolean setValues(List<CoreValue> values) {
+ if (canWrite()) {
+ parent.tree.setProperty(property.getName(), values);
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ /**
+ * Remove the underlying property
+ * @return {@code true} on success false otherwise
+ */
+ public boolean remove() {
+ if (canWrite()) {
+ parent.tree.removeProperty(property.getName());
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ private boolean canRead() {
+ return root.getPermissions().canRead(getPath(), true);
+ }
+
+ private boolean canWrite() {
+ // TODO implement canWrite
+ return canRead();
+ }
}
private static class NullLocation implements TreeLocation {
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java?rev=1376913&r1=1376912&r2=1376913&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java Fri Aug 24 13:57:36 2012
@@ -103,7 +103,7 @@ public abstract class ItemDelegate {
* @throws InvalidItemStateException if the location points to a stale item
*/
@Nonnull
- public final TreeLocation getLocation() throws InvalidItemStateException {
+ public TreeLocation getLocation() throws InvalidItemStateException {
TreeLocation location = getLocationOrNull();
if (location == null) {
throw new InvalidItemStateException("Item is stale");
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=1376913&r1=1376912&r2=1376913&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 13:57:36 2012
@@ -27,8 +27,8 @@ import javax.jcr.nodetype.PropertyDefini
import org.apache.jackrabbit.oak.api.CoreValue;
import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.TreeLocation;
+import org.apache.jackrabbit.oak.core.TreeImpl.PropertyLocation;
import org.apache.jackrabbit.oak.util.TODO;
/**
@@ -180,7 +180,7 @@ public class PropertyDelegate extends It
* @param value
*/
public void setValue(CoreValue value) throws InvalidItemStateException {
- getParentTree().setProperty(getName(), value);
+ getLocation().setValue(value);
}
/**
@@ -188,34 +188,30 @@ public class PropertyDelegate extends It
* @param values
*/
public void setValues(List<CoreValue> values) throws InvalidItemStateException {
- getParentTree().setProperty(getName(), values);
+ getLocation().setValues(values);
}
/**
* Remove the property
*/
public void remove() throws InvalidItemStateException {
- getParentTree().removeProperty(getName());
+ getLocation().remove();
}
//------------------------------------------------------------< private >---
@Nonnull
private PropertyState getPropertyState() throws InvalidItemStateException {
- PropertyState property = getLocation().getProperty();
- if (property == null) {
- throw new InvalidItemStateException("Property is stale");
- }
- return property;
+ return getLocation().getProperty(); // Not null
}
- @Nonnull
- private Tree getParentTree() throws InvalidItemStateException {
- Tree tree = getLocation().getParent().getTree();
- if (tree == null) {
- throw new InvalidItemStateException("Parent node is stale");
+ @Override
+ public PropertyLocation getLocation() throws InvalidItemStateException {
+ TreeLocation location = super.getLocation();
+ if (location.getProperty() == null) {
+ throw new InvalidItemStateException("Property is stale");
}
- return tree;
+ return (PropertyLocation) location;
}
}