jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1446483 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: NodeDelegate.java NodeImpl.java
Date Fri, 15 Feb 2013 09:17:42 GMT
Author: angela
Date: Fri Feb 15 09:17:42 2013
New Revision: 1446483

URL: http://svn.apache.org/r1446483
Log:
OAK-612 : Calling addNode on a node that has orderable child nodes violates specification
(follow-up on OAK-626)

Modified:
    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/NodeImpl.java

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=1446483&r1=1446482&r2=1446483&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
Fri Feb 15 09:17:42 2013
@@ -47,14 +47,15 @@ public class NodeDelegate extends ItemDe
     /**
      * Create a new {@code NodeDelegate} instance for a valid {@code TreeLocation}. That
      * is for one where {@code getTree() != null}.
+     *
      * @param sessionDelegate
      * @param location
      * @return
      */
     static NodeDelegate create(SessionDelegate sessionDelegate, TreeLocation location) {
         return location.getTree() == null
-            ? null
-            : new NodeDelegate(sessionDelegate, location);
+                ? null
+                : new NodeDelegate(sessionDelegate, location);
     }
 
     protected NodeDelegate(SessionDelegate sessionDelegate, Tree tree) {
@@ -72,7 +73,8 @@ public class NodeDelegate extends ItemDe
 
     /**
      * Determine whether this is the root node
-     * @return  {@code true} iff this is the root node
+     *
+     * @return {@code true} iff this is the root node
      */
     public boolean isRoot() throws InvalidItemStateException {
         return getTree().isRoot();
@@ -80,7 +82,8 @@ public class NodeDelegate extends ItemDe
 
     /**
      * Get the number of properties of the node
-     * @return  number of properties of the node
+     *
+     * @return number of properties of the node
      */
     public long getPropertyCount() throws InvalidItemStateException {
         // TODO: Exclude "invisible" internal properties (OAK-182)
@@ -89,9 +92,10 @@ public class NodeDelegate extends ItemDe
 
     /**
      * Get a property
-     * @param relPath  oak path
-     * @return  property at the path given by {@code relPath} or {@code null} if
-     * no such property exists
+     *
+     * @param relPath oak path
+     * @return property at the path given by {@code relPath} or {@code null} if
+     *         no such property exists
      */
     @CheckForNull
     public PropertyDelegate getProperty(String relPath) throws RepositoryException {
@@ -104,7 +108,8 @@ public class NodeDelegate extends ItemDe
 
     /**
      * Get the properties of the node
-     * @return  properties of the node
+     *
+     * @return properties of the node
      */
     @Nonnull
     public Iterator<PropertyDelegate> getProperties() throws InvalidItemStateException
{
@@ -113,7 +118,8 @@ public class NodeDelegate extends ItemDe
 
     /**
      * Get the number of child nodes
-     * @return  number of child nodes of the node
+     *
+     * @return number of child nodes of the node
      */
     public long getChildCount() throws InvalidItemStateException {
         // TODO: Exclude "invisible" internal child nodes (OAK-182)
@@ -122,9 +128,10 @@ public class NodeDelegate extends ItemDe
 
     /**
      * Get child node
-     * @param relPath  oak path
-     * @return  node at the path given by {@code relPath} or {@code null} if
-     * no such node exists
+     *
+     * @param relPath oak path
+     * @return node at the path given by {@code relPath} or {@code null} if
+     *         no such node exists
      */
     @CheckForNull
     public NodeDelegate getChild(String relPath) throws RepositoryException {
@@ -173,9 +180,10 @@ public class NodeDelegate extends ItemDe
 
     /**
      * Set a property
+     *
      * @param name  oak name
      * @param value
-     * @return  the set property
+     * @return the set property
      */
     @Nonnull
     public PropertyDelegate setProperty(String name, Value value) throws RepositoryException
{
@@ -194,15 +202,16 @@ public class NodeDelegate extends ItemDe
 
     /**
      * Set a multi valued property
-     * @param name  oak name
+     *
+     * @param name   oak name
      * @param values
-     * @return  the set property
+     * @return the set property
      */
     @Nonnull
     public PropertyDelegate setProperty(String name, Iterable<Value> values) throws
RepositoryException {
         Tree tree = getTree();
         PropertyState old = tree.getProperty(name);
-        if (old != null && ! old.isArray()) {
+        if (old != null && !old.isArray()) {
             throw new ValueFormatException("Attempt to set multiple values to single valued
property.");
         }
         tree.setProperty(PropertyStates.createProperty(name, values));
@@ -211,15 +220,16 @@ public class NodeDelegate extends ItemDe
 
     /**
      * Add a child node
-     * @param name  oak name
-     * @return  the added node or {@code null} if such a node already exists
+     *
+     * @param name oak name
+     * @return the added node or {@code null} if such a node already exists
      */
     @CheckForNull
     public NodeDelegate addChild(String name) throws InvalidItemStateException {
         Tree tree = getTree();
         return tree.hasChild(name)
-            ? null
-            : new NodeDelegate(sessionDelegate, tree.addChild(name));
+                ? null
+                : new NodeDelegate(sessionDelegate, tree.addChild(name));
     }
 
     /**
@@ -229,6 +239,16 @@ public class NodeDelegate extends ItemDe
         getTree().remove();
     }
 
+    /**
+     * Enables or disabled orderable children on the underlying tree.
+     *
+     * @param enable whether to enable or disable orderable children.
+     */
+    public void setOrderableChildren(boolean enable)
+            throws InvalidItemStateException {
+        getTree().setOrderableChildren(enable);
+    }
+
     //------------------------------------------------------------< internal >---
 
     @Nonnull

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1446483&r1=1446482&r2=1446483&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Fri Feb 15 09:17:42 2013
@@ -86,7 +86,7 @@ import static javax.jcr.Property.JCR_LOC
 
 /**
  * TODO document
- * 
+ *
  * @param <T> the delegate type
  */
 public class NodeImpl<T extends NodeDelegate> extends ItemImpl<T> implements
Node {
@@ -146,8 +146,7 @@ public class NodeImpl<T extends NodeDele
                     return !dlg.isStale() && dlg.getStatus() == Status.NEW;
                 }
             });
-        }
-        catch (RepositoryException e) {
+        } catch (RepositoryException e) {
             return false;
         }
     }
@@ -164,8 +163,7 @@ public class NodeImpl<T extends NodeDele
                     return !dlg.isStale() && dlg.getStatus() == Status.MODIFIED;
                 }
             });
-        }
-        catch (RepositoryException e) {
+        } catch (RepositoryException e) {
             return false;
         }
     }
@@ -201,6 +199,7 @@ public class NodeImpl<T extends NodeDele
     }
 
     //---------------------------------------------------------------< Node >---
+
     /**
      * @see Node#addNode(String)
      */
@@ -275,7 +274,7 @@ public class NodeImpl<T extends NodeDele
                 }
 
                 if (getPrimaryNodeType().hasOrderableChildNodes()) {
-                    dlg.orderBefore(oakName, null);
+                    dlg.setOrderableChildren(true);
                 }
 
                 NodeImpl<?> childNode = new NodeImpl<NodeDelegate>(added);
@@ -748,14 +747,14 @@ public class NodeImpl<T extends NodeDele
 
                 Set<String> propertyOakPaths = idManager.getReferences(weak, dlg.getTree(),
name);
                 Iterable<Property> properties = Iterables.transform(
-                    propertyOakPaths,
-                    new Function<String, Property>() {
-                        @Override
-                        public Property apply(String oakPath) {
-                            PropertyDelegate pd = sessionDelegate.getProperty(oakPath);
-                            return pd == null ? null : new PropertyImpl(pd);
+                        propertyOakPaths,
+                        new Function<String, Property>() {
+                            @Override
+                            public Property apply(String oakPath) {
+                                PropertyDelegate pd = sessionDelegate.getProperty(oakPath);
+                                return pd == null ? null : new PropertyImpl(pd);
+                            }
                         }
-                    }
                 );
 
                 return new PropertyIteratorAdapter(properties.iterator(), propertyOakPaths.size());
@@ -1440,16 +1439,7 @@ public class NodeImpl<T extends NodeDele
                 Value value = sessionDelegate.getValueFactory().createValue(nodeTypeName,
PropertyType.NAME);
                 dlg.setProperty(jcrPrimaryType, value);
 
-                if (nt.hasOrderableChildNodes()) {
-                    // freeze child order with a call to orderBefore()
-                    // only makes sense with a least two child nodes
-                    Iterator<NodeDelegate> children = dlg.getChildren();
-                    NodeDelegate child1 = children.hasNext() ? children.next() : null;
-                    NodeDelegate child2 = children.hasNext() ? children.next() : null;
-                    if (child1 != null && child2 != null) {
-                        dlg.orderBefore(child1.getName(), child2.getName());
-                    }
-                }
+                dlg.setOrderableChildren(nt.hasOrderableChildNodes());
 
                 return null;
             }



Mime
View raw message