You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/01/27 04:14:16 UTC

cvs commit: jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n ResourceManager.java

mcconnell    2003/01/26 19:14:16

  Modified:    i18n     default.properties
               i18n/src/java/org/apache/avalon/excalibur/i18n
                        ResourceManager.java
  Log:
  Updates to support explicit declaration of a locale to the ResoureManager.
  
  Revision  Changes    Path
  1.8       +1 -1      jakarta-avalon-excalibur/i18n/default.properties
  
  Index: default.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/i18n/default.properties,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- default.properties	25 Jun 2002 03:19:53 -0000	1.7
  +++ default.properties	27 Jan 2003 03:14:16 -0000	1.8
  @@ -56,7 +56,7 @@
   dist.name = ${name}-${version}
   
   #  name of jar file
  -jar.name = ${name}-${version}.jar
  +jar.name = ${name}-${package-version}.jar
   
   #  property indicating directory where all distribution archives are placed
   dist.base = distributions
  
  
  
  1.18      +29 -1     jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n/ResourceManager.java
  
  Index: ResourceManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n/ResourceManager.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ResourceManager.java	31 Aug 2002 04:56:08 -0000	1.17
  +++ ResourceManager.java	27 Jan 2003 03:14:16 -0000	1.18
  @@ -7,6 +7,7 @@
    */
   package org.apache.avalon.excalibur.i18n;
   
  +import java.util.Locale;
   import java.lang.ref.WeakReference;
   import java.util.HashMap;
   
  @@ -45,10 +46,24 @@
       public synchronized static final Resources getBaseResources( final String baseName,
                                                                    final ClassLoader classLoader )
       {
  +        return getBaseResources( baseName, Locale.getDefault(), classLoader );
  +    }
  +
  +    /**
  +     * Retrieve resource with specified basename.
  +     *
  +     * @param baseName the basename
  +     * @param classLoader the classLoader to load resources from
  +     * @return the Resources
  +     */
  +    public synchronized static final Resources getBaseResources( final String baseName,
  +                                                                 final Locale locale,
  +                                                                 final ClassLoader classLoader )
  +    {
           Resources resources = getCachedResource( baseName );
           if( null == resources )
           {
  -            resources = new Resources( baseName, classLoader );
  +            resources = new Resources( baseName, locale, classLoader );
               putCachedResource( baseName, resources );
           }
   
  @@ -137,6 +152,19 @@
       {
           return getBaseResources( getPackageResourcesBaseName( clazz ), clazz.getClassLoader() );
       }
  +
  +    /**
  +     * Retrieve resource for package relative to the specified class and locale.
  +     *
  +     * @param clazz the Class
  +     * @param locale the locale
  +     * @return the Resources
  +     */
  +    public static final Resources getPackageResources( final Class clazz, Locale locale )
  +    {
  +        return getBaseResources( getPackageResourcesBaseName( clazz ), locale, clazz.getClassLoader() );
  +    }
  +
   
       /**
        * Retrieve resource for specified Class.
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n ResourceManager.java

Posted by Stephen McConnell <mc...@apache.org>.

Peter Donald wrote:

>On Sat, 1 Feb 2003 11:07, Stephen McConnell wrote:
>  
>
>>The ResourceManager class basically gets established once following
>>which the body of the code invokes operations against the cached
>>resource.  There isn't anything in the ResourceManager currently to
>>reset the locale being used as runtime.
>>    
>>
>
>Locale.setDefault( myNewLocale );
>ResourceManager.clearResourceCache()
>
>  
>

Yep - that would work.

How about you send in a patch documenting this on the ResourceManager class?

Steve.

-- 

Stephen J. McConnell
mailto:mcconnell@apache.org
http://www.osm.net




---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n ResourceManager.java

Posted by Peter Donald <pe...@realityforge.org>.
On Sat, 1 Feb 2003 11:07, Stephen McConnell wrote:
> The ResourceManager class basically gets established once following
> which the body of the code invokes operations against the cached
> resource.  There isn't anything in the ResourceManager currently to
> reset the locale being used as runtime.

Locale.setDefault( myNewLocale );
ResourceManager.clearResourceCache()


-- 
Cheers,

Peter Donald
The big mistake that men make is that when they turn thirteen or fourteen and
all of a sudden they've reached puberty, they believe that they like women.
Actually, you're just horny. It doesn't mean you like women any more at
twenty-one than you did at ten.                --Jules Feiffer (cartoonist) 


---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n ResourceManager.java

Posted by Stephen McConnell <mc...@apache.org>.

Noel J. Bergman wrote:

>Stephen,
>
>I agree with Peter that it would be counter-intuitive for
>
>  re = ResourceManager.getResources( X.class, Locale.en )
>
>to return anything other than English resources, just because someone else
>called
>
>  rd = ResourceManager.getResources( X.class, Locale.de );
>
>first.  That just seems broken to me.
>  
>

Broken no - inconsitent yes.
I'll checkout the setting of the gefault locale tomorow and if that 
solves the requirements then I'll backout changes.

>If you are saying that once instantiated with a Locale, then subsequent
>calls that explicitly pass a Locale won't be honored, the least that should
>happen is an exception should be thrown.  That is better than silently
>ignoring the request, and returning the wrong data.
>  
>

What is really needed here is more documentation about the usage of the 
manager and the realtionship to the default locale setting.  With that 
in place then the problem dissapears.  

Cheers, Steve.

-- 

Stephen J. McConnell
mailto:mcconnell@apache.org
http://www.osm.net




---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n ResourceManager.java

Posted by Peter Royal <pr...@apache.org>.
On Friday, January 31, 2003, at 07:51  PM, Noel J. Bergman wrote:
> I agree with Peter that it would be counter-intuitive for
>
>   re = ResourceManager.getResources( X.class, Locale.en )
>
> to return anything other than English resources, just because someone 
> else
> called
>
>   rd = ResourceManager.getResources( X.class, Locale.de );
>
> first.  That just seems broken to me.

I agree too. That is non-intuitive behavior.
-pete


---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


RE: cvs commit: jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n ResourceManager.java

Posted by "Noel J. Bergman" <no...@devtech.com>.
Stephen,

I agree with Peter that it would be counter-intuitive for

  re = ResourceManager.getResources( X.class, Locale.en )

to return anything other than English resources, just because someone else
called

  rd = ResourceManager.getResources( X.class, Locale.de );

first.  That just seems broken to me.

If you are saying that once instantiated with a Locale, then subsequent
calls that explicitly pass a Locale won't be honored, the least that should
happen is an exception should be thrown.  That is better than silently
ignoring the request, and returning the wrong data.

> There isn't anything in the ResourceManager currently to
> reset the locale being used as runtime.

Sounds like Peter has a fix for that.  :-)

	--- Noel


---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n ResourceManager.java

Posted by Stephen McConnell <mc...@apache.org>.

Peter Donald wrote:

>On Sat, 1 Feb 2003 10:23, Stephen McConnell wrote:
>  
>
>>>It breaks
>>>
>>>r1 = ResourceManager.getResources( X.class, Locale.de );
>>>r2 = ResourceManager.getResources( X.class, Locale.en );
>>>r3 = ResourceManager.getResources( X.class );
>>>
>>>and will always return the german resources rather than german, english
>>>and default locale.
>>>      
>>>
>>That is the intention.
>>    
>>
>
>Seems stupid. I would expect 
>
>ResourceManager.getResources( X.class, Locale.en )
>
>to return english resources myself.
>

The ResourceManager class basically gets established once following 
which the body of the code invokes operations against the cached 
resource.  There isn't anything in the ResourceManager currently to 
reset the locale being used as runtime.  If you want a sepecic resource 
you can do that (as you suggested) using the Resource class.  The 
getBaseResources could be enhanced to check the supplied locale is 
consitent with the cached locale however I think this is unnecessary - 
after all the ResourceManager is intended to provide the cache value as 
a static value and does not need to be changed following initiation.

Steve.

-- 

Stephen J. McConnell
mailto:mcconnell@apache.org
http://www.osm.net




---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n ResourceManager.java

Posted by Peter Donald <pe...@realityforge.org>.
On Sat, 1 Feb 2003 10:23, Stephen McConnell wrote:
> >It breaks
> >
> >r1 = ResourceManager.getResources( X.class, Locale.de );
> >r2 = ResourceManager.getResources( X.class, Locale.en );
> >r3 = ResourceManager.getResources( X.class );
> >
> >and will always return the german resources rather than german, english
> > and default locale.
>
> That is the intention.

Seems stupid. I would expect 

ResourceManager.getResources( X.class, Locale.en )

to return english resources myself.

-- 
Cheers,

Peter Donald
------------------------------------
The two secrets to success:
   1- Don't tell anyone everything.
------------------------------------ 


---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n ResourceManager.java

Posted by Stephen McConnell <mc...@apache.org>.

Peter Donald wrote:

>On Sat, 1 Feb 2003 09:55, Stephen McConnell wrote:
>  
>
>>I want the resource object cached but the establishment is directing
>>that the cached resource is established with respect to a particular
>>locale.  I don't see how this breaks caching because I want the
>>behaviour of Resource per class. I simply want to override the default
>>establishment of the locale.  Please take another look - I think you
>>will find that class caching is working just fine - but I'm interested
>>in any specific issues or respective suggestions you may have.
>>    
>>
>
>It breaks
>
>r1 = ResourceManager.getResources( X.class, Locale.de );
>r2 = ResourceManager.getResources( X.class, Locale.en );
>r3 = ResourceManager.getResources( X.class );
>
>and will always return the german resources rather than german, english and 
>default locale.
>  
>

That is the intention.

The only difference is that instead of pulling in the default locale 
into the cache - the implementation can be instructed to pull an 
specific locale resource into the cache. I.e. default locale is the 
system default local unless you provide an overriding locale.  That 
point on the resource manager returns the established locale.  I.e. it's 
not broken.

Steve.

-- 

Stephen J. McConnell
mailto:mcconnell@apache.org
http://www.osm.net




---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n ResourceManager.java

Posted by Peter Donald <pe...@realityforge.org>.
On Sat, 1 Feb 2003 09:55, Stephen McConnell wrote:
> I want the resource object cached but the establishment is directing
> that the cached resource is established with respect to a particular
> locale.  I don't see how this breaks caching because I want the
> behaviour of Resource per class. I simply want to override the default
> establishment of the locale.  Please take another look - I think you
> will find that class caching is working just fine - but I'm interested
> in any specific issues or respective suggestions you may have.

It breaks

r1 = ResourceManager.getResources( X.class, Locale.de );
r2 = ResourceManager.getResources( X.class, Locale.en );
r3 = ResourceManager.getResources( X.class );

and will always return the german resources rather than german, english and 
default locale.

-- 
Cheers,

Peter Donald
*------------------------------------------------*
| You can't wake a person who is pretending      |
|       to be asleep. -Navajo Proverb.           |
*------------------------------------------------* 


---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n ResourceManager.java

Posted by Stephen McConnell <mc...@apache.org>.

Peter Donald wrote:

>This just broke clas caching. If you want this you need to use cache keyed to 
>both local and bundle. However in the scenario you are using it I would 
>recomend you backout this change and just instantiate the Resource object 
>directly. The ResourceManager is only intended for use when you want to cache 
>the resources but as you dont really then you should probably not use it. 
>

I want the resource object cached but the establishment is directing 
that the cached resource is established with respect to a particular 
locale.  I don't see how this breaks caching because I want the 
behaviour of Resource per class. I simply want to override the default 
establishment of the locale.  Please take another look - I think you 
will find that class caching is working just fine - but I'm interested 
in any specific issues or respective suggestions you may have.

Steve.

>
>On Mon, 27 Jan 2003 14:14, mcconnell@apache.org wrote:
>  
>
>>mcconnell    2003/01/26 19:14:16
>>
>>  Modified:    i18n     default.properties
>>               i18n/src/java/org/apache/avalon/excalibur/i18n
>>                        ResourceManager.java
>>  Log:
>>  Updates to support explicit declaration of a locale to the
>>ResoureManager.
>>
>>  Revision  Changes    Path
>>  1.8       +1 -1      jakarta-avalon-excalibur/i18n/default.properties
>>
>>  Index: default.properties
>>  ===================================================================
>>  RCS file: /home/cvs/jakarta-avalon-excalibur/i18n/default.properties,v
>>  retrieving revision 1.7
>>  retrieving revision 1.8
>>  diff -u -r1.7 -r1.8
>>  --- default.properties	25 Jun 2002 03:19:53 -0000	1.7
>>  +++ default.properties	27 Jan 2003 03:14:16 -0000	1.8
>>  @@ -56,7 +56,7 @@
>>   dist.name = ${name}-${version}
>>
>>   #  name of jar file
>>  -jar.name = ${name}-${version}.jar
>>  +jar.name = ${name}-${package-version}.jar
>>
>>   #  property indicating directory where all distribution archives are
>>placed dist.base = distributions
>>
>>
>>
>>  1.18      +29 -1    
>>jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n/Res
>>ourceManager.java
>>
>>  Index: ResourceManager.java
>>  ===================================================================
>>  RCS file:
>>/home/cvs/jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibu
>>r/i18n/ResourceManager.java,v retrieving revision 1.17
>>  retrieving revision 1.18
>>  diff -u -r1.17 -r1.18
>>  --- ResourceManager.java	31 Aug 2002 04:56:08 -0000	1.17
>>  +++ ResourceManager.java	27 Jan 2003 03:14:16 -0000	1.18
>>  @@ -7,6 +7,7 @@
>>    */
>>   package org.apache.avalon.excalibur.i18n;
>>
>>  +import java.util.Locale;
>>   import java.lang.ref.WeakReference;
>>   import java.util.HashMap;
>>
>>  @@ -45,10 +46,24 @@
>>       public synchronized static final Resources getBaseResources( final
>>String baseName, final ClassLoader classLoader ) {
>>  +        return getBaseResources( baseName, Locale.getDefault(),
>>classLoader ); +    }
>>  +
>>  +    /**
>>  +     * Retrieve resource with specified basename.
>>  +     *
>>  +     * @param baseName the basename
>>  +     * @param classLoader the classLoader to load resources from
>>  +     * @return the Resources
>>  +     */
>>  +    public synchronized static final Resources getBaseResources( final
>>String baseName, +                                                         
>>       final Locale locale, +                                              
>>                  final ClassLoader classLoader ) +    {
>>           Resources resources = getCachedResource( baseName );
>>           if( null == resources )
>>           {
>>  -            resources = new Resources( baseName, classLoader );
>>  +            resources = new Resources( baseName, locale, classLoader );
>>               putCachedResource( baseName, resources );
>>           }
>>
>>  @@ -137,6 +152,19 @@
>>       {
>>           return getBaseResources( getPackageResourcesBaseName( clazz ),
>>clazz.getClassLoader() ); }
>>  +
>>  +    /**
>>  +     * Retrieve resource for package relative to the specified class and
>>locale. +     *
>>  +     * @param clazz the Class
>>  +     * @param locale the locale
>>  +     * @return the Resources
>>  +     */
>>  +    public static final Resources getPackageResources( final Class
>>clazz, Locale locale ) +    {
>>  +        return getBaseResources( getPackageResourcesBaseName( clazz ),
>>locale, clazz.getClassLoader() ); +    }
>>  +
>>
>>       /**
>>        * Retrieve resource for specified Class.
>>    
>>
>
>  
>

-- 

Stephen J. McConnell
mailto:mcconnell@apache.org
http://www.osm.net




---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n ResourceManager.java

Posted by Peter Donald <pe...@realityforge.org>.
This just broke clas caching. If you want this you need to use cache keyed to 
both local and bundle. However in the scenario you are using it I would 
recomend you backout this change and just instantiate the Resource object 
directly. The ResourceManager is only intended for use when you want to cache 
the resources but as you dont really then you should probably not use it. 

On Mon, 27 Jan 2003 14:14, mcconnell@apache.org wrote:
> mcconnell    2003/01/26 19:14:16
>
>   Modified:    i18n     default.properties
>                i18n/src/java/org/apache/avalon/excalibur/i18n
>                         ResourceManager.java
>   Log:
>   Updates to support explicit declaration of a locale to the
> ResoureManager.
>
>   Revision  Changes    Path
>   1.8       +1 -1      jakarta-avalon-excalibur/i18n/default.properties
>
>   Index: default.properties
>   ===================================================================
>   RCS file: /home/cvs/jakarta-avalon-excalibur/i18n/default.properties,v
>   retrieving revision 1.7
>   retrieving revision 1.8
>   diff -u -r1.7 -r1.8
>   --- default.properties	25 Jun 2002 03:19:53 -0000	1.7
>   +++ default.properties	27 Jan 2003 03:14:16 -0000	1.8
>   @@ -56,7 +56,7 @@
>    dist.name = ${name}-${version}
>
>    #  name of jar file
>   -jar.name = ${name}-${version}.jar
>   +jar.name = ${name}-${package-version}.jar
>
>    #  property indicating directory where all distribution archives are
> placed dist.base = distributions
>
>
>
>   1.18      +29 -1    
> jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n/Res
>ourceManager.java
>
>   Index: ResourceManager.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibu
>r/i18n/ResourceManager.java,v retrieving revision 1.17
>   retrieving revision 1.18
>   diff -u -r1.17 -r1.18
>   --- ResourceManager.java	31 Aug 2002 04:56:08 -0000	1.17
>   +++ ResourceManager.java	27 Jan 2003 03:14:16 -0000	1.18
>   @@ -7,6 +7,7 @@
>     */
>    package org.apache.avalon.excalibur.i18n;
>
>   +import java.util.Locale;
>    import java.lang.ref.WeakReference;
>    import java.util.HashMap;
>
>   @@ -45,10 +46,24 @@
>        public synchronized static final Resources getBaseResources( final
> String baseName, final ClassLoader classLoader ) {
>   +        return getBaseResources( baseName, Locale.getDefault(),
> classLoader ); +    }
>   +
>   +    /**
>   +     * Retrieve resource with specified basename.
>   +     *
>   +     * @param baseName the basename
>   +     * @param classLoader the classLoader to load resources from
>   +     * @return the Resources
>   +     */
>   +    public synchronized static final Resources getBaseResources( final
> String baseName, +                                                         
>        final Locale locale, +                                              
>                   final ClassLoader classLoader ) +    {
>            Resources resources = getCachedResource( baseName );
>            if( null == resources )
>            {
>   -            resources = new Resources( baseName, classLoader );
>   +            resources = new Resources( baseName, locale, classLoader );
>                putCachedResource( baseName, resources );
>            }
>
>   @@ -137,6 +152,19 @@
>        {
>            return getBaseResources( getPackageResourcesBaseName( clazz ),
> clazz.getClassLoader() ); }
>   +
>   +    /**
>   +     * Retrieve resource for package relative to the specified class and
> locale. +     *
>   +     * @param clazz the Class
>   +     * @param locale the locale
>   +     * @return the Resources
>   +     */
>   +    public static final Resources getPackageResources( final Class
> clazz, Locale locale ) +    {
>   +        return getBaseResources( getPackageResourcesBaseName( clazz ),
> locale, clazz.getClassLoader() ); +    }
>   +
>
>        /**
>         * Retrieve resource for specified Class.

-- 
Cheers,

Peter Donald
*------------------------------------------------------*
| "Common sense is the collection of prejudices        |
|  acquired by age 18. " -Albert Einstein              |
*------------------------------------------------------* 


---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org