You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Greg Torrance <gr...@pobox.com> on 2016/11/13 14:07:28 UTC

[configuration] Combined Configuration examples

Hi all,

I am trying to work out the precise differences between 
OverrideCombiner, UnionCombiner, and MergeCombiner. However, the 
examples on this page 
(https://commons.apache.org/proper/commons-configuration/userguide/howto_combinedconfiguration.html) 
are confusing to me.

testfile1.xml and testfile2.xml both contain Channels with id="4", 
however none of the Combiner Results shows any Channels with id="4".  
And the Notes on the right-hand side of the page contain no mention of 
Channel 4.

Am I missing something? Are the examples correct?

What I'm really trying to understand is the impact of attributes in the 
way the various combiners choose to combine elements. (Any pointers to 
further documentation on this would be appreciated.)

Thoughts?

Thanks,
Greg


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


Re: [configuration] Custom variable interpolation

Posted by Greg Torrance <gr...@pobox.com>.
Hi Oliver,

Thanks for the info!

I created a ticket for the documentation inconsistency. I trust it's 
suitable.

    https://issues.apache.org/jira/browse/CONFIGURATION-643

Thanks,
Greg

On 11/23/2016 03:41 PM, Oliver Heger wrote:
> Hi Greg,
>
> Am 23.11.2016 um 00:50 schrieb Greg Torrance:
>> Hi all,
>>
>> I would like to implement a custom variable interpolator that is
>> specific to a Configuration object, but that also supports the standard
>> prefixes (sys, const, env).
>>
>> What I mean by "specific to a Configuration object" is that the custom
>> interpolator needs to know the Configuration to which it is associated
>> in order to produce a valid result for a variable.
>>
>> Say I want to associate a variable "rootDir" with the custom prefix
>> "myPrefix". To use this variable I would specify ${myPrefix:rootDir} in
>> my configuration file. At the code level, though, if I create a
>> Configuration config1, I want "rootDir" for that Configuration to
>> evaluate to "/abc/def". But for Configuration config2, "rootDir" should
>> evaluate to "/ghi/jkl". I assume I will need to have a specific Lookup
>> instance per Configuration, right?
>>
>> I have tried to understand how to do this based on this page
>> (https://commons.apache.org/proper/commons-configuration/userguide/howto_basicfeatures.html#Customizing_interpolation),
>> but the information seems to be a bit inaccurate based on v2.1. (For
>> example, it refers to calling the static registerGlobalLookup() method
>> on ConfigurationInterpolator, but this method does not appear to exist.)
> Could you please open a ticket in our bugtracking system [1] when you
> notice inconsistencies in the documentation, so that they can be fixed?
> Thanks in advance!
>
> [1]
> https://commons.apache.org/proper/commons-configuration/issue-tracking.html
>
>> Also, I'm not clear if I should be extending StrLookup, or implementing
>> Lookup. (I was initially using StrLookup, but the
>> ConfigurationInterpolator registerLookup() method requires a Lookup
>> instance.)
> StrLookup is from [lang], to avoid a direct dependency, [configuration]
> uses its own abstraction. But the Lookup interface is so simple that it
> can be easily implemented.
>
>> If I do the following, it seems to allow me create a working custom
>> interpolator. But when I do this, the standard prefixes (sys, const,
>> env) no longer work:
>>
>> ConfigurationInterpolator ci = new ConfigurationInterpolator();
>> ci.registerLookup("myPrefix", new MyLookup()); // implementation of
>> Lookup interface
>> config1.setInterpolator(ci);
> You can try the following:
> config1.getInterpolator().registerLookup( ... );
>
> This should add the new lookup to the existing ones.
>
> Oliver
>
>> Any thoughts on how to implement this using Commons Configuration best
>> practices?
>>
>> Thanks in advance,
>> Greg
>>
>> ---------------------------------------------------------------------
>> 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] Custom variable interpolation

Posted by Oliver Heger <ol...@oliver-heger.de>.
Hi Greg,

Am 23.11.2016 um 00:50 schrieb Greg Torrance:
> Hi all,
> 
> I would like to implement a custom variable interpolator that is
> specific to a Configuration object, but that also supports the standard
> prefixes (sys, const, env).
> 
> What I mean by "specific to a Configuration object" is that the custom
> interpolator needs to know the Configuration to which it is associated
> in order to produce a valid result for a variable.
> 
> Say I want to associate a variable "rootDir" with the custom prefix
> "myPrefix". To use this variable I would specify ${myPrefix:rootDir} in
> my configuration file. At the code level, though, if I create a
> Configuration config1, I want "rootDir" for that Configuration to
> evaluate to "/abc/def". But for Configuration config2, "rootDir" should
> evaluate to "/ghi/jkl". I assume I will need to have a specific Lookup
> instance per Configuration, right?
> 
> I have tried to understand how to do this based on this page
> (https://commons.apache.org/proper/commons-configuration/userguide/howto_basicfeatures.html#Customizing_interpolation),
> but the information seems to be a bit inaccurate based on v2.1. (For
> example, it refers to calling the static registerGlobalLookup() method
> on ConfigurationInterpolator, but this method does not appear to exist.)

Could you please open a ticket in our bugtracking system [1] when you
notice inconsistencies in the documentation, so that they can be fixed?
Thanks in advance!

[1]
https://commons.apache.org/proper/commons-configuration/issue-tracking.html

> 
> Also, I'm not clear if I should be extending StrLookup, or implementing
> Lookup. (I was initially using StrLookup, but the
> ConfigurationInterpolator registerLookup() method requires a Lookup
> instance.)

StrLookup is from [lang], to avoid a direct dependency, [configuration]
uses its own abstraction. But the Lookup interface is so simple that it
can be easily implemented.

> 
> If I do the following, it seems to allow me create a working custom
> interpolator. But when I do this, the standard prefixes (sys, const,
> env) no longer work:
> 
> ConfigurationInterpolator ci = new ConfigurationInterpolator();
> ci.registerLookup("myPrefix", new MyLookup()); // implementation of
> Lookup interface
> config1.setInterpolator(ci);

You can try the following:
config1.getInterpolator().registerLookup( ... );

This should add the new lookup to the existing ones.

Oliver

> 
> Any thoughts on how to implement this using Commons Configuration best
> practices?
> 
> Thanks in advance,
> Greg
> 
> ---------------------------------------------------------------------
> 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


[configuration] Custom variable interpolation

Posted by Greg Torrance <gr...@pobox.com>.
Hi all,

I would like to implement a custom variable interpolator that is 
specific to a Configuration object, but that also supports the standard 
prefixes (sys, const, env).

What I mean by "specific to a Configuration object" is that the custom 
interpolator needs to know the Configuration to which it is associated 
in order to produce a valid result for a variable.

Say I want to associate a variable "rootDir" with the custom prefix 
"myPrefix". To use this variable I would specify ${myPrefix:rootDir} in 
my configuration file. At the code level, though, if I create a 
Configuration config1, I want "rootDir" for that Configuration to 
evaluate to "/abc/def". But for Configuration config2, "rootDir" should 
evaluate to "/ghi/jkl". I assume I will need to have a specific Lookup 
instance per Configuration, right?

I have tried to understand how to do this based on this page 
(https://commons.apache.org/proper/commons-configuration/userguide/howto_basicfeatures.html#Customizing_interpolation), 
but the information seems to be a bit inaccurate based on v2.1. (For 
example, it refers to calling the static registerGlobalLookup() method 
on ConfigurationInterpolator, but this method does not appear to exist.)

Also, I'm not clear if I should be extending StrLookup, or implementing 
Lookup. (I was initially using StrLookup, but the 
ConfigurationInterpolator registerLookup() method requires a Lookup 
instance.)

If I do the following, it seems to allow me create a working custom 
interpolator. But when I do this, the standard prefixes (sys, const, 
env) no longer work:

ConfigurationInterpolator ci = new ConfigurationInterpolator();
ci.registerLookup("myPrefix", new MyLookup()); // implementation of 
Lookup interface
config1.setInterpolator(ci);

Any thoughts on how to implement this using Commons Configuration best 
practices?

Thanks in advance,
Greg

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


Re: [configuration] Combined Configuration examples

Posted by Aaron Gadberry <aa...@gadberry.com>.
Thanks Oliver!

On Mon, Nov 14, 2016 at 3:24 PM, Oliver Heger <ol...@oliver-heger.de>
wrote:

> Hi Aaron,
>
> Am 14.11.2016 um 18:38 schrieb Aaron Gadberry:
> > Hi All,
> >
> > A follow up question.  Is there a way to view the combined XML?  I am
> > constantly missing elements not knowing if it is my paths or my original
> > files or the combiner.
>
> what you could do is to copy the combined configuration into a
> XMLConfiguration and save this to a file. XMLConfiguration has a
> constructor that accepts a hierarchical configuration; so you pass in
> the combined configuration. Then the configuration can be saved to file
> or dumped to an output stream:
>
> XMLConfiguration copy = new XMLConfiguration(combined);
> FileHandler handler = new FileHandler(copy);
> handler.save(new File("target.xml"));
>
> Oliver
>
> >
> > Thanks,
> >
> >
> >
> > On Sun, Nov 13, 2016 at 2:54 PM, Greg Torrance <gr...@pobox.com>
> > wrote:
> >
> >> Thanks Oliver.
> >>
> >> I think I understand what you're saying about why Channel 4 would not be
> >> included with the OverrideCombiner (if it doesn't exist in
> testfile1.xml).
> >> I am sorry to hear, though, that attributes are not used at all for
> >> matching with OverrideCombiner. If I'm understanding it correctly, that
> >> means it can't really be used for overriding just specific list items,
> as
> >> the entire list would have to be represented, in the same order, in both
> >> primary and overriding files, or the wrong list item might be
> overridden.
> >> (For example, if the primary list had Channels 1, 2, and 3, and the
> >> override list had only Channel 2, then it would attempt to override
> Channel
> >> 1 with the info from Channel 2.) Is my understanding correct?
> >>
> >> Anyway, I'm going to experiment a bit and try to make sure I have a good
> >> understanding of how this works.
> >>
> >> Thanks again for the help.
> >>
> >> Greg
> >>
> >>
> >> On 11/13/2016 01:51 PM, Oliver Heger wrote:
> >>
> >>> Hi Greg,
> >>>
> >>> Am 13.11.2016 um 18:41 schrieb Greg Torrance:
> >>>
> >>>> Hi Oliver,
> >>>>
> >>>> Thanks for the reply. That is helpful!
> >>>>
> >>>> Hm, it looks as if the examples are partly incorrect. I assume that
> >>>>>
> >>>> the channel with id="4" should not be part of testfile1.xml, but only
> be
> >>>> contained in the second file. It should appear in the results of union
> >>>> and  merge combiner. Does that make sense?
> >>>>
> >>>> I'm not clear why -- if the channel with id="4" is not contained in
> >>>> testfile1.xml -- why it will not end up in the results from all three
> >>>> combiners. Why just union and merge and not override, too?
> >>>>
> >>> On a higher level, OverrideCombiner detects that both files have a list
> >>> of channels. Therefore, it copies the first list and ignores the second
> >>> one. So the channels element in the first file overrides the one in the
> >>> second file.
> >>>
> >>> As for the attributes, do I understand correctly that the attribute
> >>>> values for elements are used, essentially, as "key" values to
> >>>> distinguish the various elements for combining purposes? And if the
> >>>> values of any attributes of two elements differ, then the elements
> would
> >>>> be considered different elements for combining purposes? (Said another
> >>>> way, if two elements have a set of attributes in common, if the values
> >>>> for those common attributes are the same, the elements will be
> >>>> considered to match.) Does that make sense? Is that correct?
> >>>>
> >>> This is true only for MergeCombiner. The other combiners do not try to
> >>> match nodes in both configurations based on their attribute values;
> they
> >>> take two source nodes at the same position in the hierarchy and produce
> >>> a result node that has all the attributes of the two source nodes.
> >>>
> >>> Oliver
> >>>
> >>> Thanks again for the reply.
> >>>>
> >>>> Greg
> >>>>
> >>>> On 11/13/2016 12:05 PM, Oliver Heger wrote:
> >>>>
> >>>>> Hi Greg,
> >>>>>
> >>>>> Am 13.11.2016 um 15:07 schrieb Greg Torrance:
> >>>>>
> >>>>>> Hi all,
> >>>>>>
> >>>>>> I am trying to work out the precise differences between
> >>>>>> OverrideCombiner, UnionCombiner, and MergeCombiner. However, the
> >>>>>> examples on this page
> >>>>>> (https://commons.apache.org/proper/commons-configuration/use
> >>>>>> rguide/howto_combinedconfiguration.html)
> >>>>>>
> >>>>>> are confusing to me.
> >>>>>>
> >>>>>> testfile1.xml and testfile2.xml both contain Channels with id="4",
> >>>>>> however none of the Combiner Results shows any Channels with id="4".
> >>>>>> And the Notes on the right-hand side of the page contain no mention
> of
> >>>>>> Channel 4.
> >>>>>>
> >>>>>> Am I missing something? Are the examples correct?
> >>>>>>
> >>>>> Hm, it looks as if the examples are partly incorrect. I assume that
> the
> >>>>> channel with id="4" should not be part of testfile1.xml, but only be
> >>>>> contained in the second file. It should appear in the results of
> union
> >>>>> and merge combiner. Does that make sense?
> >>>>>
> >>>>> What I'm really trying to understand is the impact of attributes in
> the
> >>>>>> way the various combiners choose to combine elements. (Any pointers
> to
> >>>>>> further documentation on this would be appreciated.)
> >>>>>>
> >>>>> Some more information can be found in the Javadocs of the combiner
> >>>>> classes:
> >>>>> - UnionCombiner states: "Another limitation is the handling of
> >>>>> attributes: Attributes can only have a single value. So if two nodes
> are
> >>>>> to be combined which both have an attribute with the same name, it is
> >>>>> not possible to construct a proper union attribute. In this case, the
> >>>>> attribute value from the first node is used."
> >>>>>
> >>>>> - OverrideCombiner has an addAttributes() method with the following
> >>>>> documentation: "Handles the attributes during a combination process.
> >>>>> First all attributes of the first node are added to the result. Then
> all
> >>>>> attributes of the second node, which are not contained in the first
> >>>>> node, are also added."
> >>>>>
> >>>>> - The merging behavior of MergeCombiner is also described in its
> class
> >>>>> documentation.
> >>>>>
> >>>>> Does this help?
> >>>>> Oliver
> >>>>>
> >>>>> Thoughts?
> >>>>>>
> >>>>>> Thanks,
> >>>>>> Greg
> >>>>>>
> >>>>>>
> >>>>>> ------------------------------------------------------------
> ---------
> >>>>>> 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
> >>>>
> >>>> ---------------------------------------------------------------------
> >>> 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] Combined Configuration examples

Posted by Oliver Heger <ol...@oliver-heger.de>.
Hi Aaron,

Am 14.11.2016 um 18:38 schrieb Aaron Gadberry:
> Hi All,
> 
> A follow up question.  Is there a way to view the combined XML?  I am
> constantly missing elements not knowing if it is my paths or my original
> files or the combiner.

what you could do is to copy the combined configuration into a
XMLConfiguration and save this to a file. XMLConfiguration has a
constructor that accepts a hierarchical configuration; so you pass in
the combined configuration. Then the configuration can be saved to file
or dumped to an output stream:

XMLConfiguration copy = new XMLConfiguration(combined);
FileHandler handler = new FileHandler(copy);
handler.save(new File("target.xml"));

Oliver

> 
> Thanks,
> 
> 
> 
> On Sun, Nov 13, 2016 at 2:54 PM, Greg Torrance <gr...@pobox.com>
> wrote:
> 
>> Thanks Oliver.
>>
>> I think I understand what you're saying about why Channel 4 would not be
>> included with the OverrideCombiner (if it doesn't exist in testfile1.xml).
>> I am sorry to hear, though, that attributes are not used at all for
>> matching with OverrideCombiner. If I'm understanding it correctly, that
>> means it can't really be used for overriding just specific list items, as
>> the entire list would have to be represented, in the same order, in both
>> primary and overriding files, or the wrong list item might be overridden.
>> (For example, if the primary list had Channels 1, 2, and 3, and the
>> override list had only Channel 2, then it would attempt to override Channel
>> 1 with the info from Channel 2.) Is my understanding correct?
>>
>> Anyway, I'm going to experiment a bit and try to make sure I have a good
>> understanding of how this works.
>>
>> Thanks again for the help.
>>
>> Greg
>>
>>
>> On 11/13/2016 01:51 PM, Oliver Heger wrote:
>>
>>> Hi Greg,
>>>
>>> Am 13.11.2016 um 18:41 schrieb Greg Torrance:
>>>
>>>> Hi Oliver,
>>>>
>>>> Thanks for the reply. That is helpful!
>>>>
>>>> Hm, it looks as if the examples are partly incorrect. I assume that
>>>>>
>>>> the channel with id="4" should not be part of testfile1.xml, but only be
>>>> contained in the second file. It should appear in the results of union
>>>> and  merge combiner. Does that make sense?
>>>>
>>>> I'm not clear why -- if the channel with id="4" is not contained in
>>>> testfile1.xml -- why it will not end up in the results from all three
>>>> combiners. Why just union and merge and not override, too?
>>>>
>>> On a higher level, OverrideCombiner detects that both files have a list
>>> of channels. Therefore, it copies the first list and ignores the second
>>> one. So the channels element in the first file overrides the one in the
>>> second file.
>>>
>>> As for the attributes, do I understand correctly that the attribute
>>>> values for elements are used, essentially, as "key" values to
>>>> distinguish the various elements for combining purposes? And if the
>>>> values of any attributes of two elements differ, then the elements would
>>>> be considered different elements for combining purposes? (Said another
>>>> way, if two elements have a set of attributes in common, if the values
>>>> for those common attributes are the same, the elements will be
>>>> considered to match.) Does that make sense? Is that correct?
>>>>
>>> This is true only for MergeCombiner. The other combiners do not try to
>>> match nodes in both configurations based on their attribute values; they
>>> take two source nodes at the same position in the hierarchy and produce
>>> a result node that has all the attributes of the two source nodes.
>>>
>>> Oliver
>>>
>>> Thanks again for the reply.
>>>>
>>>> Greg
>>>>
>>>> On 11/13/2016 12:05 PM, Oliver Heger wrote:
>>>>
>>>>> Hi Greg,
>>>>>
>>>>> Am 13.11.2016 um 15:07 schrieb Greg Torrance:
>>>>>
>>>>>> Hi all,
>>>>>>
>>>>>> I am trying to work out the precise differences between
>>>>>> OverrideCombiner, UnionCombiner, and MergeCombiner. However, the
>>>>>> examples on this page
>>>>>> (https://commons.apache.org/proper/commons-configuration/use
>>>>>> rguide/howto_combinedconfiguration.html)
>>>>>>
>>>>>> are confusing to me.
>>>>>>
>>>>>> testfile1.xml and testfile2.xml both contain Channels with id="4",
>>>>>> however none of the Combiner Results shows any Channels with id="4".
>>>>>> And the Notes on the right-hand side of the page contain no mention of
>>>>>> Channel 4.
>>>>>>
>>>>>> Am I missing something? Are the examples correct?
>>>>>>
>>>>> Hm, it looks as if the examples are partly incorrect. I assume that the
>>>>> channel with id="4" should not be part of testfile1.xml, but only be
>>>>> contained in the second file. It should appear in the results of union
>>>>> and merge combiner. Does that make sense?
>>>>>
>>>>> What I'm really trying to understand is the impact of attributes in the
>>>>>> way the various combiners choose to combine elements. (Any pointers to
>>>>>> further documentation on this would be appreciated.)
>>>>>>
>>>>> Some more information can be found in the Javadocs of the combiner
>>>>> classes:
>>>>> - UnionCombiner states: "Another limitation is the handling of
>>>>> attributes: Attributes can only have a single value. So if two nodes are
>>>>> to be combined which both have an attribute with the same name, it is
>>>>> not possible to construct a proper union attribute. In this case, the
>>>>> attribute value from the first node is used."
>>>>>
>>>>> - OverrideCombiner has an addAttributes() method with the following
>>>>> documentation: "Handles the attributes during a combination process.
>>>>> First all attributes of the first node are added to the result. Then all
>>>>> attributes of the second node, which are not contained in the first
>>>>> node, are also added."
>>>>>
>>>>> - The merging behavior of MergeCombiner is also described in its class
>>>>> documentation.
>>>>>
>>>>> Does this help?
>>>>> Oliver
>>>>>
>>>>> Thoughts?
>>>>>>
>>>>>> Thanks,
>>>>>> Greg
>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> 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
>>>>
>>>> ---------------------------------------------------------------------
>>> 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] Character position of key in file

Posted by Greg Torrance <gr...@pobox.com>.
Thanks for the detailed suggestions, Oliver. I appreciate it. I'll dig 
around a bit and give it some thought; you've given me a good head start.

All the best,
Greg

On 11/15/2016 03:35 PM, Oliver Heger wrote:
> Hi Greg,
>
> Am 14.11.2016 um 22:34 schrieb Greg Torrance:
>> Thanks Oliver.
>>
>> Regarding the Configuration API, is it possible to replace not just
>> values but keys, too? For example, could I replace
>>
>> <ReplaceMe id="4"/>
>>
>> with
>>
>> <NewKey>
>>     <NewChildKey1>
>>        <NewChildKey2>Some Value</NewChildKey2>
>>     </NewChildKey1>
>> </NewKey>
>>
>> If so, can you suggest what class to look at first (for accomplishing
>> this)?
> This is indeed a tough one. There are multiple options, but I am not
> sure whether they fully cover your use case; you will certainly need
> some experiments:
>
> - With the high-level API (offered by Configuration) you can delete the
> key to be replaced and then use the addNodes() method to insert a nodes
> structure as replacement. The tricky part is to get the key for
> addNodes() right, so the replacement goes to the desired position. The
> configuration's expression engine may help you here. It has methods to
> query for keys (and receive matching node objects) and to obtain a
> canonical key for a given node.
>
> - You may also operate on the hierarchical configuration's node
> structure directly. The root node can be queried via the node model
> getNodeModel()). As this structure is immutable, you cannot directly
> change it, but you have to create a copy which might not be that efficient.
>
> - Unfortunately, XMLConfiguration has no direct hooks to manipulate the
> node creation process. There are some helper methods, but these are private.
>
> The use case is interesting. It would be good to offer some generic
> support for configuration pre-processing, independent on a concrete
> implementation. However, this is probably not easy to implement, and it
> may still be insufficient for specific use cases.
>
> Oliver
>
>> Thanks,
>> Greg
>>
>> On 11/14/2016 04:27 PM, Oliver Heger wrote:
>>> Hi Greg,
>>>
>>> Am 14.11.2016 um 19:01 schrieb Greg Torrance:
>>>> I hope I'm not asking too many questions...
>>>>
>>>> I wonder if it is possible to determine the character/byte position
>>>> of a particular key in a configuration file?
>>> No, the original position from where data is read is not stored in the
>>> resulting configuration.
>>>
>>>> My intent is to do a pre-pass of an XML configuration file in which
>>>> certain configuration keys/values are replaced by other keys/values.
>>>> Once that is done the file will be reloaded. I realize this is
>>>> possible outside of Commons Configuration, but I was wondering if
>>>> there is a "hook" in the tool that might help simplify the process.
>>>>
>>> But wouldn't it be easier to do this with the Configuration API? Load
>>> the configuration, iterate over its keys, replace data as appropriate
>>> and save the result?
>>>
>>> Oliver
>>>
>>>> Thanks,
>>>> Greg
>>>>
>>> ---------------------------------------------------------------------
>>> 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
>
>


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


Re: [configuration] Character position of key in file

Posted by Oliver Heger <ol...@oliver-heger.de>.
Hi Greg,

Am 14.11.2016 um 22:34 schrieb Greg Torrance:
> Thanks Oliver.
> 
> Regarding the Configuration API, is it possible to replace not just
> values but keys, too? For example, could I replace
> 
> <ReplaceMe id="4"/>
> 
> with
> 
> <NewKey>
>    <NewChildKey1>
>       <NewChildKey2>Some Value</NewChildKey2>
>    </NewChildKey1>
> </NewKey>
> 
> If so, can you suggest what class to look at first (for accomplishing
> this)?

This is indeed a tough one. There are multiple options, but I am not
sure whether they fully cover your use case; you will certainly need
some experiments:

- With the high-level API (offered by Configuration) you can delete the
key to be replaced and then use the addNodes() method to insert a nodes
structure as replacement. The tricky part is to get the key for
addNodes() right, so the replacement goes to the desired position. The
configuration's expression engine may help you here. It has methods to
query for keys (and receive matching node objects) and to obtain a
canonical key for a given node.

- You may also operate on the hierarchical configuration's node
structure directly. The root node can be queried via the node model
getNodeModel()). As this structure is immutable, you cannot directly
change it, but you have to create a copy which might not be that efficient.

- Unfortunately, XMLConfiguration has no direct hooks to manipulate the
node creation process. There are some helper methods, but these are private.

The use case is interesting. It would be good to offer some generic
support for configuration pre-processing, independent on a concrete
implementation. However, this is probably not easy to implement, and it
may still be insufficient for specific use cases.

Oliver

> 
> Thanks,
> Greg
> 
> On 11/14/2016 04:27 PM, Oliver Heger wrote:
>> Hi Greg,
>>
>> Am 14.11.2016 um 19:01 schrieb Greg Torrance:
>>> I hope I'm not asking too many questions...
>>>
>>> I wonder if it is possible to determine the character/byte position
>>> of a particular key in a configuration file?
>> No, the original position from where data is read is not stored in the
>> resulting configuration.
>>
>>> My intent is to do a pre-pass of an XML configuration file in which
>>> certain configuration keys/values are replaced by other keys/values.
>>> Once that is done the file will be reloaded. I realize this is
>>> possible outside of Commons Configuration, but I was wondering if
>>> there is a "hook" in the tool that might help simplify the process.
>>>
>> But wouldn't it be easier to do this with the Configuration API? Load
>> the configuration, iterate over its keys, replace data as appropriate
>> and save the result?
>>
>> Oliver
>>
>>> Thanks,
>>> Greg
>>>
>> ---------------------------------------------------------------------
>> 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] Character position of key in file

Posted by Greg Torrance <gr...@pobox.com>.
Thanks Oliver.

Regarding the Configuration API, is it possible to replace not just 
values but keys, too? For example, could I replace

<ReplaceMe id="4"/>

with

<NewKey>
    <NewChildKey1>
       <NewChildKey2>Some Value</NewChildKey2>
    </NewChildKey1>
</NewKey>

If so, can you suggest what class to look at first (for accomplishing 
this)?

Thanks,
Greg

On 11/14/2016 04:27 PM, Oliver Heger wrote:
> Hi Greg,
>
> Am 14.11.2016 um 19:01 schrieb Greg Torrance:
>> I hope I'm not asking too many questions...
>>
>> I wonder if it is possible to determine the character/byte position of a particular key in a configuration file?
> No, the original position from where data is read is not stored in the
> resulting configuration.
>
>> My intent is to do a pre-pass of an XML configuration file in which certain configuration keys/values are replaced by other keys/values. Once that is done the file will be reloaded. I realize this is possible outside of Commons Configuration, but I was wondering if there is a "hook" in the tool that might help simplify the process.
>>
> But wouldn't it be easier to do this with the Configuration API? Load
> the configuration, iterate over its keys, replace data as appropriate
> and save the result?
>
> Oliver
>
>> Thanks,
>> Greg
>>
> ---------------------------------------------------------------------
> 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] Character position of key in file

Posted by Oliver Heger <ol...@oliver-heger.de>.
Hi Greg,

Am 14.11.2016 um 19:01 schrieb Greg Torrance:
> I hope I'm not asking too many questions...
> 
> I wonder if it is possible to determine the character/byte position of a particular key in a configuration file?
No, the original position from where data is read is not stored in the
resulting configuration.

> 
> My intent is to do a pre-pass of an XML configuration file in which certain configuration keys/values are replaced by other keys/values. Once that is done the file will be reloaded. I realize this is possible outside of Commons Configuration, but I was wondering if there is a "hook" in the tool that might help simplify the process.
> 
But wouldn't it be easier to do this with the Configuration API? Load
the configuration, iterate over its keys, replace data as appropriate
and save the result?

Oliver

> Thanks,
> Greg
> 

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


[configuration] Character position of key in file

Posted by Greg Torrance <gr...@pobox.com>.
I hope I'm not asking too many questions...

I wonder if it is possible to determine the character/byte position of a particular key in a configuration file?

My intent is to do a pre-pass of an XML configuration file in which certain configuration keys/values are replaced by other keys/values. Once that is done the file will be reloaded. I realize this is possible outside of Commons Configuration, but I was wondering if there is a "hook" in the tool that might help simplify the process.

Thanks,
Greg

Re: [configuration] Combined Configuration examples

Posted by Aaron Gadberry <aa...@gadberry.com>.
Hi All,

A follow up question.  Is there a way to view the combined XML?  I am
constantly missing elements not knowing if it is my paths or my original
files or the combiner.

Thanks,



On Sun, Nov 13, 2016 at 2:54 PM, Greg Torrance <gr...@pobox.com>
wrote:

> Thanks Oliver.
>
> I think I understand what you're saying about why Channel 4 would not be
> included with the OverrideCombiner (if it doesn't exist in testfile1.xml).
> I am sorry to hear, though, that attributes are not used at all for
> matching with OverrideCombiner. If I'm understanding it correctly, that
> means it can't really be used for overriding just specific list items, as
> the entire list would have to be represented, in the same order, in both
> primary and overriding files, or the wrong list item might be overridden.
> (For example, if the primary list had Channels 1, 2, and 3, and the
> override list had only Channel 2, then it would attempt to override Channel
> 1 with the info from Channel 2.) Is my understanding correct?
>
> Anyway, I'm going to experiment a bit and try to make sure I have a good
> understanding of how this works.
>
> Thanks again for the help.
>
> Greg
>
>
> On 11/13/2016 01:51 PM, Oliver Heger wrote:
>
>> Hi Greg,
>>
>> Am 13.11.2016 um 18:41 schrieb Greg Torrance:
>>
>>> Hi Oliver,
>>>
>>> Thanks for the reply. That is helpful!
>>>
>>> Hm, it looks as if the examples are partly incorrect. I assume that
>>>>
>>> the channel with id="4" should not be part of testfile1.xml, but only be
>>> contained in the second file. It should appear in the results of union
>>> and  merge combiner. Does that make sense?
>>>
>>> I'm not clear why -- if the channel with id="4" is not contained in
>>> testfile1.xml -- why it will not end up in the results from all three
>>> combiners. Why just union and merge and not override, too?
>>>
>> On a higher level, OverrideCombiner detects that both files have a list
>> of channels. Therefore, it copies the first list and ignores the second
>> one. So the channels element in the first file overrides the one in the
>> second file.
>>
>> As for the attributes, do I understand correctly that the attribute
>>> values for elements are used, essentially, as "key" values to
>>> distinguish the various elements for combining purposes? And if the
>>> values of any attributes of two elements differ, then the elements would
>>> be considered different elements for combining purposes? (Said another
>>> way, if two elements have a set of attributes in common, if the values
>>> for those common attributes are the same, the elements will be
>>> considered to match.) Does that make sense? Is that correct?
>>>
>> This is true only for MergeCombiner. The other combiners do not try to
>> match nodes in both configurations based on their attribute values; they
>> take two source nodes at the same position in the hierarchy and produce
>> a result node that has all the attributes of the two source nodes.
>>
>> Oliver
>>
>> Thanks again for the reply.
>>>
>>> Greg
>>>
>>> On 11/13/2016 12:05 PM, Oliver Heger wrote:
>>>
>>>> Hi Greg,
>>>>
>>>> Am 13.11.2016 um 15:07 schrieb Greg Torrance:
>>>>
>>>>> Hi all,
>>>>>
>>>>> I am trying to work out the precise differences between
>>>>> OverrideCombiner, UnionCombiner, and MergeCombiner. However, the
>>>>> examples on this page
>>>>> (https://commons.apache.org/proper/commons-configuration/use
>>>>> rguide/howto_combinedconfiguration.html)
>>>>>
>>>>> are confusing to me.
>>>>>
>>>>> testfile1.xml and testfile2.xml both contain Channels with id="4",
>>>>> however none of the Combiner Results shows any Channels with id="4".
>>>>> And the Notes on the right-hand side of the page contain no mention of
>>>>> Channel 4.
>>>>>
>>>>> Am I missing something? Are the examples correct?
>>>>>
>>>> Hm, it looks as if the examples are partly incorrect. I assume that the
>>>> channel with id="4" should not be part of testfile1.xml, but only be
>>>> contained in the second file. It should appear in the results of union
>>>> and merge combiner. Does that make sense?
>>>>
>>>> What I'm really trying to understand is the impact of attributes in the
>>>>> way the various combiners choose to combine elements. (Any pointers to
>>>>> further documentation on this would be appreciated.)
>>>>>
>>>> Some more information can be found in the Javadocs of the combiner
>>>> classes:
>>>> - UnionCombiner states: "Another limitation is the handling of
>>>> attributes: Attributes can only have a single value. So if two nodes are
>>>> to be combined which both have an attribute with the same name, it is
>>>> not possible to construct a proper union attribute. In this case, the
>>>> attribute value from the first node is used."
>>>>
>>>> - OverrideCombiner has an addAttributes() method with the following
>>>> documentation: "Handles the attributes during a combination process.
>>>> First all attributes of the first node are added to the result. Then all
>>>> attributes of the second node, which are not contained in the first
>>>> node, are also added."
>>>>
>>>> - The merging behavior of MergeCombiner is also described in its class
>>>> documentation.
>>>>
>>>> Does this help?
>>>> Oliver
>>>>
>>>> Thoughts?
>>>>>
>>>>> Thanks,
>>>>> Greg
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> 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
>>>
>>> ---------------------------------------------------------------------
>> 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] Combined Configuration examples

Posted by Greg Torrance <gr...@pobox.com>.
Thanks Oliver.

I think I understand what you're saying about why Channel 4 would not be 
included with the OverrideCombiner (if it doesn't exist in 
testfile1.xml). I am sorry to hear, though, that attributes are not used 
at all for matching with OverrideCombiner. If I'm understanding it 
correctly, that means it can't really be used for overriding just 
specific list items, as the entire list would have to be represented, in 
the same order, in both primary and overriding files, or the wrong list 
item might be overridden. (For example, if the primary list had Channels 
1, 2, and 3, and the override list had only Channel 2, then it would 
attempt to override Channel 1 with the info from Channel 2.) Is my 
understanding correct?

Anyway, I'm going to experiment a bit and try to make sure I have a good 
understanding of how this works.

Thanks again for the help.

Greg

On 11/13/2016 01:51 PM, Oliver Heger wrote:
> Hi Greg,
>
> Am 13.11.2016 um 18:41 schrieb Greg Torrance:
>> Hi Oliver,
>>
>> Thanks for the reply. That is helpful!
>>
>>> Hm, it looks as if the examples are partly incorrect. I assume that
>> the channel with id="4" should not be part of testfile1.xml, but only be
>> contained in the second file. It should appear in the results of union
>> and  merge combiner. Does that make sense?
>>
>> I'm not clear why -- if the channel with id="4" is not contained in
>> testfile1.xml -- why it will not end up in the results from all three
>> combiners. Why just union and merge and not override, too?
> On a higher level, OverrideCombiner detects that both files have a list
> of channels. Therefore, it copies the first list and ignores the second
> one. So the channels element in the first file overrides the one in the
> second file.
>
>> As for the attributes, do I understand correctly that the attribute
>> values for elements are used, essentially, as "key" values to
>> distinguish the various elements for combining purposes? And if the
>> values of any attributes of two elements differ, then the elements would
>> be considered different elements for combining purposes? (Said another
>> way, if two elements have a set of attributes in common, if the values
>> for those common attributes are the same, the elements will be
>> considered to match.) Does that make sense? Is that correct?
> This is true only for MergeCombiner. The other combiners do not try to
> match nodes in both configurations based on their attribute values; they
> take two source nodes at the same position in the hierarchy and produce
> a result node that has all the attributes of the two source nodes.
>
> Oliver
>
>> Thanks again for the reply.
>>
>> Greg
>>
>> On 11/13/2016 12:05 PM, Oliver Heger wrote:
>>> Hi Greg,
>>>
>>> Am 13.11.2016 um 15:07 schrieb Greg Torrance:
>>>> Hi all,
>>>>
>>>> I am trying to work out the precise differences between
>>>> OverrideCombiner, UnionCombiner, and MergeCombiner. However, the
>>>> examples on this page
>>>> (https://commons.apache.org/proper/commons-configuration/userguide/howto_combinedconfiguration.html)
>>>>
>>>> are confusing to me.
>>>>
>>>> testfile1.xml and testfile2.xml both contain Channels with id="4",
>>>> however none of the Combiner Results shows any Channels with id="4".
>>>> And the Notes on the right-hand side of the page contain no mention of
>>>> Channel 4.
>>>>
>>>> Am I missing something? Are the examples correct?
>>> Hm, it looks as if the examples are partly incorrect. I assume that the
>>> channel with id="4" should not be part of testfile1.xml, but only be
>>> contained in the second file. It should appear in the results of union
>>> and merge combiner. Does that make sense?
>>>
>>>> What I'm really trying to understand is the impact of attributes in the
>>>> way the various combiners choose to combine elements. (Any pointers to
>>>> further documentation on this would be appreciated.)
>>> Some more information can be found in the Javadocs of the combiner
>>> classes:
>>> - UnionCombiner states: "Another limitation is the handling of
>>> attributes: Attributes can only have a single value. So if two nodes are
>>> to be combined which both have an attribute with the same name, it is
>>> not possible to construct a proper union attribute. In this case, the
>>> attribute value from the first node is used."
>>>
>>> - OverrideCombiner has an addAttributes() method with the following
>>> documentation: "Handles the attributes during a combination process.
>>> First all attributes of the first node are added to the result. Then all
>>> attributes of the second node, which are not contained in the first
>>> node, are also added."
>>>
>>> - The merging behavior of MergeCombiner is also described in its class
>>> documentation.
>>>
>>> Does this help?
>>> Oliver
>>>
>>>> Thoughts?
>>>>
>>>> Thanks,
>>>> Greg
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>
> ---------------------------------------------------------------------
> 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] Combined Configuration examples

Posted by Oliver Heger <ol...@oliver-heger.de>.
Hi Greg,

Am 13.11.2016 um 18:41 schrieb Greg Torrance:
> Hi Oliver,
> 
> Thanks for the reply. That is helpful!
> 
>> Hm, it looks as if the examples are partly incorrect. I assume that
> the channel with id="4" should not be part of testfile1.xml, but only be
> contained in the second file. It should appear in the results of union
> and  merge combiner. Does that make sense?
> 
> I'm not clear why -- if the channel with id="4" is not contained in
> testfile1.xml -- why it will not end up in the results from all three
> combiners. Why just union and merge and not override, too?
On a higher level, OverrideCombiner detects that both files have a list
of channels. Therefore, it copies the first list and ignores the second
one. So the channels element in the first file overrides the one in the
second file.

> 
> As for the attributes, do I understand correctly that the attribute
> values for elements are used, essentially, as "key" values to
> distinguish the various elements for combining purposes? And if the
> values of any attributes of two elements differ, then the elements would
> be considered different elements for combining purposes? (Said another
> way, if two elements have a set of attributes in common, if the values
> for those common attributes are the same, the elements will be
> considered to match.) Does that make sense? Is that correct?
This is true only for MergeCombiner. The other combiners do not try to
match nodes in both configurations based on their attribute values; they
take two source nodes at the same position in the hierarchy and produce
a result node that has all the attributes of the two source nodes.

Oliver

> 
> Thanks again for the reply.
> 
> Greg
> 
> On 11/13/2016 12:05 PM, Oliver Heger wrote:
>> Hi Greg,
>>
>> Am 13.11.2016 um 15:07 schrieb Greg Torrance:
>>> Hi all,
>>>
>>> I am trying to work out the precise differences between
>>> OverrideCombiner, UnionCombiner, and MergeCombiner. However, the
>>> examples on this page
>>> (https://commons.apache.org/proper/commons-configuration/userguide/howto_combinedconfiguration.html)
>>>
>>> are confusing to me.
>>>
>>> testfile1.xml and testfile2.xml both contain Channels with id="4",
>>> however none of the Combiner Results shows any Channels with id="4".
>>> And the Notes on the right-hand side of the page contain no mention of
>>> Channel 4.
>>>
>>> Am I missing something? Are the examples correct?
>> Hm, it looks as if the examples are partly incorrect. I assume that the
>> channel with id="4" should not be part of testfile1.xml, but only be
>> contained in the second file. It should appear in the results of union
>> and merge combiner. Does that make sense?
>>
>>> What I'm really trying to understand is the impact of attributes in the
>>> way the various combiners choose to combine elements. (Any pointers to
>>> further documentation on this would be appreciated.)
>> Some more information can be found in the Javadocs of the combiner
>> classes:
>> - UnionCombiner states: "Another limitation is the handling of
>> attributes: Attributes can only have a single value. So if two nodes are
>> to be combined which both have an attribute with the same name, it is
>> not possible to construct a proper union attribute. In this case, the
>> attribute value from the first node is used."
>>
>> - OverrideCombiner has an addAttributes() method with the following
>> documentation: "Handles the attributes during a combination process.
>> First all attributes of the first node are added to the result. Then all
>> attributes of the second node, which are not contained in the first
>> node, are also added."
>>
>> - The merging behavior of MergeCombiner is also described in its class
>> documentation.
>>
>> Does this help?
>> Oliver
>>
>>> Thoughts?
>>>
>>> Thanks,
>>> Greg
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
> 

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


Re: [configuration] Combined Configuration examples

Posted by Greg Torrance <gr...@pobox.com>.
Hi Oliver,

Thanks for the reply. That is helpful!

 > Hm, it looks as if the examples are partly incorrect. I assume that 
the channel with id="4" should not be part of testfile1.xml, but only be 
contained in the second file. It should appear in the results of union 
and  merge combiner. Does that make sense?

I'm not clear why -- if the channel with id="4" is not contained in 
testfile1.xml -- why it will not end up in the results from all three 
combiners. Why just union and merge and not override, too?

As for the attributes, do I understand correctly that the attribute 
values for elements are used, essentially, as "key" values to 
distinguish the various elements for combining purposes? And if the 
values of any attributes of two elements differ, then the elements would 
be considered different elements for combining purposes? (Said another 
way, if two elements have a set of attributes in common, if the values 
for those common attributes are the same, the elements will be 
considered to match.) Does that make sense? Is that correct?

Thanks again for the reply.

Greg

On 11/13/2016 12:05 PM, Oliver Heger wrote:
> Hi Greg,
>
> Am 13.11.2016 um 15:07 schrieb Greg Torrance:
>> Hi all,
>>
>> I am trying to work out the precise differences between
>> OverrideCombiner, UnionCombiner, and MergeCombiner. However, the
>> examples on this page
>> (https://commons.apache.org/proper/commons-configuration/userguide/howto_combinedconfiguration.html)
>> are confusing to me.
>>
>> testfile1.xml and testfile2.xml both contain Channels with id="4",
>> however none of the Combiner Results shows any Channels with id="4".
>> And the Notes on the right-hand side of the page contain no mention of
>> Channel 4.
>>
>> Am I missing something? Are the examples correct?
> Hm, it looks as if the examples are partly incorrect. I assume that the
> channel with id="4" should not be part of testfile1.xml, but only be
> contained in the second file. It should appear in the results of union
> and merge combiner. Does that make sense?
>
>> What I'm really trying to understand is the impact of attributes in the
>> way the various combiners choose to combine elements. (Any pointers to
>> further documentation on this would be appreciated.)
> Some more information can be found in the Javadocs of the combiner classes:
> - UnionCombiner states: "Another limitation is the handling of
> attributes: Attributes can only have a single value. So if two nodes are
> to be combined which both have an attribute with the same name, it is
> not possible to construct a proper union attribute. In this case, the
> attribute value from the first node is used."
>
> - OverrideCombiner has an addAttributes() method with the following
> documentation: "Handles the attributes during a combination process.
> First all attributes of the first node are added to the result. Then all
> attributes of the second node, which are not contained in the first
> node, are also added."
>
> - The merging behavior of MergeCombiner is also described in its class
> documentation.
>
> Does this help?
> Oliver
>
>> Thoughts?
>>
>> Thanks,
>> Greg
>>
>>
>> ---------------------------------------------------------------------
>> 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] Combined Configuration examples

Posted by Oliver Heger <ol...@oliver-heger.de>.
Hi Greg,

Am 13.11.2016 um 15:07 schrieb Greg Torrance:
> Hi all,
> 
> I am trying to work out the precise differences between
> OverrideCombiner, UnionCombiner, and MergeCombiner. However, the
> examples on this page
> (https://commons.apache.org/proper/commons-configuration/userguide/howto_combinedconfiguration.html)
> are confusing to me.
> 
> testfile1.xml and testfile2.xml both contain Channels with id="4",
> however none of the Combiner Results shows any Channels with id="4". 
> And the Notes on the right-hand side of the page contain no mention of
> Channel 4.
> 
> Am I missing something? Are the examples correct?
Hm, it looks as if the examples are partly incorrect. I assume that the
channel with id="4" should not be part of testfile1.xml, but only be
contained in the second file. It should appear in the results of union
and merge combiner. Does that make sense?

> 
> What I'm really trying to understand is the impact of attributes in the
> way the various combiners choose to combine elements. (Any pointers to
> further documentation on this would be appreciated.)
Some more information can be found in the Javadocs of the combiner classes:
- UnionCombiner states: "Another limitation is the handling of
attributes: Attributes can only have a single value. So if two nodes are
to be combined which both have an attribute with the same name, it is
not possible to construct a proper union attribute. In this case, the
attribute value from the first node is used."

- OverrideCombiner has an addAttributes() method with the following
documentation: "Handles the attributes during a combination process.
First all attributes of the first node are added to the result. Then all
attributes of the second node, which are not contained in the first
node, are also added."

- The merging behavior of MergeCombiner is also described in its class
documentation.

Does this help?
Oliver

> 
> Thoughts?
> 
> Thanks,
> Greg
> 
> 
> ---------------------------------------------------------------------
> 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