You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Moein Enayati <mo...@gmail.com> on 2011/02/12 15:58:22 UTC

[configuration] How to edit a bean using apache.commons.configuration ....

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

Re: [configuration] How to edit a bean using apache.commons.configuration ....

Posted by Moein Enayati <mo...@gmail.com>.
Dear Ralph & Oliver

thank you both
I will try them on.

Moein.

Re: [configuration] How to edit a bean using apache.commons.configuration ....

Posted by Oliver Heger <ol...@oliver-heger.de>.
Am 13.02.2011 17:13, schrieb Ralph Goers:
> Commons Configuration isn't meant to be a bean entity framework but a way for applications to access configuration data. Therefore it doesn't follow normal Java bean semantics.  Although you could probably make it function as one I'd be surprised if it would be nearly as efficient as some of the true Java Bean frameworks.  http://java-source.net/open-source/xml-parsers has a decent list of various tools you could use to do this.
>
> Ralph

I fully agree with Ralph. There are specialized solutions for bean 
persistence which are more appropriate for your use case. If you are on 
Java 1.6, you have built in support for JAXB [1] which might be an 
option, too.

Oliver

[1] 
http://download.oracle.com/javase/6/docs/technotes/guides/xml/jaxb/index.html

>
> On Feb 12, 2011, at 9:35 PM, Moein Enayati wrote:
>
>> Dear Oliver
>>
>> Thanks a lot for your nicely reply.
>> but you know , I was thinking of a service approach in which I have an
>> entity(bean) which stored in XML file and by request , I load it into a
>> bean-object and give it to the client (another module) and after all changes
>> applied of the bean-object , I save it in it's corresponding location in xml
>> file.
>>
>> is there any way to do so , or is it a correct approach of using
>> configuration entities?
>>
>> thanks again / Moein
>>
>>
>>
>> On Sat, Feb 12, 2011 at 7:07 PM, Oliver Heger
>> <ol...@oliver-heger.de>wrote:
>>
>>> 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-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: user-help@commons.apache.org
>>>
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>


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


Re: [configuration] How to edit a bean using apache.commons.configuration ....

Posted by Ralph Goers <ra...@dslextreme.com>.
Commons Configuration isn't meant to be a bean entity framework but a way for applications to access configuration data. Therefore it doesn't follow normal Java bean semantics.  Although you could probably make it function as one I'd be surprised if it would be nearly as efficient as some of the true Java Bean frameworks.  http://java-source.net/open-source/xml-parsers has a decent list of various tools you could use to do this.

Ralph

On Feb 12, 2011, at 9:35 PM, Moein Enayati wrote:

> Dear Oliver
> 
> Thanks a lot for your nicely reply.
> but you know , I was thinking of a service approach in which I have an
> entity(bean) which stored in XML file and by request , I load it into a
> bean-object and give it to the client (another module) and after all changes
> applied of the bean-object , I save it in it's corresponding location in xml
> file.
> 
> is there any way to do so , or is it a correct approach of using
> configuration entities?
> 
> thanks again / Moein
> 
> 
> 
> On Sat, Feb 12, 2011 at 7:07 PM, Oliver Heger
> <ol...@oliver-heger.de>wrote:
> 
>> 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-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>> 
>> 


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


Re: [configuration] How to edit a bean using apache.commons.configuration ....

Posted by Moein Enayati <mo...@gmail.com>.
Dear Oliver

Thanks a lot for your nicely reply.
but you know , I was thinking of a service approach in which I have an
entity(bean) which stored in XML file and by request , I load it into a
bean-object and give it to the client (another module) and after all changes
applied of the bean-object , I save it in it's corresponding location in xml
file.

is there any way to do so , or is it a correct approach of using
configuration entities?

thanks again / Moein



On Sat, Feb 12, 2011 at 7:07 PM, Oliver Heger
<ol...@oliver-heger.de>wrote:

> 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-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: [configuration] How to edit a bean using apache.commons.configuration ....

Posted by Oliver Heger <ol...@oliver-heger.de>.
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-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org