jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1330359 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: PropertyDelegate.java PropertyImpl.java
Date Wed, 25 Apr 2012 15:43:58 GMT
Author: reschke
Date: Wed Apr 25 15:43:58 2012
New Revision: 1330359

URL: http://svn.apache.org/viewvc?rev=1330359&view=rev
Log:
split PropertyImpl into PropertyImpl and PropertyDelegate

Added:
    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/PropertyImpl.java

Added: 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=1330359&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
(added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
Wed Apr 25 15:43:58 2012
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.jcr;
+
+import java.util.List;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.PropertyDefinition;
+
+import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.namepath.Paths;
+
+public class PropertyDelegate {
+
+    private final SessionContext<SessionImpl> sessionContext;
+    private Tree parent;
+    private PropertyState propertyState;
+
+    PropertyDelegate(SessionContext<SessionImpl> sessionContext, Tree parent,
+            PropertyState propertyState) {
+        this.sessionContext = sessionContext;
+        this.parent = parent;
+        this.propertyState = propertyState;
+    }
+
+    PropertyDefinition getDefinition() throws RepositoryException {
+        // TODO
+        return null;
+    }
+    
+    void remove() throws RepositoryException {
+        getParentContentTree().removeProperty(getName());
+    }
+    
+    void setValue(CoreValue value) throws RepositoryException {
+        getParentContentTree().setProperty(getName(), value);
+    }
+
+    void setValues(List<CoreValue> values) throws RepositoryException {
+        getParentContentTree().setProperty(getName(), values);
+    }
+
+    Tree getParentContentTree() {
+        resolve();
+        return parent;
+    }
+
+    PropertyState getPropertyState() {
+        resolve();
+        return propertyState;
+    }
+
+    Tree.Status getPropertyStatus() {
+        return getParentContentTree().getPropertyStatus(getName());
+    }
+    
+    String getName() {
+        return getPropertyState().getName();
+    }
+
+    String getPath() {
+        return '/' + getParentContentTree().getPath() + '/' + getName();
+    }
+
+    //------------------------------------------------------------< private >---
+
+    private Root getBranch() {
+        return sessionContext.getBranch();
+    }
+
+    private synchronized void resolve() {
+        parent = getBranch().getTree(parent.getPath());
+        String path = Paths.concat(parent.getPath(), propertyState.getName());
+
+        if (parent == null) {
+            propertyState = null;
+        }
+        else {
+            propertyState = parent.getProperty(Paths.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=1330359&r1=1330358&r2=1330359&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
Wed Apr 25 15:43:58 2012
@@ -16,16 +16,9 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
-import org.apache.jackrabbit.oak.api.Root;
-import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.api.Tree.Status;
-import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.jcr.util.LogUtil;
-import org.apache.jackrabbit.oak.jcr.util.ValueConverter;
-import org.apache.jackrabbit.oak.namepath.Paths;
-import org.apache.jackrabbit.value.ValueHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.util.Calendar;
 
 import javax.jcr.Binary;
 import javax.jcr.Item;
@@ -39,9 +32,16 @@ import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
 import javax.jcr.nodetype.PropertyDefinition;
-import java.io.InputStream;
-import java.math.BigDecimal;
-import java.util.Calendar;
+
+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.jcr.util.LogUtil;
+import org.apache.jackrabbit.oak.jcr.util.ValueConverter;
+import org.apache.jackrabbit.oak.namepath.Paths;
+import org.apache.jackrabbit.value.ValueHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * {@code PropertyImpl}...
@@ -53,15 +53,13 @@ public class PropertyImpl extends ItemIm
      */
     private static final Logger log = LoggerFactory.getLogger(PropertyImpl.class);
 
-    private Tree parent;
-    private PropertyState propertyState;
-
+    private final PropertyDelegate pd;
+    
     PropertyImpl(SessionContext<SessionImpl> sessionContext, Tree parent,
             PropertyState propertyState) {
 
         super(sessionContext);
-        this.parent = parent;
-        this.propertyState = propertyState;
+        this.pd = new PropertyDelegate(sessionContext, parent, propertyState);
     }
 
     //---------------------------------------------------------------< Item >---
@@ -78,7 +76,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public String getName() throws RepositoryException {
-        return toJcrPath(name());
+        return toJcrPath(pd.getName());
     }
 
     /**
@@ -86,7 +84,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public String getPath() throws RepositoryException {
-        return path();
+        return toJcrPath(pd.getPath());
     }
 
     /**
@@ -94,7 +92,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public Node getParent() throws RepositoryException {
-        return new NodeImpl(sessionContext, getParentContentTree());
+        return new NodeImpl(sessionContext, pd.getParentContentTree());
     }
 
     /**
@@ -122,7 +120,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public boolean isNew() {
-        return getParentContentTree().getPropertyStatus(name()) == Status.NEW;
+        return pd.getPropertyStatus() == Status.NEW;
     }
 
     /**
@@ -130,7 +128,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public boolean isModified() {
-        return getParentContentTree().getPropertyStatus(name()) == Status.MODIFIED;
+        return pd.getPropertyStatus() == Status.MODIFIED;
     }
 
     /**
@@ -138,7 +136,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public void remove() throws RepositoryException {
-        getParentContentTree().removeProperty(name());
+        pd.remove();
     }
 
     /**
@@ -499,8 +497,7 @@ public class PropertyImpl extends ItemIm
 
     @Override
     public PropertyDefinition getDefinition() throws RepositoryException {
-        // TODO
-        return null;
+        return pd.getDefinition();
     }
 
     /**
@@ -521,74 +518,9 @@ public class PropertyImpl extends ItemIm
         }
     }
 
-    /**
-     * @see javax.jcr.Property#isMultiple()
-     */
     @Override
     public boolean isMultiple() throws RepositoryException {
-        return getPropertyState().isArray();
-    }
-
-    //------------------------------------------------------------< private >---
-
-    /**
-     *
-     * @param defaultType
-     * @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;
-    }
-
-    /**
-     *
-     * @param value
-     * @param requiredType
-     * @throws RepositoryException
-     */
-    private void setValue(Value value, int requiredType) throws RepositoryException {
-        if (requiredType == PropertyType.UNDEFINED) {
-            // should never get here since calling methods assert valid type
-            throw new IllegalArgumentException("Property type of a value cannot be undefined
(" + LogUtil.safeGetJCRPath(this) + ").");
-        }
-
-        if (value == null) {
-            remove();
-        } else {
-            Value targetValue = ValueHelper.convert(value, requiredType, getValueFactory());
-            getParentContentTree().setProperty(name(), ValueConverter.toCoreValue(targetValue,
sessionContext));
-        }
-    }
-
-    /**
-     *
-     * @param values
-     * @param requiredType
-     * @throws RepositoryException
-     */
-    private void setValues(Value[] values, int requiredType) throws RepositoryException {
-        if (requiredType == PropertyType.UNDEFINED) {
-            // should never get here since calling methods assert valid type
-            throw new IllegalArgumentException("Property type of a value cannot be undefined
(" + LogUtil.safeGetJCRPath(this) + ").");
-        }
-
-        if (values == null) {
-            remove();
-        } else {
-            Value[] targetValues = ValueHelper.convert(values, requiredType, getValueFactory());
-            getParentContentTree().setProperty(name(), ValueConverter.toCoreValues(targetValues,
sessionContext));
-        }
+        return pd.getPropertyState().isArray();
     }
 
     /**
@@ -607,38 +539,64 @@ public class PropertyImpl extends ItemIm
         }
     }
 
-    private Root getBranch() {
-        return sessionContext.getBranch();
-    }
-
-    private Tree getParentContentTree() {
-        resolve();
-        return parent;
-    }
+    /**
+    *
+    * @param defaultType
+    * @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() {
-        resolve();
-        return propertyState;
-    }
-
-    private String name() {
-        return getPropertyState().getName();
+        return pd.getPropertyState();
     }
 
-    private String path() {
-        return '/' + getParentContentTree().getPath() + '/' + name();
-    }
-
-    private synchronized void resolve() {
-        parent = getBranch().getTree(parent.getPath());
-        String path = Paths.concat(parent.getPath(), propertyState.getName());
-
-        if (parent == null) {
-            propertyState = null;
-        }
-        else {
-            propertyState = parent.getProperty(Paths.getName(path));
-        }
-    }
+    /**
+    *
+    * @param value
+    * @param requiredType
+    * @throws RepositoryException
+    */
+   private void setValue(Value value, int requiredType) throws RepositoryException {
+       
+       assert(requiredType != PropertyType.UNDEFINED);
+       
+       if (value == null) {
+           pd.remove();
+       } else {
+           Value targetValue = ValueHelper.convert(value, requiredType, sessionContext.getValueFactory());
+           pd.setValue(ValueConverter.toCoreValue(targetValue, sessionContext));
+       }
+   }
+
+   /**
+   *
+   * @param values
+   * @param requiredType
+   * @throws RepositoryException
+   */
+  private void setValues(Value[] values, int requiredType) throws RepositoryException {
+      
+      assert(requiredType != PropertyType.UNDEFINED);
+
+      if (values == null) {
+          remove();
+      } else {
+          Value[] targetValues = ValueHelper.convert(values, requiredType, sessionContext.getValueFactory());
+          pd.setValues(ValueConverter.toCoreValues(targetValues, sessionContext));
+      }
+  }
 
 }
\ No newline at end of file



Mime
View raw message