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 2014/04/13 18:01:48 UTC
svn commit: r1587016 -
/commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.java
Author: oheger
Date: Sun Apr 13 16:01:48 2014
New Revision: 1587016
URL: http://svn.apache.org/r1587016
Log:
Fixed test case for the copy constructor.
It is necessary to invoke beginRead() on the configuration to be copied.
Otherwise, the combined configuration does not get constructed.
Modified:
commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/BaseHierarchicalConfiguration.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=1587016&r1=1587015&r2=1587016&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:01:48 2014
@@ -648,11 +648,39 @@ public class BaseHierarchicalConfigurati
private static NodeModel<ImmutableNode> createNodeModel(
HierarchicalConfiguration<ImmutableNode> c)
{
- ImmutableNode root = (c != null) ? c.getRootNode() : null;
+ ImmutableNode root = (c != null) ? obtainRootNode(c) : null;
return new InMemoryNodeModel(root);
}
/**
+ * Obtains the root node from a configuration whose data is to be copied. It
+ * has to be ensured that the synchronizer is called correctly.
+ *
+ * @param c the configuration that is to be copied
+ * @return the root node of this configuration
+ */
+ private static ImmutableNode obtainRootNode(
+ HierarchicalConfiguration<ImmutableNode> c)
+ {
+ boolean needSynchronization = c instanceof AbstractConfiguration;
+ if (needSynchronization)
+ {
+ ((AbstractConfiguration) c).beginRead(false);
+ }
+ try
+ {
+ return c.getRootNode();
+ }
+ finally
+ {
+ if (needSynchronization)
+ {
+ ((AbstractConfiguration) c).endRead();
+ }
+ }
+ }
+
+ /**
* A specialized visitor base class that can be used for storing the tree of
* configuration nodes. The basic idea is that each node can be associated
* with a reference object. This reference object has a concrete meaning in