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/05/07 18:34:03 UTC

svn commit: r1335103 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: ItemDelegate.java NodeDelegate.java PropertyDelegate.java

Author: mduerig
Date: Mon May  7 16:34:02 2012
New Revision: 1335103

URL: http://svn.apache.org/viewvc?rev=1335103&view=rev
Log:
OAK-84: Delegates for Session, Node, Property and Item
- Add Javadoc
- Simplify getParent(), getPath()

Modified:
    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/NodeDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java

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=1335103&r1=1335102&r2=1335103&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 Mon May  7 16:34:02 2012
@@ -19,17 +19,50 @@ package org.apache.jackrabbit.oak.jcr;
 
 import org.apache.jackrabbit.oak.api.Tree.Status;
 
+/**
+ * Abstract base class for {@link NodeDelegate} and {@link PropertyDelegate}
+ */
 public abstract class ItemDelegate {
-    
+
+    protected final SessionDelegate sessionDelegate;
+
+    protected ItemDelegate(SessionDelegate sessionDelegate) {
+        this.sessionDelegate = sessionDelegate;
+    }
+
+    /**
+     * Get the name of this item
+     * @return oak name of this item
+     */
     abstract String getName();
 
+    /**
+     * Get the path of this item
+     * @return oak path of this item
+     */
     abstract String getPath();
 
+    /**
+     * Get the parent of this item
+     * @return  parent of this item or {@code null} for root
+     */
     abstract NodeDelegate getParent();
 
+    /**
+     * Determine whether this item is stale
+     * @return  {@code true} iff stale
+     */
     abstract boolean isStale();
 
+    /**
+     * Get the status of this item
+     * @return  {@link Status} of this item
+     */
     abstract Status getStatus();
 
+    /**
+     * Get the session delegate with which this item is associated
+     * @return  {@link SessionDelegate} to which this item belongs
+     */
     abstract SessionDelegate getSessionDelegate();
 }

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=1335103&r1=1335102&r2=1335103&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 Mon May  7 16:34:02 2012
@@ -36,55 +36,40 @@ import java.util.List;
  * An item is stale if the underlying items does not exist anymore.
  */
 public class NodeDelegate extends ItemDelegate {
-    private final SessionDelegate sessionDelegate;
+
+    /**
+     * The underlying {@link Tree} instance. In order to ensure the instance
+     * is up to date, this field <em>should not be accessed directly</em> but
+     * rather the {@link #getTree()} method should be used.
+     */
     private Tree tree;
 
     NodeDelegate(SessionDelegate sessionDelegate, Tree tree) {
-        this.sessionDelegate = sessionDelegate;
+        super(sessionDelegate);
         this.tree = tree;
     }
 
-    /**
-     * Get the name of this node
-     * @return oak name of the node
-     */
     @Override
     String getName() {
         return getTree().getName();
     }
 
-    /**
-     * Get the path of this node
-     * @return oak path of the node
-     */
     @Override
     String getPath() {
         return '/' + getTree().getPath();
     }
 
-    /**
-     * Get the parent of this node
-     * @return  parent of this node or {@code null} it this is the root
-     */
     @Override
     NodeDelegate getParent() {
         Tree parent = getParentTree();
         return parent == null ? null : new NodeDelegate(sessionDelegate, parent);
     }
 
-    /**
-     * Determine whether this node is stale
-     * @return  {@code true} iff stale
-     */
     @Override
     boolean isStale() {
         return getTree() == null;
     }
 
-    /**
-     * Get the status of this node
-     * @return  {@link Status} of this node
-     */
     @Override
     Status getStatus() {
         Tree parent = getParentTree();
@@ -96,10 +81,6 @@ public class NodeDelegate extends ItemDe
         }
     }
 
-    /**
-     * Get the session which with this node is associated
-     * @return  {@link SessionDelegate} to which this node belongs
-     */
     @Override
     SessionDelegate getSessionDelegate() {
         return sessionDelegate;
@@ -114,8 +95,8 @@ public class NodeDelegate extends ItemDe
     }
 
     /**
-     * Get the number of properties of this node
-     * @return  number of properties of this node
+     * Get the number of properties of the node
+     * @return  number of properties of the node
      */
     long getPropertyCount() {
         return getTree().getPropertyCount();
@@ -141,8 +122,8 @@ public class NodeDelegate extends ItemDe
     }
 
     /**
-     * Get the properties of this node
-     * @return  properties of this node
+     * Get the properties of the node
+     * @return  properties of the node
      */
     Iterator<PropertyDelegate> getProperties() {
         return propertyDelegateIterator(getTree().getProperties().iterator());
@@ -150,7 +131,7 @@ public class NodeDelegate extends ItemDe
 
     /**
      * Get the number of child nodes
-     * @return  number of child nodes of this node
+     * @return  number of child nodes of the node
      */
     long getChildCount() {
         return getTree().getChildrenCount();
@@ -169,7 +150,7 @@ public class NodeDelegate extends ItemDe
 
     /**
      * Get child nodes
-     * @return  child nodes of this node
+     * @return  child nodes of the node
      */
     Iterator<NodeDelegate> getChildren() {
         return nodeDelegateIterator(getTree().getChildren().iterator());
@@ -210,7 +191,7 @@ public class NodeDelegate extends ItemDe
     }
 
     /**
-     * Remove this node
+     * Remove the node
      */
     void remove() {
         getParentTree().removeChild(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=1335103&r1=1335102&r2=1335103&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 Mon May  7 16:34:02 2012
@@ -27,15 +27,32 @@ import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
 import java.util.List;
 
+/**
+ * {@code PropertyDelegate} serve as internal representations of {@code Property}s.
+ * The methods of this class do not throw checked exceptions. Instead clients
+ * are expected to inspect the return value and ensure that all preconditions
+ * hold before a method is invoked. Specifically the behaviour of all methods
+ * of this class but {@link #isStale()} is undefined if the instance is stale.
+ * An item is stale if the underlying items does not exist anymore.
+ */
 public class PropertyDelegate extends ItemDelegate {
 
-    private final SessionDelegate sessionDelegate;
+    /**
+     * The underlying {@link Tree} of the parent node. In order to ensure the
+     * instance is up to date, this field <em>should not be accessed directly</em>
+     * but rather the {@link #getParentTree()} Tree()} method should be used.
+     */
     private Tree parent;
+
+    /**
+     * The underlying {@link PropertyState}. In order to ensure the instance is up
+     * to date, this field <em>should not be accessed directly</em> but rather the
+     * {@link #getPropertyState()} method should be used.
+     */
     private PropertyState propertyState;
 
-    PropertyDelegate(SessionDelegate sessionDelegate, Tree parent,
-            PropertyState propertyState) {
-        this.sessionDelegate = sessionDelegate;
+    PropertyDelegate(SessionDelegate sessionDelegate, Tree parent, PropertyState propertyState) {
+        super(sessionDelegate);
         this.parent = parent;
         this.propertyState = propertyState;
     }
@@ -47,14 +64,12 @@ public class PropertyDelegate extends It
 
     @Override
     String getPath() {
-        String parentPath = getParentTree().getPath();
-        return parentPath.isEmpty() ? '/' + getName() : '/' + parentPath + '/' + getName();
+        return getParent().getPath() + '/' + getName();
     }
 
     @Override
     NodeDelegate getParent() {
-        Tree parent = getParentTree();
-        return parent == null ? null : new NodeDelegate(sessionDelegate, parent);
+        return new NodeDelegate(sessionDelegate, getParentTree());
     }
 
     @Override
@@ -72,18 +87,34 @@ public class PropertyDelegate extends It
         return sessionDelegate;
     }
 
+    /**
+     * Get the value of the property
+     * @return  value or {@code null} if multi values
+     */
     CoreValue getValue() {
         return getPropertyState().getValue();
     }
 
+    /**
+     * Get the value of the property
+     * @return  value or {@code null} if single valued
+     */
     Iterable<CoreValue> getValues() {
         return getPropertyState().getValues();
     }
 
+    /**
+     * Determine whether the property is multi valued
+     * @return  {@code true} if multi valued
+     */
     boolean isMultivalue() {
         return getPropertyState().isArray();
     }
 
+    /**
+     * Get the property definition of the property
+     * @return
+     */
     PropertyDefinition getDefinition() {
         // TODO
         return new PropertyDefinition() {
@@ -167,14 +198,25 @@ public class PropertyDelegate extends It
         };
     }
 
+    /**
+     * Set the value of the property
+     * @param value
+     */
     void setValue(CoreValue value) {
         getParentTree().setProperty(getName(), value);
     }
 
+    /**
+     * Set the values of the property
+     * @param values
+     */
     void setValues(List<CoreValue> values) {
         getParentTree().setProperty(getName(), values);
     }
 
+    /**
+     * Remove the property
+     */
     void remove() {
         getParentTree().removeProperty(getName());
     }