You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2009/10/27 22:31:23 UTC
svn commit: r830349 - in
/commons/proper/configuration/branches/configuration2_experimental/src:
main/java/org/apache/commons/configuration2/base/
test/java/org/apache/commons/configuration2/base/
Author: oheger
Date: Tue Oct 27 21:31:21 2009
New Revision: 830349
URL: http://svn.apache.org/viewvc?rev=830349&view=rev
Log:
Ported changes from the flat package to the flat node classes in base: the internal update flag was moved from the node handler to the flat root node.
Modified:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatLeafNode.java
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNode.java
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNodeHandler.java
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNodeSourceAdapter.java
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatRootNode.java
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodeHandler.java
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodes.java
Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatLeafNode.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatLeafNode.java?rev=830349&r1=830348&r2=830349&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatLeafNode.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatLeafNode.java Tue Oct 27 21:31:21 2009
@@ -260,4 +260,28 @@
{
return getParent().getConfigurationSource();
}
+
+ /**
+ * 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/base/FlatNode.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNode.java?rev=830349&r1=830348&r2=830349&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNode.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNode.java Tue Oct 27 21:31:21 2009
@@ -167,4 +167,30 @@
* @return the owning {@code FlatConfigurationSource}
*/
public abstract FlatConfigurationSource getConfigurationSource();
+
+ /**
+ * Returns the internal update flag. This flag is set by the node handler
+ * whenever a change at the node structure affects the associated
+ * configuration source. When the configuration source receives a change
+ * event it queries this flag. The result of this method determines whether
+ * the configuration source'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 source 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/base/FlatNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNodeHandler.java?rev=830349&r1=830348&r2=830349&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNodeHandler.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNodeHandler.java Tue Oct 27 21:31:21 2009
@@ -58,30 +58,6 @@
class FlatNodeHandler extends AbstractNodeHandler<FlatNode>
{
/**
- * 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 {@code
- * ConfigurationSource} was caused by this node handler. Whenever the
- * {@code ConfigurationSource} adapter receives a change event, it asks the
- * node hander whether it is responsible for this event. The result of this
- * method determines whether the adapter'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 {@code ConfigurationSource} 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.
*
@@ -236,14 +212,14 @@
*/
public void removeChild(FlatNode node, FlatNode child)
{
- internalUpdate = true;
+ setInternalUpdate(node, true);
try
{
node.removeChild(child);
}
finally
{
- internalUpdate = false;
+ setInternalUpdate(node, false);
}
}
@@ -271,14 +247,27 @@
*/
public void setValue(FlatNode node, Object value)
{
- internalUpdate = true;
+ setInternalUpdate(node, true);
try
{
node.setValue(value);
}
finally
{
- internalUpdate = false;
+ setInternalUpdate(node, false);
}
}
+
+ /**
+ * Sets the internal update flag of the specified node. This method is
+ * called if a change on the node structure is performed that affects the
+ * associated configuration source.
+ *
+ * @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/base/FlatNodeSourceAdapter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNodeSourceAdapter.java?rev=830349&r1=830348&r2=830349&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNodeSourceAdapter.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatNodeSourceAdapter.java Tue Oct 27 21:31:21 2009
@@ -102,7 +102,7 @@
*/
public void configurationSourceChanged(ConfigurationSourceEvent event)
{
- if (!event.isBeforeUpdate() && !nodeHandler.isInternalUpdate())
+ if (!event.isBeforeUpdate() && !isInternalUpdate())
{
invalidateRootNode();
}
@@ -234,4 +234,16 @@
{
root = null;
}
+
+ /**
+ * Returns a flag whether the latest change on this configuration source 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 root != null && root.isInternalUpdate();
+ }
}
Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatRootNode.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatRootNode.java?rev=830349&r1=830348&r2=830349&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatRootNode.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/FlatRootNode.java Tue Oct 27 21:31:21 2009
@@ -65,6 +65,12 @@
private final FlatConfigurationSource configurationSource;
/**
+ * A flag whether an update of the configuration source was caused by an
+ * operation on its node structure.
+ */
+ private boolean internalUpdate;
+
+ /**
* Creates a new instance of {@code FlatRootNode} and initializes it with
* the {@code FlatConfigurationSource} it belongs to.
* @param source the owning {@code FlatConfigurationSource}
@@ -273,6 +279,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/base/TestFlatNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodeHandler.java?rev=830349&r1=830348&r2=830349&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodeHandler.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodeHandler.java Tue Oct 27 21:31:21 2009
@@ -47,7 +47,7 @@
private static final String NAME = "testProperty";
/** The node handler to be tested. */
- private FlatNodeHandler handler;
+ private FlatNodeHandlerTestImpl handler;
/** The configuration source associated with the node handler. */
private FlatConfigurationSource source;
@@ -71,7 +71,7 @@
internalUpdate = handler.isInternalUpdate();
}
});
- handler = new FlatNodeHandler();
+ handler = new FlatNodeHandlerTestImpl();
}
/**
@@ -327,4 +327,29 @@
{
handler.setAttributeValue(setUpTestNode(), "attr", "test");
}
+
+ /**
+ * 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/base/TestFlatNodes.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodes.java?rev=830349&r1=830348&r2=830349&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodes.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodes.java Tue Oct 27 21:31:21 2009
@@ -609,4 +609,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());
+ }
}