commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1587026 - in /commons/proper/configuration/branches/immutableNodes/src: main/java/org/apache/commons/configuration/ main/java/org/apache/commons/configuration/tree/ test/java/org/apache/commons/configuration/ test/java/org/apache/commons/c...
Date Sun, 13 Apr 2014 16:07:07 GMT
Author: oheger
Date: Sun Apr 13 16:07:07 2014
New Revision: 1587026

URL: http://svn.apache.org/r1587026
Log:
TrackedNodeModel now requires an InMemoryNodeModelSupport object.

Access to the underlying model is now indirect. This caused some adaptations in
multiple hierarchical configuration classes. Because access to the model is
now guarded by the Synchronizer the remaining failing test for
CombinedConfiguration is running now.

Modified:
    commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
    commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/INIConfiguration.java
    commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/SubnodeConfiguration.java
    commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/TrackedNodeModel.java
    commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestSubnodeConfiguration.java
    commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestTrackedNodeModel.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=1587026&r1=1587025&r2=1587026&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
Sun Apr 13 16:07:07 2014
@@ -32,6 +32,7 @@ import org.apache.commons.configuration.
 import org.apache.commons.configuration.tree.ConfigurationNodeVisitorAdapter;
 import org.apache.commons.configuration.tree.ImmutableNode;
 import org.apache.commons.configuration.tree.InMemoryNodeModel;
+import org.apache.commons.configuration.tree.InMemoryNodeModelSupport;
 import org.apache.commons.configuration.tree.NodeHandler;
 import org.apache.commons.configuration.tree.NodeModel;
 import org.apache.commons.configuration.tree.NodeSelector;
@@ -48,7 +49,7 @@ import org.apache.commons.configuration.
  * @version $Id$
  */
 public class BaseHierarchicalConfiguration extends AbstractHierarchicalConfiguration<ImmutableNode>
-    implements Serializable, Cloneable
+    implements Serializable, Cloneable, InMemoryNodeModelSupport
 {
     /**
      * Constant for the subnode configuration modified event.
@@ -99,6 +100,16 @@ public class BaseHierarchicalConfigurati
     }
 
     /**
+     * {@inheritDoc} This implementation returns the {@code InMemoryNodeModel}
+     * used by this configuration.
+     */
+    @Override
+    public InMemoryNodeModel getNodeModel()
+    {
+        return (InMemoryNodeModel) super.getNodeModel();
+    }
+
+    /**
      * Creates a new {@code Configuration} object containing all keys
      * that start with the specified prefix. This implementation will return a
      * {@code BaseHierarchicalConfiguration} object so that the structure of
@@ -262,6 +273,7 @@ public class BaseHierarchicalConfigurati
      *
      * @param key the key of the sub configuration
      * @return a {@code NodeSelector} for initializing a sub configuration
+     * @since 2.0
      */
     protected NodeSelector getSubConfigurationNodeSelector(String key)
     {
@@ -273,16 +285,17 @@ public class BaseHierarchicalConfigurati
      * node.
      *
      * @param selector the {@code NodeSelector}
-     * @param parentModel the parent node model
+     * @param parentModelSupport the {@code InMemoryNodeModelSupport} object for
+     *        the parent node model
      * @return the newly created sub configuration
      * @since 2.0
      */
     protected SubnodeConfiguration createSubConfigurationForTrackedNode(
-            NodeSelector selector, InMemoryNodeModel parentModel)
+            NodeSelector selector, InMemoryNodeModelSupport parentModelSupport)
     {
         SubnodeConfiguration subConfig =
                 new SubnodeConfiguration(this, new TrackedNodeModel(
-                        parentModel, selector, true));
+                        parentModelSupport, selector, true));
         initSubConfigurationForThisParent(subConfig);
         return subConfig;
     }
@@ -314,22 +327,22 @@ public class BaseHierarchicalConfigurati
     private BaseHierarchicalConfiguration createConnectedSubConfiguration(
             String key)
     {
-        InMemoryNodeModel myModel = getSubConfigurationParentModel();
         NodeSelector selector = getSubConfigurationNodeSelector(key);
-        myModel.trackNode(selector, this);
-        return createSubConfigurationForTrackedNode(selector, myModel);
+        getSubConfigurationParentModel().trackNode(selector, this);
+        return createSubConfigurationForTrackedNode(selector, this);
     }
 
     /**
      * Creates a list of connected sub configurations based on a passed in list
      * of node selectors.
      *
-     * @param parentModel the parent node model
+     * @param parentModelSupport the parent node model support object
      * @param selectors the list of {@code NodeSelector} objects
      * @return the list with sub configurations
      */
     private List<HierarchicalConfiguration<ImmutableNode>> createConnectedSubConfigurations(
-            InMemoryNodeModel parentModel, Collection<NodeSelector> selectors)
+            InMemoryNodeModelSupport parentModelSupport,
+            Collection<NodeSelector> selectors)
     {
         List<HierarchicalConfiguration<ImmutableNode>> configs =
                 new ArrayList<HierarchicalConfiguration<ImmutableNode>>(
@@ -337,7 +350,7 @@ public class BaseHierarchicalConfigurati
         for (NodeSelector selector : selectors)
         {
             configs.add(createSubConfigurationForTrackedNode(selector,
-                    parentModel));
+                    parentModelSupport));
         }
         return configs;
     }
@@ -486,7 +499,7 @@ public class BaseHierarchicalConfigurati
 
         Collection<NodeSelector> selectors =
                 parentModel.selectAndTrackNodes(key, this);
-        return createConnectedSubConfigurations(parentModel, selectors);
+        return createConnectedSubConfigurations(this, selectors);
     }
 
     /**
@@ -542,7 +555,7 @@ public class BaseHierarchicalConfigurati
         }
 
         InMemoryNodeModel parentModel = getSubConfigurationParentModel();
-        return createConnectedSubConfigurations(parentModel,
+        return createConnectedSubConfigurations(this,
                 parentModel.trackChildNodes(key, this));
     }
 

Modified: commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/INIConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/INIConfiguration.java?rev=1587026&r1=1587025&r2=1587026&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/INIConfiguration.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/INIConfiguration.java
Sun Apr 13 16:07:07 2014
@@ -35,6 +35,7 @@ import org.apache.commons.configuration.
 import org.apache.commons.configuration.ex.ConfigurationRuntimeException;
 import org.apache.commons.configuration.tree.ImmutableNode;
 import org.apache.commons.configuration.tree.InMemoryNodeModel;
+import org.apache.commons.configuration.tree.InMemoryNodeModelSupport;
 import org.apache.commons.configuration.tree.NodeHandler;
 import org.apache.commons.configuration.tree.NodeHandlerDecorator;
 import org.apache.commons.configuration.tree.NodeSelector;
@@ -853,7 +854,7 @@ public class INIConfiguration extends Ba
                 // obtain the node for the section, create it on demand
                 InMemoryNodeModel parentModel = getSubConfigurationParentModel();
                 NodeSelector selector = parentModel.trackChildNodeWithCreation(null, name,
this);
-                return createSubConfigurationForTrackedNode(selector, parentModel);
+                return createSubConfigurationForTrackedNode(selector, this);
             }
         }
     }
@@ -869,7 +870,8 @@ public class INIConfiguration extends Ba
         InMemoryNodeModel parentModel = getSubConfigurationParentModel();
         NodeSelector selector = new NodeSelector(null); // selects parent
         parentModel.trackNode(selector, this);
-        GlobalSectionNodeModel model = new GlobalSectionNodeModel(parentModel, selector);
+        GlobalSectionNodeModel model =
+                new GlobalSectionNodeModel(this, selector);
         SubnodeConfiguration sub = new SubnodeConfiguration(this, model);
         initSubConfigurationForThisParent(sub);
         return sub;
@@ -899,13 +901,13 @@ public class INIConfiguration extends Ba
          * Creates a new instance of {@code GlobalSectionNodeModel} and
          * initializes it with the given underlying model.
          *
-         * @param model the underlying {@code InMemoryNodeModel}
+         * @param modelSupport the underlying {@code InMemoryNodeModel}
          * @param selector the {@code NodeSelector}
          */
-        public GlobalSectionNodeModel(InMemoryNodeModel model,
+        public GlobalSectionNodeModel(InMemoryNodeModelSupport modelSupport,
                 NodeSelector selector)
         {
-            super(model, selector, true);
+            super(modelSupport, selector, true);
         }
 
         @Override

Modified: commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/SubnodeConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/SubnodeConfiguration.java?rev=1587026&r1=1587025&r2=1587026&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/SubnodeConfiguration.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/SubnodeConfiguration.java
Sun Apr 13 16:07:07 2014
@@ -179,6 +179,17 @@ public class SubnodeConfiguration extend
     }
 
     /**
+     * {@inheritDoc} This implementation returns the node model of the parent
+     * configuration. This is necessary because this sub configuration does not
+     * have an {@code InMemoryNodeModel} object.
+     */
+    @Override
+    public InMemoryNodeModel getNodeModel()
+    {
+        return getParent().getNodeModel();
+    }
+
+    /**
      * {@inheritDoc} This implementation returns a copy of the current node
      * model with the same settings. However, it has to be ensured that the
      * track count for the node selector is increased.
@@ -191,7 +202,7 @@ public class SubnodeConfiguration extend
         InMemoryNodeModel parentModel =
                 (InMemoryNodeModel) getParent().getModel();
         parentModel.trackNode(getRootSelector(), getParent());
-        return new TrackedNodeModel(parentModel, getRootSelector(), true);
+        return new TrackedNodeModel(getParent(), getRootSelector(), true);
     }
 
     /**

Modified: commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/TrackedNodeModel.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/TrackedNodeModel.java?rev=1587026&r1=1587025&r2=1587026&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/TrackedNodeModel.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/TrackedNodeModel.java
Sun Apr 13 16:07:07 2014
@@ -29,14 +29,21 @@ import java.util.concurrent.atomic.Atomi
  * structure. This is the case for instance for a {@code SubnodeConfiguration}.
  * </p>
  * <p>
- * An instance of this class is constructed with a reference to the underlying
- * {@code InMemoryNodeModel} and the {@link NodeSelector} pointing to the
- * tracked node acting as this model's root node. The {@code NodeModel}
+ * An instance of this class is constructed with an
+ * {@link InMemoryNodeModelSupport} object providing a reference to the
+ * underlying {@code InMemoryNodeModel} and the {@link NodeSelector} pointing to
+ * the tracked node acting as this model's root node. The {@code NodeModel}
  * operations are implemented by delegating to the wrapped
  * {@code InMemoryNodeModel} object specifying the selector to the tracked node
  * as target root node for the update transaction. Note that the tracked node
  * can become detached at any time. This situation is handled transparently by
- * the implementation of {@code InMemoryNodeModel}.
+ * the implementation of {@code InMemoryNodeModel}. The reason for using an
+ * {@code InMemoryNodeModelSupport} object rather than an
+ * {@code InMemoryNodeModel} directly is that this additional layer of
+ * indirection can be used for performing special initializations on the model
+ * before it is returned to the {@code TrackedNodeModel} object. This is needed
+ * by some dynamic configuration implementations, e.g. by
+ * {@code CombinedConfiguration}.
  * </p>
  * <p>
  * If the tracked node acting as root node is exclusively used by this model, it
@@ -56,7 +63,7 @@ import java.util.concurrent.atomic.Atomi
 public class TrackedNodeModel implements NodeModel<ImmutableNode>
 {
     /** Stores the underlying parent model. */
-    private final InMemoryNodeModel parentModel;
+    private final InMemoryNodeModelSupport parentModelSupport;
 
     /** The selector for the managed tracked node. */
     private final NodeSelector selector;
@@ -80,7 +87,7 @@ public class TrackedNodeModel implements
      * model explicitly. Therefore, it makes sense to do this automatically on
      * finalization.
      *
-     * @param model the underlying {@code InMemoryNodeModel} (must not be
+     * @param modelSupport the underlying {@code InMemoryNodeModelSupport} (must not be
      *        <b>null</b>)
      * @param sel the selector to the root node of this model (must not be
      *        <b>null</b>)
@@ -88,26 +95,37 @@ public class TrackedNodeModel implements
      *        released on finalization
      * @throws IllegalArgumentException if a required parameter is missing
      */
-    public TrackedNodeModel(InMemoryNodeModel model, NodeSelector sel,
+    public TrackedNodeModel(InMemoryNodeModelSupport modelSupport, NodeSelector sel,
             boolean untrackOnFinalize)
     {
-        if (model == null)
+        if (modelSupport == null)
         {
             throw new IllegalArgumentException(
-                    "Underlying model must not be null!");
+                    "Underlying model support must not be null!");
         }
         if (sel == null)
         {
             throw new IllegalArgumentException("Selector must not be null!");
         }
 
-        parentModel = model;
+        parentModelSupport = modelSupport;
         selector = sel;
         releaseTrackedNodeOnFinalize = untrackOnFinalize;
         closed = new AtomicBoolean();
     }
 
     /**
+     * Returns the {@code InMemoryNodeModelSupport} object which is used to gain
+     * access to the underlying node model.
+     *
+     * @return the associated {@code InMemoryNodeModelSupport} object
+     */
+    public InMemoryNodeModelSupport getParentModelSupport()
+    {
+        return parentModelSupport;
+    }
+
+    /**
      * Returns the parent model. Operations on this model are delegated to this
      * parent model specifying the selector to the tracked node.
      *
@@ -115,7 +133,7 @@ public class TrackedNodeModel implements
      */
     public InMemoryNodeModel getParentModel()
     {
-        return parentModel;
+        return getParentModelSupport().getNodeModel();
     }
 
     /**

Modified: commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestSubnodeConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestSubnodeConfiguration.java?rev=1587026&r1=1587025&r2=1587026&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestSubnodeConfiguration.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestSubnodeConfiguration.java
Sun Apr 13 16:07:07 2014
@@ -122,7 +122,7 @@ public class TestSubnodeConfiguration
     {
         InMemoryNodeModel parentModel = (InMemoryNodeModel) parent.getModel();
         parentModel.trackNode(selector, parent);
-        return new TrackedNodeModel(parentModel, selector, true);
+        return new TrackedNodeModel(parent, selector, true);
     }
 
     /**

Modified: commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestTrackedNodeModel.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestTrackedNodeModel.java?rev=1587026&r1=1587025&r2=1587026&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestTrackedNodeModel.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestTrackedNodeModel.java
Sun Apr 13 16:07:07 2014
@@ -45,6 +45,9 @@ public class TestTrackedNodeModel
     /** A mock for the underlying node model. */
     private InMemoryNodeModel parentModel;
 
+    /** A mock for the support object that provides the model. */
+    private InMemoryNodeModelSupport modelSupport;
+
     @BeforeClass
     public static void setUpBeforeClass() throws Exception
     {
@@ -60,6 +63,10 @@ public class TestTrackedNodeModel
     public void setUp() throws Exception
     {
         parentModel = EasyMock.createMock(InMemoryNodeModel.class);
+        modelSupport = EasyMock.createMock(InMemoryNodeModelSupport.class);
+        EasyMock.expect(modelSupport.getNodeModel()).andReturn(parentModel)
+                .anyTimes();
+        EasyMock.replay(modelSupport);
     }
 
     /**
@@ -69,7 +76,7 @@ public class TestTrackedNodeModel
      */
     private TrackedNodeModel setUpModel()
     {
-        return new TrackedNodeModel(parentModel, selector, true);
+        return new TrackedNodeModel(modelSupport, selector, true);
     }
 
     /**
@@ -78,7 +85,7 @@ public class TestTrackedNodeModel
     @Test(expected = IllegalArgumentException.class)
     public void testInitNoSelector()
     {
-        new TrackedNodeModel(parentModel, null, true);
+        new TrackedNodeModel(modelSupport, null, true);
     }
 
     /**



Mime
View raw message