Issue Details (XML | Word | Printable)

Key: CONFIGURATION-287
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Oliver Heger
Reporter: Ruben Silva
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Commons Configuration

XMLConfiguration.addNodes() problem using other configuration Nodes

Created: 26/Jul/07 02:05 PM   Updated: 22/Aug/09 07:36 PM
Return to search
Component/s: None
Affects Version/s: 1.4
Fix Version/s: 1.5

Time Tracking:
Not Specified

Resolution Date: 26/Jul/07 08:17 PM


 Description  « Hide
Trying to use the method XMLConfiguration.addNodes() to add a tree of configuration properties to a node in other tree fails.

Example:

public static void main(String ...args){
try{ configDestination = new XMLConfiguration("output.xml"); configSource = new XMLConfiguration("input.xml"); }
catch(ConfigurationException cex){ System.out.println("File not found"); }
Collection collection = new ArrayList();
collection = configSource.getRoot().getChildren();
configDestination.addNodes("newNodes", collection);
try { configDestination.save(); } catch (ConfigurationException e) { System.out.println("Error saving"); }
}

The XML files:

input.xml

<rootNode>
<newNodeChild>
<newNodeChildChild>child value</newNodeChildChild>
<newNodeChildChild>child value 2</newNodeChildChild>
<newNodeChildChild>child value 3</newNodeChildChild>
</newNodeChild>
</rootNode>

output.xml

<testRootNode>
<test>TEST</test>
</testRootNode>

output.xml after running the code:

<testRootNode>
<test>TEST</test>
<newNodes/>
</testRootNode>

Expected output.xml:

<testRootNode>
<test>TEST</test>
<newNodes>
<newNodeChild>
<newNodeChildChild>child value</newNodeChildChild>
<newNodeChildChild>child value 2</newNodeChildChild>
<newNodeChildChild>child value 3</newNodeChildChild>
</newNodeChild>
<newNodes/>
</testRootNode>

Apparently "the copied nodes still contain a reference to their old configuration (because you directly fetched them from the root node of the source configuration). Because of this reference they are not detected as new nodes when the destination configuration is saved, and hence not written to disk.

I think addNodes() should reset this reference, so that the added nodes can be detected as new nodes. (But then you have to be aware that you break the source configuration because a node can only be contained in exactly one configuration.) "



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Oliver Heger made changes - 26/Jul/07 08:03 PM
Field Original Value New Value
Assignee Oliver Heger [ oliver.heger@t-online.de ]
Fix Version/s 1.5 [ 12312239 ]
Repository Revision Date User Message
ASF #559964 Thu Jul 26 20:10:36 UTC 2007 oheger CONFIGURATION-287: Reset the reference property of all nodes to be added in the HierarchicalConfiguration.addNodes() method
Files Changed
MODIFY /jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
MODIFY /jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
MODIFY /jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
MODIFY /jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java

Oliver Heger added a comment - 26/Jul/07 08:17 PM
HierarchicalConfiguration.addNodes() now resets the references of the added nodes. This allows XMLConfiguration to detect the affected nodes as new, and they are correctly saved. I also added a note to the Javadocs of addNodes() about directly copying nodes from one configuration to another one.

Oliver Heger made changes - 26/Jul/07 08:17 PM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Oliver Heger made changes - 22/Aug/09 07:36 PM
Status Resolved [ 5 ] Closed [ 6 ]