commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r829654 - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/flat/ test/java/org/apache/commons/configuration2/flat/
Date Sun, 25 Oct 2009 21:18:53 GMT
Author: oheger
Date: Sun Oct 25 21:18:52 2009
New Revision: 829654

URL: http://svn.apache.org/viewvc?rev=829654&view=rev
Log:
Moved internal update flag from FlagNodeHandler to FlatRootNode.

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/AbstractFlatConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatLeafNode.java
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNode.java
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNodeHandler.java
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatRootNode.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodeHandler.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodes.java

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/AbstractFlatConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/AbstractFlatConfiguration.java?rev=829654&r1=829653&r2=829654&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/AbstractFlatConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/AbstractFlatConfiguration.java
Sun Oct 25 21:18:52 2009
@@ -267,6 +267,18 @@
     }
 
     /**
+     * Returns a flag whether the latest change on this configuration was caused
+     * by a manipulation of the associated flat node structure. If this is the
+     * case, the node structure need not be invalidated.
+     *
+     * @return the internal update flag
+     */
+    private boolean isInternalUpdate()
+    {
+        return rootNode != null && rootNode.isInternalUpdate();
+    }
+
+    /**
      * Registers a change listener at this configuration that causes the node
      * structure to be invalidated whenever the content is changed.
      */
@@ -283,7 +295,7 @@
             {
                 if (!event.isBeforeUpdate())
                 {
-                    if (!((FlatNodeHandler) getNodeHandler()).isInternalUpdate())
+                    if (!isInternalUpdate())
                     {
                         invalidateRootNode();
                     }

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatLeafNode.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatLeafNode.java?rev=829654&r1=829653&r2=829654&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatLeafNode.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatLeafNode.java
Sun Oct 25 21:18:52 2009
@@ -261,4 +261,28 @@
     {
         return getParent().getConfiguration();
     }
+
+    /**
+     * Returns the internal update flag. This implementation delegates to the
+     * parent node, which maintains the internal update flag.
+     *
+     * @return the internal update flag
+     */
+    @Override
+    public boolean isInternalUpdate()
+    {
+        return getParent().isInternalUpdate();
+    }
+
+    /**
+     * Sets the internal update flag. This implementation delegates to the
+     * parent node, which maintains the internal update flag.
+     *
+     * @param update the new value of the flag
+     */
+    @Override
+    public void setInternalUpdate(boolean update)
+    {
+        getParent().setInternalUpdate(update);
+    }
 }

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNode.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNode.java?rev=829654&r1=829653&r2=829654&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNode.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNode.java
Sun Oct 25 21:18:52 2009
@@ -163,4 +163,29 @@
      * @return the owning {@code Configuration}
      */
     public abstract Configuration getConfiguration();
+
+    /**
+     * Returns the internal update flag. This flag is set by the node handler
+     * whenever a change at the node structure affects the associated
+     * configuration. When the configuration receives a change event it queries
+     * this flag. The result of this method determines whether the
+     * configuration's node structure has to be invalidated: if the event was
+     * caused by the node handler, the structure has already been updated and
+     * there is no need to invalidate it. Otherwise the configuration was
+     * directly manipulated, and the node structure is now out of sync.
+     *
+     * @return a flag whether the last update was caused by a manipulation of
+     *         the node structure
+     */
+    public abstract boolean isInternalUpdate();
+
+    /**
+     * Sets the internal update flag. This method is called by the node handler
+     * to indicate that a change event was caused by a change of the flat node
+     * structure.
+     *
+     * @param update the update flag
+     * @see #isInternalUpdate()
+     */
+    public abstract void setInternalUpdate(boolean update);
 }

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNodeHandler.java?rev=829654&r1=829653&r2=829654&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNodeHandler.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatNodeHandler.java
Sun Oct 25 21:18:52 2009
@@ -65,29 +65,6 @@
     private NodeHandlerRegistry nodeHandlerRegistry;
 
     /**
-     * A flag whether an update of the configuration was caused by an operation
-     * on its node structure.
-     */
-    private boolean internalUpdate;
-
-    /**
-     * Returns a flag whether an update of the associated configuration was
-     * caused by this node handler. Whenever the configuration receives a change
-     * event, it asks the node hander whether it is responsible for this event.
-     * The result of this method determines whether the configuration's node
-     * structure has to be invalidated: if the event was caused by the node
-     * handler, the structure has already been updated and there is no need to
-     * invalidate it. Otherwise the configuration was directly manipulated, and
-     * the node structure is now out of sync.
-     *
-     * @return a flag whether an internal update was caused by this node handler
-     */
-    public boolean isInternalUpdate()
-    {
-        return internalUpdate;
-    }
-
-    /**
      * Adds an attribute to the specified node. Flat nodes do not support
      * attributes, so this implementation just throws an exception.
      *
@@ -241,14 +218,14 @@
      */
     public void removeChild(FlatNode node, FlatNode child)
     {
-        internalUpdate = true;
+        setInternalUpdate(node, true);
         try
         {
             node.removeChild(child);
         }
         finally
         {
-            internalUpdate = false;
+            setInternalUpdate(node, false);
         }
     }
 
@@ -276,14 +253,14 @@
      */
     public void setValue(FlatNode node, Object value)
     {
-        internalUpdate = true;
+        setInternalUpdate(node, true);
         try
         {
             node.setValue(value);
         }
         finally
         {
-            internalUpdate = false;
+            setInternalUpdate(node, false);
         }
     }
 
@@ -344,4 +321,17 @@
             }
         });
     }
+
+    /**
+     * Sets the internal update flag of the specified node. This method is if a
+     * change on the node structure is performed that affects the associated
+     * configuration.
+     *
+     * @param node the flat node affected by the change
+     * @param f the value of the internal update flag
+     */
+    void setInternalUpdate(FlatNode node, boolean f)
+    {
+        node.setInternalUpdate(f);
+    }
 }

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatRootNode.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatRootNode.java?rev=829654&r1=829653&r2=829654&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatRootNode.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/FlatRootNode.java
Sun Oct 25 21:18:52 2009
@@ -65,6 +65,12 @@
     private final Configuration configuration;
 
     /**
+     * A flag whether an update of the configuration was caused by an operation
+     * on its node structure.
+     */
+    private boolean internalUpdate;
+
+    /**
      * Creates a new instance of {@code FlatRootNode}. The {@code Configuration}
      * the node belongs to must be passed in.
      *
@@ -276,6 +282,29 @@
     }
 
     /**
+     * Returns the internal update flag. The root node of the flat node
+     * structure maintains this flag as a member field.
+     *
+     * @return the internal update flag
+     */
+    @Override
+    public boolean isInternalUpdate()
+    {
+        return internalUpdate;
+    }
+
+    /**
+     * Sets the internal update flag.
+     *
+     * @param update the value of the update flag
+     */
+    @Override
+    public void setInternalUpdate(boolean update)
+    {
+        internalUpdate = update;
+    }
+
+    /**
      * Returns the value index for the specified child node. This method is used
      * to determine the index of the value of a property with multiple values
      * that corresponds to the given child node. It counts the occurrences of

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodeHandler.java?rev=829654&r1=829653&r2=829654&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodeHandler.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodeHandler.java
Sun Oct 25 21:18:52 2009
@@ -43,7 +43,7 @@
     private static final String NAME = "testProperty";
 
     /** The node handler to be tested. */
-    private FlatNodeHandler handler;
+    private FlatNodeHandlerTestImpl handler;
 
     /** The mock configuration associated with the node handler. */
     private AbstractConfiguration config;
@@ -67,7 +67,7 @@
                 internalUpdate = handler.isInternalUpdate();
             }
         });
-        handler = new FlatNodeHandler();
+        handler = new FlatNodeHandlerTestImpl();
     }
 
     /**
@@ -323,4 +323,29 @@
             // ok
         }
     }
+
+    /**
+     * A test flat node handler implementation. It is used mainly for checking
+     * the internal update flag.
+     */
+    private static class FlatNodeHandlerTestImpl extends FlatNodeHandler
+    {
+        /** Stores the internal update flag. */
+        private boolean internalUpdate;
+
+        public boolean isInternalUpdate()
+        {
+            return internalUpdate;
+        }
+
+        /**
+         * Records this invocation and stores the value of the flag.
+         */
+        @Override
+        void setInternalUpdate(FlatNode node, boolean f)
+        {
+            internalUpdate = f;
+            super.setInternalUpdate(node, f);
+        }
+    }
 }

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodes.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodes.java?rev=829654&r1=829653&r2=829654&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodes.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodes.java
Sun Oct 25 21:18:52 2009
@@ -640,4 +640,31 @@
     {
         parent.setValue(VALUE);
     }
+
+    /**
+     * Tests the implementation of isInternalUpdate() in the root node.
+     */
+    @Test
+    public void testIsInternalUpdateRoot()
+    {
+        assertFalse("Already an internal update", parent.isInternalUpdate());
+        parent.setInternalUpdate(true);
+        assertTrue("No internal update", parent.isInternalUpdate());
+        parent.setInternalUpdate(false);
+        assertFalse("Still internal update", parent.isInternalUpdate());
+    }
+
+    /**
+     * Tests the implementation of isInternalUpdate() in the leaf node.
+     */
+    @Test
+    public void testIsInternalUpdateLeaf()
+    {
+        assertFalse("Already an internal update", node.isInternalUpdate());
+        node.setInternalUpdate(true);
+        assertTrue("No internal update", node.isInternalUpdate());
+        assertTrue("No internal update in root", parent.isInternalUpdate());
+        parent.setInternalUpdate(false);
+        assertFalse("Still internal update", node.isInternalUpdate());
+    }
 }



Mime
View raw message