avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/i18n/src/java/org/apache/avalon/excalibur/i18n ResourceManager.java
Date Sat, 31 Aug 2002 04:56:08 GMT
donaldp     2002/08/30 21:56:08

  Modified:    i18n/src/java/org/apache/avalon/excalibur/i18n
                        ResourceManager.java
  Log:
  Add a method to clear the whole cahce. Protect it with a runtime permission.
  
  Revision  Changes    Path
  1.17      +40 -10    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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- ResourceManager.java	31 Aug 2002 04:31:27 -0000	1.16
  +++ ResourceManager.java	31 Aug 2002 04:56:08 -0000	1.17
  @@ -17,6 +17,11 @@
    */
   public class ResourceManager
   {
  +    /**
  +     * Permission needed to clear complete cache.
  +     */
  +    private static final RuntimePermission CLEAR_CACHE_PERMISSION =
  +        new RuntimePermission( "i18n.clearCompleteCache" );
       private static final HashMap c_resources = new HashMap();
   
       /**
  @@ -37,17 +42,42 @@
        * @param classLoader the classLoader to load resources from
        * @return the Resources
        */
  -    public static final Resources getBaseResources( final String baseName,
  -                                                    final ClassLoader classLoader )
  +    public synchronized static final Resources getBaseResources( final String baseName,
  +                                                                 final ClassLoader classLoader
)
  +    {
  +        Resources resources = getCachedResource( baseName );
  +        if( null == resources )
  +        {
  +            resources = new Resources( baseName, classLoader );
  +            putCachedResource( baseName, resources );
  +        }
  +
  +        return resources;
  +    }
  +
  +    /**
  +     * Clear the cache of all resources currently loaded into the
  +     * system. This method is useful if you need to dump the complete
  +     * cache and because part of the application is reloading and
  +     * thus the resources may need to be reloaded.
  +     *
  +     * <p>Note that the caller must have been granted the
  +     * "i18n.clearCompleteCache" {@link RuntimePermission} or
  +     * else a security exception will be thrown.</p>
  +     *
  +     * @throws SecurityException if the caller does not have
  +     *                           permission to clear cache
  +     */
  +    public synchronized static final void clearResourceCache()
  +        throws SecurityException
       {
  -        Resources packet = getCachedResource( baseName );
  -        if( null == packet )
  +        final SecurityManager sm = System.getSecurityManager();
  +        if( null != sm )
           {
  -            packet = new Resources( baseName, classLoader );
  -            putCachedResource( baseName, packet );
  +            sm.checkPermission( CLEAR_CACHE_PERMISSION );
           }
   
  -        return packet;
  +        c_resources.clear();
       }
   
       /**
  @@ -56,8 +86,8 @@
        * @param baseName the resource key
        * @param resources the resources object
        */
  -    private static final void putCachedResource( final String baseName,
  -                                                 final Resources resources )
  +    private synchronized static final void putCachedResource( final String baseName,
  +                                                              final Resources resources
)
       {
           c_resources.put( baseName,
                            new WeakReference( resources ) );
  @@ -69,7 +99,7 @@
        * @param baseName the resource key
        * @return resources the resources object
        */
  -    private static final Resources getCachedResource( final String baseName )
  +    private synchronized static final Resources getCachedResource( final String baseName
)
       {
           final WeakReference weakReference =
               (WeakReference)c_resources.get( baseName );
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message