commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Heger (JIRA)" <>
Subject [jira] Commented: (CONFIGURATION-292) removeChild() doen't trigger auto saving
Date Fri, 07 Sep 2007 06:33:30 GMT


Oliver Heger commented on CONFIGURATION-292:

I am very reluctant to make the removeNode() method public and add the event for the following

- 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);
    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)";
      found = true;

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:
>             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.

View raw message