commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1578573 - 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 Mon, 17 Mar 2014 21:07:53 GMT
Author: oheger
Date: Mon Mar 17 21:07:53 2014
New Revision: 1578573

URL: http://svn.apache.org/r1578573
Log:
Added a method for querying a node handler for a tracked node to InMemoryNodeModel.

This functionality is needed for operating on sub trees of the model.

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=1578573&r1=1578572&r2=1578573&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
Mon Mar 17 21:07:53 2014
@@ -412,6 +412,30 @@ public class InMemoryNodeModel implement
     }
 
     /**
+     * Returns a {@code NodeHandler} for a tracked node. Such a handler may be
+     * required for operations on a sub tree of the model. The handler to be
+     * returned depends on the current state of the tracked node. If it is still
+     * active, a handler is used which shares some data (especially the parent
+     * mapping) with this model. Detached track nodes in contrast have their own
+     * separate model; in this case a handler associated with this model is
+     * returned.
+     *
+     * @param selector the {@code NodeSelector} defining the tracked node
+     * @return a {@code NodeHandler} for this tracked node
+     * @throws ConfigurationRuntimeException if the selector is unknown
+     */
+    public NodeHandler<ImmutableNode> getTrackedNodeHandler(
+            NodeSelector selector)
+    {
+        TreeData currentData = structure.get();
+        InMemoryNodeModel detachedNodeModel =
+                currentData.getNodeTracker().getDetachedNodeModel(selector);
+        return (detachedNodeModel != null) ? detachedNodeModel.getNodeHandler()
+                : new TrackedNodeHandler(currentData.getNodeTracker()
+                        .getTrackedNode(selector), currentData);
+    }
+
+    /**
      * Returns a flag whether the specified tracked node is detached. As long as
      * the {@code NodeSelector} associated with that node returns a single
      * instance, the tracked node is said to be <em>life</em>. If now an update

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=1578573&r1=1578572&r2=1578573&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
Mon Mar 17 21:07:53 2014
@@ -19,6 +19,7 @@ package org.apache.commons.configuration
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -655,4 +656,41 @@ public class TestInMemoryNodeModelTracke
         assertEquals("Name was changed", "table", node.getNodeName());
         assertFalse("Node is defined", model.getNodeHandler().isDefined(node));
     }
+
+    /**
+     * Tests whether a node handler for a tracked node can be queried which is
+     * still active.
+     */
+    @Test
+    public void testGetTrackedNodeHandlerActive()
+    {
+        NodeKeyResolver<ImmutableNode> resolver = createResolver();
+        model.trackNode(selector, resolver);
+        NodeHandler<ImmutableNode> handler =
+                model.getTrackedNodeHandler(selector);
+        assertTrue("Wrong node handler: " + handler,
+                handler instanceof TrackedNodeHandler);
+        assertSame("Wrong root node", model.getTrackedNode(selector),
+                handler.getRootNode());
+        TrackedNodeHandler tnh = (TrackedNodeHandler) handler;
+        assertSame("Wrong parent handler", model.getTreeData(),
+                tnh.getParentHandler());
+    }
+
+    /**
+     * Tests whether a node handler for a detached tracked node can be queried.
+     */
+    @Test
+    public void testGetTrackedNodeHandlerDetached()
+    {
+        NodeKeyResolver<ImmutableNode> resolver = createResolver();
+        model.trackNode(selector, resolver);
+        initDetachedNode(resolver);
+        NodeHandler<ImmutableNode> handler =
+                model.getTrackedNodeHandler(selector);
+        assertSame("Wrong root node", model.getTrackedNode(selector),
+                handler.getRootNode());
+        assertTrue("Wrong handler: " + handler, handler instanceof TreeData);
+        assertNotSame("Shared handler", model.getNodeHandler(), handler);
+    }
 }



Mime
View raw message