Hi,

Am 12.02.2011 15:58, schrieb Moein Enayati:
Dear all

I'm newly familiar with apache.commons and wondering of having an
XML-Preferences file for my java applicaiton . till know I found
apache.commons.configuration so useful in set/getproperties and also in
getting a saved bean from xml resource.
but I need to load a bean and apply user changes on it and save it again in
its previous location in xml file.

would you please help me is there any way to do so ?

thanks/Moein


with "bean" you mean the bean declarations as described in the user's guide [1] I assume.

Well, basically a bean declaration is no different from normal properties defined in the XML document. This means you can use setProperty() with the corresponding keys to alter parts of the declaration.

Take the following example from the user's guide:

<config>
  <gui>
    <windowManager config-class="examples.windows.DefaultWindowManager"
      closable="false" resizable="true" defaultWidth="400"
      defaultHeight="250">
<styleDefinition config-class="examples.windows.WindowStyleDefinition"
        backColor="#ffffff" foreColor="0080ff" iconName="myicon" />
    </windowManager>
  </gui>
</config>

If you want to change the backColor property of the style definition of the window manager bean, you could use the following call:

config.setProperty("gui.windowManager.styleDefinition[@backColor]",
    "#0000ff");

Oliver

[1] http://commons.apache.org/configuration/userguide/howto_beans.html#Declaring_and_Creating_Beans

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org

Reply via email to