commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1575768 - in /commons/proper/configuration/branches/immutableNodes/src: main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModelTrackedNodes.java
Date Sun, 09 Mar 2014 21:05:09 GMT
Author: oheger
Date: Sun Mar  9 21:05:08 2014
New Revision: 1575768

URL: http://svn.apache.org/r1575768
Log:
InMemoryNodeModel now supports addNodes() on a tracked node.

The implementation is analogous to other operations on tracked nodes.

Modified:
    commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java
    commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModelTrackedNodes.java

Modified: commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java?rev=1575768&r1=1575767&r2=1575768&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java
Sun Mar  9 21:05:08 2014
@@ -140,7 +140,27 @@ public class InMemoryNodeModel implement
         }
     }
 
-    public void addNodes(final String key,
+    public void addNodes(String key, Collection<? extends ImmutableNode> nodes,
+            NodeKeyResolver<ImmutableNode> resolver)
+    {
+        addNodes(key, null, nodes, resolver);
+    }
+
+    /**
+     * Adds new nodes using a tracked node as root node. This method works like
+     * the normal {@code addNodes()} method, but the origin of the operation
+     * (also for the interpretation of the passed in key) is a tracked node
+     * identified by the passed in {@code NodeSelector}. The selector can be
+     * <b>null</b>, then the root node is assumed.
+     *
+     * @param key the key
+     * @param selector the {@code NodeSelector} defining the root node (or
+     *        <b>null</b>)
+     * @param nodes the collection of new nodes to be added
+     * @param resolver the {@code NodeKeyResolver}
+     * @throws ConfigurationRuntimeException if the selector cannot be resolved
+     */
+    public void addNodes(final String key, NodeSelector selector,
             final Collection<? extends ImmutableNode> nodes,
             final NodeKeyResolver<ImmutableNode> resolver)
     {
@@ -151,8 +171,8 @@ public class InMemoryNodeModel implement
                 public boolean initTransaction(ModelTransaction tx)
                 {
                     List<QueryResult<ImmutableNode>> results =
-                            resolver.resolveKey(tx.getCurrentData().getRootNode(),
-                                    key, tx.getCurrentData());
+                            resolver.resolveKey(tx.getQueryRoot(), key,
+                                    tx.getCurrentData());
                     if (results.size() == 1)
                     {
                         if (results.get(0).isAttributeResult())
@@ -164,8 +184,8 @@ public class InMemoryNodeModel implement
                     else
                     {
                         NodeAddData<ImmutableNode> addData =
-                                resolver.resolveAddKey(tx.getCurrentData()
-                                        .getRootNode(), key, tx.getCurrentData());
+                                resolver.resolveAddKey(tx.getQueryRoot(), key,
+                                        tx.getCurrentData());
                         if (addData.isAttribute())
                         {
                             throw attributeKeyException(key);
@@ -179,7 +199,7 @@ public class InMemoryNodeModel implement
                     }
                     return true;
                 }
-            }, null, resolver);
+            }, selector, resolver);
         }
     }
 

Modified: commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModelTrackedNodes.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModelTrackedNodes.java?rev=1575768&r1=1575767&r2=1575768&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModelTrackedNodes.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModelTrackedNodes.java
Sun Mar  9 21:05:08 2014
@@ -498,4 +498,40 @@ public class TestInMemoryNodeModelTracke
         assertSame("Root node was changed", rootNode, model.getRootNode());
         checkForAddedField(fieldsNodeFromTrackedNode());
     }
+
+    /**
+     * Tests whether an addNodes() operation works on a tracked node.
+     */
+    @Test
+    public void testAddNodesOnTrackedNode()
+    {
+        NodeKeyResolver<ImmutableNode> resolver = createResolver(false);
+        prepareResolverForAddKeys(resolver);
+        EasyMock.replay(resolver);
+        model.trackNode(selector, resolver);
+        model.addNodes("fields", selector, Collections
+                .singleton(NodeStructureHelper.createFieldNode(NEW_FIELD)),
+                resolver);
+        checkForAddedField(fieldsNodeFromModel());
+        checkForAddedField(fieldsNodeFromTrackedNode());
+    }
+
+    /**
+     * Tests an addNodes() operation on a tracked node that is detached.
+     */
+    @Test
+    public void testAddNodesOnDetachedNode()
+    {
+        NodeKeyResolver<ImmutableNode> resolver = createResolver(false);
+        prepareResolverForAddKeys(resolver);
+        EasyMock.replay(resolver);
+        model.trackNode(selector, resolver);
+        initDetachedNode(resolver);
+        ImmutableNode rootNode = model.getRootNode();
+        model.addNodes("fields", selector, Collections
+                .singleton(NodeStructureHelper.createFieldNode(NEW_FIELD)),
+                resolver);
+        assertSame("Root node was changed", rootNode, model.getRootNode());
+        checkForAddedField(fieldsNodeFromTrackedNode());
+    }
 }



Mime
View raw message