commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Heger (JIRA)" <j...@apache.org>
Subject [jira] Resolved: (CONFIGURATION-287) XMLConfiguration.addNodes() problem using other configuration Nodes
Date Thu, 26 Jul 2007 20:18:04 GMT

     [ https://issues.apache.org/jira/browse/CONFIGURATION-287?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Oliver Heger resolved CONFIGURATION-287.
----------------------------------------

    Resolution: Fixed

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.

> XMLConfiguration.addNodes() problem using other configuration Nodes
> -------------------------------------------------------------------
>
>                 Key: CONFIGURATION-287
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-287
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Ruben Silva
>            Assignee: Oliver Heger
>             Fix For: 1.5
>
>
> 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.) " 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message