commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1580044 - in /commons/proper/configuration/branches/immutableNodes/src: main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java
Date Fri, 21 Mar 2014 20:37:30 GMT
Author: oheger
Date: Fri Mar 21 20:37:29 2014
New Revision: 1580044

URL: http://svn.apache.org/r1580044
Log:
Implemented configurationsAt(String, boolean) in BaseHierarchicalConfiguration.

Modified:
    commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
    commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java

Modified: commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java?rev=1580044&r1=1580043&r2=1580044&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
Fri Mar 21 20:37:29 2014
@@ -278,9 +278,23 @@ public class BaseHierarchicalConfigurati
         InMemoryNodeModel myModel = getSubConfigurationParentModel();
         NodeSelector selector = getSubConfigurationNodeSelector(key);
         myModel.trackNode(selector, this);
+        return createSubConfigurationForTrackedNode(selector, myModel);
+    }
+
+    /**
+     * Creates a connected sub configuration based on a selector for a tracked
+     * node.
+     *
+     * @param selector the {@code NodeSelector}
+     * @param parentModel the parent node model
+     * @return the newly created sub configuration
+     */
+    private SubnodeConfiguration createSubConfigurationForTrackedNode(
+            NodeSelector selector, InMemoryNodeModel parentModel)
+    {
         SubnodeConfiguration subConfig =
-                new SubnodeConfiguration(this, new TrackedNodeModel(myModel,
-                        selector, true));
+                new SubnodeConfiguration(this, new TrackedNodeModel(
+                        parentModel, selector, true));
         subConfig.addConfigurationListener(changeListener);
         return subConfig;
     }
@@ -392,6 +406,32 @@ public class BaseHierarchicalConfigurati
     }
 
     /**
+     * {@inheritDoc} This implementation creates tracked nodes for the specified
+     * key. Then sub configurations for these nodes are created and returned.
+     */
+    public List<HierarchicalConfiguration<ImmutableNode>> configurationsAt(
+            String key, boolean supportUpdates)
+    {
+        if (!supportUpdates)
+        {
+            return configurationsAt(key);
+        }
+
+        InMemoryNodeModel parentModel = getSubConfigurationParentModel();
+        Collection<NodeSelector> selectors =
+                parentModel.selectAndTrackNodes(key, this);
+        List<HierarchicalConfiguration<ImmutableNode>> configs =
+                new ArrayList<HierarchicalConfiguration<ImmutableNode>>(
+                        selectors.size());
+        for (NodeSelector selector : selectors)
+        {
+            configs.add(createSubConfigurationForTrackedNode(selector,
+                    parentModel));
+        }
+        return configs;
+    }
+
+    /**
      * {@inheritDoc} This implementation first delegates to
      * {@code configurationsAt()} to create a list of
      * {@code SubnodeConfiguration} objects. Then for each element of this list
@@ -429,6 +469,10 @@ public class BaseHierarchicalConfigurati
         return subs;
     }
 
+    public List<HierarchicalConfiguration<ImmutableNode>> childConfigurationsAt(String
key, boolean supportUpdates) {
+        return null;
+    }
+
     /**
      * {@inheritDoc} This implementation first delegates to
      * {@code childConfigurationsAt()} to create a list of mutable child

Modified: commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java?rev=1580044&r1=1580043&r2=1580044&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestHierarchicalConfiguration.java
Fri Mar 21 20:37:29 2014
@@ -40,6 +40,9 @@ import org.junit.Test;
  */
 public class TestHierarchicalConfiguration
 {
+    /** Constant for a changed name. */
+    private static final String NEW_NAME = "alteredName";
+
     /** The configuration to be tested. */
     private BaseHierarchicalConfiguration config;
 
@@ -374,14 +377,42 @@ public class TestHierarchicalConfigurati
     }
 
     /**
-     * Tests the configurationsAt() method.
+     * Helper method for checking a configurationsAt() method. It is also tested
+     * whether the configuration is connected to its parent.
+     *
+     * @param withUpdates the updates flag
+     * @param expName the expected name in the parent configuration
      */
-    @Test
-    public void testConfigurationsAt()
+    private void checkConfigurationsAtWithUpdate(boolean withUpdates,
+            String expName)
     {
+        String key = "tables.table(1).fields.field";
         List<HierarchicalConfiguration<ImmutableNode>> lstFlds =
-                config.configurationsAt("tables.table(1).fields.field");
+                withUpdates ? config.configurationsAt(key, true) : config
+                        .configurationsAt(key);
         checkSubConfigurations(lstFlds);
+        lstFlds.get(0).setProperty("name", NEW_NAME);
+        assertEquals("Wrong name in parent", expName,
+                config.getString("tables.table(1).fields.field(0).name"));
+    }
+
+    /**
+     * Tests the configurationsAt() method if the sub configurations are not
+     * connected..
+     */
+    @Test
+    public void testConfigurationsAtNoUpdate()
+    {
+        checkConfigurationsAtWithUpdate(false, NodeStructureHelper.field(1, 0));
+    }
+
+    /**
+     * Tests configurationsAt() if the sub configurations are connected.
+     */
+    @Test
+    public void testConfigurationsAtWithUpdates()
+    {
+        checkConfigurationsAtWithUpdate(true, NEW_NAME);
     }
 
     /**



Mime
View raw message