You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Oliver Heger <Ol...@t-online.de> on 2004/10/09 11:46:06 UTC
Re:[configuration] Question on save configuration using commons-configuration
Hello Tao,
there have recently been a couple of changes in [commons-configuration]
related to a consistent handling of load() and save() methods across
file based configuration classes. Some of the problems you encountered
are probably caused by bugs that have been corrected in the mean time.
So first of all you should update to the latest version, which is RC 2.
To your first experiment: You are correct that CompositeConfiguration
concentrates on gathering configuration sources, but does not have much
support for saving. A workaround is to cast the Configuration object
returned by ConfigurationFactory to a CompositeConfiguration and
directly to access the Configuration objects contained in the composite
(using the getConfiguration(int index) method), cast them to the correct
sub type and then call their save() methods. This should work.
To your second experiment: I am a bit confused because
HierarchicalXMLConfiguration does not provide a save() method at the
moment. Do you mean XMLConfiguration? Well, the FileNotFoundException
thrown by save() methods of XMLConfiguration were caused by a bug that
has been fixed. So an update to the newest version will probaby help.
For HierarchicalXMLConfiguration I have written a patch that implements
a save() method, but that has not been applied yet.
I hope I could help you. The official place for obtaining information
about Jakarta commons components and putting questions is the commons
user mailing list (which I have CCed). You should subscribe at this
list. Maybe there are further replies to this posting.
Oliver
Tao Wang wrote:
>Dear Mr. Heger:
>
>My name is Tao Wang. I am trying to use commons-configuration to load and update XML configuration data. I got some problems when trying to save configuration. I can't find good examples over the Internet. I found your name inside the javadoc, and wondering if you don't mind give me some help or sample code for me to follow.
>
>Basically, I did two experiments. First, I created a parent xml file that includes two configuration xml files. I created a Configuration using ConfigurationFactory, which returns a reference to Configuration. Reading the configuration data has no problem. But I can't save it, because the save() method is not defined in Configuration interface. Do I have to cast the reference to a child class that has save methods? In addition, since I load the data from two different xml files, I don't know how data can be saved into right files. Is that possible? If so, how?
>
>My second experiment is to directly use HierarchicalXMLConfiguration class to load one configuration xml file. I have no problem to load the data. But I still can't call any of the save() methods. I got exception indicating that the file is not found. But I load the file successfully! If I tried to save it to another file, the exception said that it can't save to the file without giving a reason, though the file is actually created. Could you probably show me how to do the saving with HierarchicalXMLConfiguration class?
>
>Your generous care and help would be greatly appreciated!
>
>Best Regards,
>
>Tao Wang
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org