jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1335081 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: ItemDelegate.java NodeDelegate.java PropertyDelegate.java PropertyImpl.java
Date Mon, 07 May 2012 15:54:47 GMT
Author: mduerig
Date: Mon May  7 15:54:46 2012
New Revision: 1335081

URL: http://svn.apache.org/viewvc?rev=1335081&view=rev
Log:
OAK-84: Delegates for Session, Node, Property and Item
- Make PropertyDelegate more versatile, pull methods common with NodeDelegate up to ItemDelegate

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
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.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=1335081&r1=1335080&r2=1335081&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 15:54:46 2012
@@ -17,12 +17,19 @@
 
 package org.apache.jackrabbit.oak.jcr;
 
+import org.apache.jackrabbit.oak.api.Tree.Status;
+
 public abstract class ItemDelegate {
     
     abstract String getName();
 
     abstract String getPath();
 
+    abstract NodeDelegate getParent();
+
     abstract boolean isStale();
 
+    abstract Status getStatus();
+
+    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=1335081&r1=1335080&r2=1335081&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 15:54:46 2012
@@ -63,26 +63,29 @@ public class NodeDelegate extends ItemDe
     }
 
     /**
-     * Determine whether this node is stale
-     * @return  {@code true} iff stale
+     * Get the parent of this node
+     * @return  parent of this node or {@code null} it this is the root
      */
     @Override
-    boolean isStale() {
-        return getTree() == null;
+    NodeDelegate getParent() {
+        Tree parent = getParentTree();
+        return parent == null ? null : new NodeDelegate(sessionDelegate, parent);
     }
 
     /**
-     * Determine whether this is the root node
-     * @return  {@code true} iff this is the root node
+     * Determine whether this node is stale
+     * @return  {@code true} iff stale
      */
-    boolean isRoot() {
-        return getParentTree() == null;
+    @Override
+    boolean isStale() {
+        return getTree() == null;
     }
 
     /**
      * Get the status of this node
      * @return  {@link Status} of this node
      */
+    @Override
     Status getStatus() {
         Tree parent = getParentTree();
         if (parent == null) {
@@ -97,17 +100,17 @@ 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;
     }
 
     /**
-     * Get the parent of this node
-     * @return  parent of this node or {@code null} it this is the root
+     * Determine whether this is the root node
+     * @return  {@code true} iff this is the root node
      */
-    NodeDelegate getParent() {
-        Tree parent = getParentTree();
-        return parent == null ? null : new NodeDelegate(sessionDelegate, parent);
+    boolean isRoot() {
+        return getParentTree() == null;
     }
 
     /**

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=1335081&r1=1335080&r2=1335081&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 15:54:46 2012
@@ -19,9 +19,9 @@ package org.apache.jackrabbit.oak.jcr;
 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.Tree.Status;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 
-import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
@@ -40,7 +40,51 @@ public class PropertyDelegate extends It
         this.propertyState = propertyState;
     }
 
-    PropertyDefinition getDefinition() throws RepositoryException {
+    @Override
+    String getName() {
+        return getPropertyState().getName();
+    }
+
+    @Override
+    String getPath() {
+        String parentPath = getParentTree().getPath();
+        return parentPath.isEmpty() ? '/' + getName() : '/' + parentPath + '/' + getName();
+    }
+
+    @Override
+    NodeDelegate getParent() {
+        Tree parent = getParentTree();
+        return parent == null ? null : new NodeDelegate(sessionDelegate, parent);
+    }
+
+    @Override
+    boolean isStale() {
+        return getPropertyState() == null;
+    }
+
+    @Override
+    Status getStatus() {
+        return getParentTree().getPropertyStatus(getName());
+    }
+
+    @Override
+    SessionDelegate getSessionDelegate() {
+        return sessionDelegate;
+    }
+
+    CoreValue getValue() {
+        return getPropertyState().getValue();
+    }
+
+    Iterable<CoreValue> getValues() {
+        return getPropertyState().getValues();
+    }
+
+    boolean isMultivalue() {
+        return getPropertyState().isArray();
+    }
+
+    PropertyDefinition getDefinition() {
         // TODO
         return new PropertyDefinition() {
 
@@ -122,55 +166,31 @@ public class PropertyDelegate extends It
             }
         };
     }
-    
-    void remove() throws RepositoryException {
-        getParentTree().removeProperty(getName());
-    }
-    
-    void setValue(CoreValue value) throws RepositoryException {
+
+    void setValue(CoreValue value) {
         getParentTree().setProperty(getName(), value);
     }
 
-    void setValues(List<CoreValue> values) throws RepositoryException {
+    void setValues(List<CoreValue> values) {
         getParentTree().setProperty(getName(), values);
     }
 
-    Tree getParentTree() {
-        resolve();
-        return parent;
+    void remove() {
+        getParentTree().removeProperty(getName());
     }
 
-    PropertyState getPropertyState() {
+    //------------------------------------------------------------< private >---
+
+    private PropertyState getPropertyState() {
         resolve();
         return propertyState;
     }
 
-    Tree.Status getPropertyStatus() {
-        return getParentTree().getPropertyStatus(getName());
-    }
-    
-    @Override
-    String getName() {
-        return getPropertyState().getName();
-    }
-
-    @Override
-    String getPath() {
-        String parentPath = getParentTree().getPath();
-        return parentPath.isEmpty() ? '/' + getName() : '/' + parentPath + '/' + getName();
-    }
-
-    @Override
-    boolean isStale() {
-        return getParentTree() == null;
-    }
-
-    SessionDelegate getSessionDelegate() {
-        return sessionDelegate;
+    private Tree getParentTree() {
+        resolve();
+        return parent;
     }
 
-    //------------------------------------------------------------< private >---
-
     private synchronized void resolve() {
         parent = sessionDelegate.getTree(parent.getPath());
         String path = PathUtils.concat(parent.getPath(), propertyState.getName());
@@ -181,4 +201,5 @@ public class PropertyDelegate extends It
             propertyState = parent.getProperty(PathUtils.getName(path));
         }
     }
+
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java?rev=1335081&r1=1335080&r2=1335081&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
Mon May  7 15:54:46 2012
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
-import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree.Status;
 import org.apache.jackrabbit.oak.jcr.util.LogUtil;
 import org.apache.jackrabbit.oak.jcr.value.ValueConverter;
@@ -72,8 +71,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public Node getParent() throws RepositoryException {
-        return new NodeImpl(new NodeDelegate(sessionDelegate,
-                dlg.getParentTree()));
+        return new NodeImpl(dlg.getParent());
     }
 
     /**
@@ -81,7 +79,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public boolean isNew() {
-        return dlg.getPropertyStatus() == Status.NEW;
+        return dlg.getStatus() == Status.NEW;
     }
 
     /**
@@ -89,7 +87,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public boolean isModified() {
-        return dlg.getPropertyStatus() == Status.MODIFIED;
+        return dlg.getStatus() == Status.MODIFIED;
     }
 
     /**
@@ -97,6 +95,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public void remove() throws RepositoryException {
+        checkStatus();
         dlg.remove();
     }
 
@@ -304,7 +303,7 @@ public class PropertyImpl extends ItemIm
             throw new ValueFormatException(LogUtil.safeGetJCRPath(this) + " is multi-valued.");
         }
 
-        return ValueConverter.toValue(getPropertyState().getValue(), sessionDelegate);
+        return ValueConverter.toValue(dlg.getValue(), sessionDelegate);
     }
 
     @Override
@@ -314,7 +313,7 @@ public class PropertyImpl extends ItemIm
             throw new ValueFormatException(LogUtil.safeGetJCRPath(this) + " is not multi-valued.");
         }
 
-        return ValueConverter.toValues(getPropertyState().getValues(), sessionDelegate);
+        return ValueConverter.toValues(dlg.getValues(), sessionDelegate);
     }
 
     /**
@@ -486,7 +485,8 @@ public class PropertyImpl extends ItemIm
 
     @Override
     public boolean isMultiple() throws RepositoryException {
-        return dlg.getPropertyState().isArray();
+        checkStatus();
+        return dlg.isMultivalue();
     }
 
     //------------------------------------------------------------< private >---
@@ -513,22 +513,18 @@ public class PropertyImpl extends ItemIm
     * @return the required type for this property.
     * @throws javax.jcr.RepositoryException
     */
-   private int getRequiredType(int defaultType) throws RepositoryException {
-       // check type according to definition of this property
-       PropertyDefinition def = getDefinition();
-       int reqType = (def == null) ? PropertyType.UNDEFINED : getDefinition().getRequiredType();
-       if (reqType == PropertyType.UNDEFINED) {
-           if (defaultType == PropertyType.UNDEFINED) {
-               reqType = PropertyType.STRING;
-           } else {
-               reqType = defaultType;
-           }
-       }
-       return reqType;
-   }
-
-    private PropertyState getPropertyState() {
-        return dlg.getPropertyState();
+    private int getRequiredType(int defaultType) throws RepositoryException {
+        // check type according to definition of this property
+        PropertyDefinition def = getDefinition();
+        int reqType = (def == null) ? PropertyType.UNDEFINED : getDefinition().getRequiredType();
+        if (reqType == PropertyType.UNDEFINED) {
+            if (defaultType == PropertyType.UNDEFINED) {
+                reqType = PropertyType.STRING;
+            } else {
+                reqType = defaultType;
+            }
+        }
+        return reqType;
     }
 
     /**
@@ -537,40 +533,40 @@ public class PropertyImpl extends ItemIm
     * @param requiredType
     * @throws RepositoryException
     */
-   private void setValue(Value value, int requiredType) throws RepositoryException {
-       assert(requiredType != PropertyType.UNDEFINED);
+    private void setValue(Value value, int requiredType) throws RepositoryException {
+        assert(requiredType != PropertyType.UNDEFINED);
 
-      // TODO check again if definition validation should be respected here.
-       if (isMultiple()) {
-           throw new ValueFormatException("Attempt to set a single value to multi-valued
property.");
-       }
-       if (value == null) {
-           dlg.remove();
-       } else {
-           Value targetValue = ValueHelper.convert(value, requiredType, sessionDelegate.getValueFactory());
-           dlg.setValue(ValueConverter.toCoreValue(targetValue, sessionDelegate));
-       }
-   }
+        // TODO check again if definition validation should be respected here.
+        if (isMultiple()) {
+            throw new ValueFormatException("Attempt to set a single value to multi-valued
property.");
+        }
+        if (value == null) {
+            dlg.remove();
+        } else {
+            Value targetValue = ValueHelper.convert(value, requiredType, sessionDelegate.getValueFactory());
+            dlg.setValue(ValueConverter.toCoreValue(targetValue, sessionDelegate));
+        }
+    }
 
-   /**
+    /**
    *
    * @param values
    * @param requiredType
    * @throws RepositoryException
    */
-  private void setValues(Value[] values, int requiredType) throws RepositoryException {
-      assert(requiredType != PropertyType.UNDEFINED);
+    private void setValues(Value[] values, int requiredType) throws RepositoryException {
+        assert(requiredType != PropertyType.UNDEFINED);
 
-      // TODO check again if definition validation should be respected here.
-      if (!isMultiple()) {
-          throw new ValueFormatException("Attempt to set multiple values to single valued
property.");
-      }
-      if (values == null) {
-          dlg.remove();
-      } else {
-          Value[] targetValues = ValueHelper.convert(values, requiredType, sessionDelegate.getValueFactory());
-          dlg.setValues(ValueConverter.toCoreValues(targetValues, sessionDelegate));
-      }
-  }
+        // TODO check again if definition validation should be respected here.
+        if (!isMultiple()) {
+            throw new ValueFormatException("Attempt to set multiple values to single valued
property.");
+        }
+        if (values == null) {
+            dlg.remove();
+        } else {
+            Value[] targetValues = ValueHelper.convert(values, requiredType, sessionDelegate.getValueFactory());
+            dlg.setValues(ValueConverter.toCoreValues(targetValues, sessionDelegate));
+        }
+    }
 
 }
\ No newline at end of file



Mime
View raw message