Thanks for the help, Oliver.
However, I think I may have led you astray with my proposed code change. It
was a bit hasty of me and I was suggesting doing the opposite of what I
wanted to do.
I was actually trying to get the substitution to only use the 1st value in a
multi-valued property. For example, a file like
V1 = value1
V1 = value2
Myprop = {$V1}
Would result in a configuration having
Myprop = value1
This way, when I do config.getString("Myprop") I'd get "value1" and not
"[value1, value2]".
>From what I can tell you're suggestion is a different way of actually
causing
Myprop = [value1, value2]
I think. I'm not sure.. I will experiment with what you've suggested.
Thank you!
If it's not the case, I think what I should originally have suggested was to
write toIterator(Object value) to pull off the first value from the split
and pass an iterator on just that single value.
Again.. thanks for bearing with my mistakes in explaining this.
Moran
> -----Original Message-----
> From: Oliver Heger [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, August 17, 2005 2:21 PM
> To: Jakarta Commons Users List
> Subject: Re: [configuration] Property Substitution Policy
>
> AbstractConfiguration provides a static setDelimiter() method, which
> takes a char that will be interpreted as a list delimiter. So if this
> character is detected in a string passed to the setProperty() or
> addProperty() methods, the string will be splitted into multiple values.
>
> To disable this behavior you can simply set the delimiter character to a
> value that does not occur in your properties, e.g. '\0'. An alternative
> is to quote occurences of the delimiter character with a back slash
> (e.g. "Hello\, world"). They will then be ignored.
>
> Does this help you with your problem?
> Oliver
>
> Moran Ben-David wrote:
>
> >I have dug deeper into the commons configuration codebase and uncovered
> the
> >exact place where the decision to do multi-valued substitution is made:
> >
> >(in PropertyConverter.java)
> >
> > public static Iterator toIterator(Object value, char delimiter)
> > {
> > ...
> > if (value instanceof String)
> > {
> > String s = (String) value;
> > if (s.indexOf(delimiter) > 0)
> > {
> > return split((String) value, delimiter).iterator();
> > }
> > else
> > {
> > return new SingletonIterator(value);
> > }
> > }
> >
> > ...
> > }
> >
> >I think the easiest thing for me to do is to
> >
> >1. overload toIterator:
> >
> > public static Iterator toIterator(Object value);
> >
> >This function would just disregard the delimiter case of the above
> function
> >but essentially will do the same thing.
> >
> >2. add a flag to the AbstractConfiguration class to tell wether to do
> >multivalued substituions.
> >
> >3. put a condition in AbstractConfiguration.addProperty(String, Object)
> to
> >look at the flag cand call the appropriate version of
> >PropertyConverter.toIterator().
> >
> >4. overload the constructor of AbstractConfiguration to accept
> >initialization of the substitution strategy flag.
> >
> >5. construct my PropertiesConfiguration (in my custom code) with a
> >flag=false passed. I.e. don't substitute.
> >
> >
> >My appoligies if this is a bit of "thinking outloud". I understand that
> >this might violate some of the design principles in Commons
> Configuration.
> >I guess that's me saying that I appreciate any guidance anyone has to
> offer
> >in this change.
> >
> >What will definitely not be fun, is that my code base will diverge from
> the
> >trunk of commons configuration. Perhaps I ought to think of subclassing
> >PropertiesConfiguration to handle this.. that might be smarter.. though
> >calls like super.addProperty might pose a problem.
> >
> >Thanks for reading if you got this far,
> >Moran Ben-David
> >http://www.place-base.com
> >
> >
> >
> >
> >>-----Original Message-----
> >>From: Moran Ben-David [mailto:[EMAIL PROTECTED]
> >>Sent: Wednesday, August 17, 2005 11:01 AM
> >>To: 'Jakarta Commons Users List'
> >>Subject: [configuration] Property Substitution Policy
> >>
> >>Hi all,
> >>
> >>I have a configuration which ends up having multiple valued properties
> as
> >>such:
> >>
> >>v1 = value1.1
> >>v1 = value1.2
> >>v2 = ${v1}
> >>
> >>My problem is that v2 ends up being set with multi-valued v1.
> >>
> >>v2 = [value1.1, value1.2]
> >>
> >>Has anybody tried to change this policy to use only the first element in
> >>the
> >>substitution?
> >>
> >>It seems to me that causing the PropertiesReader to toggle, based on
> some
> >>sort of parameter passed into the PropertiesConfiguration. The reader
> >>would
> >>toggle between full substitution and first-value substitution.
> >>
> >>A better design might be to pass in a strategy object that handles that?
> >>I.e. allowing anyone declaring the PropertiesConfiguration to either
> >>override the existing subbing strategy by passing in
> >>SubstitutionStrategy/Substitutor object.
> >>
> >>Does any one know if this ability is already in the commons
> configuration
> >>code base? Is it in the works? I'm looking to at least benefit from
> >>design
> >>guidance form any commons developers if I do make this change myself.
> >>
> >>Thanks,
> >>Moran Ben-David
> >>
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]