> -----Original Message-----
> From: Berin Loritsch [mailto:[EMAIL PROTECTED]
> Sent: 12 December 2001 21:05
> To: Avalon Developers List
> Subject: Re: new method Configuration.containsAttribute() ?
>
> Vincent Massol wrote:
>
> > Ok. Here is my use case :
> >
> > <configurationFactory>
> >
> > <bundle id="short name1"
> > [language="language1"]
> > [country="Country1"]>
> >
> > /path/to/bundle1
> >
> > </bundle>
> >
> > </configurationFactory>
> >
> > In the implementation code I'd like to take one action if no
> > language/country are specified and another if they are (because
behind
> > the scenes I need to call an API which has 2 signatures, one with a
> > Locale and one without - I don't want to get the default locale and
only
> > use the signature that accepts a locale as this would mean I
override
> > the default implementation of the API I'm referring to as I would
> > introduce my own logic).
>
>
> The single parameter method is only a shortcut for what you are really
> doing. It is not your "own" logic per se.
>
> In your case, the ResourceBundle.getBundle(String) method is exactly
the
> same as:
>
> getBundle(baseName, Locale.getDefault(),
> this.getClass().getClassLoader())
>
> As it says directly in the JavaDocs. The Locale is a bit different if
> you are not using the default because you have to have a language, but
> can further specify it with a country or variant.
hehe doing some extrapolation ... :) I had voluntarily not explained
what I was doing with the Locale in my previous email so that you would
not find a way around ... :) ... but apparently it failed ...
Actually, I'm not doing a ResourceBundle.getBundle() but using another
class which wraps around Bundle. However, I wanted the discussion to be
more generic and simply consider the case where I need to decide what to
do in my code based upon the fact that an attribute exist or not.
>
> In this particular case, I might do something like this:
>
> Locale defLocale = Locale.getDefault();
> String language = conf.getAttribute("language",
defLocale.getLanguage());
> String country = conf.getAttribute("country", defLocale.getCountry());
>
> Locale usedLocale = new Locale(language, country);
> getBundle(baseName, usedLocale);
>
>
> Ideally, you would have a static constants interface that would define
> your
> default language/country:
>
> interface Constants
> {
> String DEFAULT_LANGUAGE = Locale.getDefault().getLanguage();
> String DEFAULT_COUNTRY = Locale.getDefault().getCountry();
> }
>
>
>
> > I can imagine lots of cases where you would need to verify if an
> > attribute exists because you may want to do something different if
it
> > does than if it does not.
>
>
> We would have to vote on adding the "boolean attributeExists()" method
> to Configuration. It might not happen, and I am +0 on it. I'm not
> going to stand in it's way, but not totally convinced it's necessary.
>
The getChild() API has a signature that allows for returning null and
thus testing for existence. Why couldn't we have the same thing for
attributes. However, I'm not going to press this issue as I can always
use the
null == getAttribute("key", null)
construct. Let's forget it then, until someone else needs it ... :)
Thanks for the help.
-Vincent
>
> > Ok about immutability :)
> >
> > Forget about hashtable. Isn't there an ImmutableHashtable in a
utility
> > class anywhere that would have the same API save for the write
methods ?
>
>
> java.util.Collections.unmodifiableMap(Map)
>
> And for this purpose is a hack.
>
> --
>
> "They that give up essential liberty to obtain a little temporary
safety
> deserve neither liberty nor safety."
> - Benjamin Franklin
>
>
> --
> To unsubscribe, e-mail: <mailto:avalon-dev-
> [EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:avalon-dev-
> [EMAIL PROTECTED]>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>