[
https://issues.apache.org/jira/browse/CONFIGURATION-292?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12525608
]
Oliver Heger commented on CONFIGURATION-292:
--------------------------------------------
I am very reluctant to make the removeNode() method public and add the event
for the following reasons:
- This would add a new method to the public API of HierarchicalConfiguration
with a semantic that somewhat conflicts with the clearProperty()/clearTree()
methods.
- The method was originally intended to do some cleanup after a property was
deleted (to remove empty nodes without children). This is more an
implementation detail rather than a feature to be exposed.
- What would be the relation between an EVENT_REMOVE_NODE event and an
EVENT_CLEAR_PROPERTY? Would either event trigger the other one or not? For
event listeners it would be harder to properly react on these events.
Having said that, what other options are there to solve your problem. As I
understand it, you have a parent node and want to remove some of its children
matching a certain condition. You could do the following:
- Use the XPathExpressionEngine. Here you can use the full power of XPath to
specify your condition when defining the key for clearProperty() or clearTree().
- Construct the keys on your own using indices. This could look roughly like
the following pseudo code:
ConfigurationNode parent = ...
String parentKey = ...
boolean found = false;
do {
for(Iterator it = parent.getChildren(); it.hasNext()) {
ConfigurationNode node = (ConfigurationNode) it.next();
if(node meets my condition) {
// construct a key for the first node with this name by using index 0
String nodeKey = parentKey + "." + node.getName() + "(0)";
config.clearTree(nodeKey);
found = true;
break;
}
}while(found);
Here you create unambiguous keys for every single node to be removed.
Does this help you?
> removeChild() doen't trigger auto saving
> ----------------------------------------
>
> Key: CONFIGURATION-292
> URL: https://issues.apache.org/jira/browse/CONFIGURATION-292
> Project: Commons Configuration
> Issue Type: Bug
> Affects Versions: 1.4
> Environment: I am using Nightly build dated July 19, 2007
> Reporter: irina fridkina
> Fix For: 2.0
>
>
> When I remove nodes from the XMLConfiguration with autoSave enabled the file
> doesn't change. Here is an example
> XMLConfiguration config = new XMLConfiguration("c:\\conf.xml");
> config.setAutoSave(true) ;
> ConfigurationNode parentNode = config.getRootNode();
> parentNode.removeChild(childName);
> config.xml didn't change to reflect the changes
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.