jautil.cache
Class JACacheHandler

java.lang.Object
  extended by jautil.cache.JACacheHandler
Direct Known Subclasses:
AvatarsCacheHandler, MiscCacheHandler

public abstract class JACacheHandler
extends java.lang.Object

A JA cache handler provides access to a local cache for a collection of potentially remote and dispersed data files, each identified by its URL.

This is an abstract class. Each concrete subclass must supply a local root directory for the cache via the abstract method getCacheRootDir().

Each cache is bound to a specific version of JASigning.

Each cache entry is identified by its name and is represented by a pair of files: a descriptor, represented here as a JACacheDescriptor, and the cached copy of the data at the original URL. The contents of the descriptor include the entry name and the original data URL.

The obvious way to support this cache would be through the standard Java caching mechanism, the JNLP Persistence Service. However, that service seems not to be available to HTML applets -- at least not automatically so: a typical applet dies a horrible death as soon as it tries to use that service. So this cache is implemented using the local file system: the descriptor and data files for a given entry are held in a subdirectory of the cache root directory with the same name as the entry. Any JA cache root directory is expected to be held under a directory called .jasigning/ under the given user's base directory.


Method Summary
 JACacheDescriptor ensureCached(java.lang.String name, java.lang.String url)
          Tries to ensure that this cache contains an up-to-date pair of files for the entry with the given name and original data URL, returning the cache descriptor if successful, or null otherwise.
 java.net.URL getCachedDataURL(java.lang.String ename, java.lang.String durl)
          Returns a URL for the local copy of the data in the cache entry for the given name and remote data URL; the result is null if the required cache entry does not exist and cannot be created.
 java.net.URL getDataFileURL(JACacheDescriptor desc)
          Returns a URL for the local copy of the data in the cache entry identified by the given descriptor; if the given descriptor is null the result is also null.
 java.lang.String getDataFileURLStr(JACacheDescriptor desc)
          Returns the string form of the URL for the local copy of the data in the cache entry identified by the given descriptor; if the given descriptor is null the result is also null.
 boolean hasACacheEntry(java.lang.String ename, java.lang.String url)
          Determines whether the cache contains a (possibly stale) entry for the given name and original data URL.
 boolean isCached(java.lang.String ename, java.lang.String url)
          Determines whether the cache contains an (up-to-date) pair of files for the entry with the given name and original data URL.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

hasACacheEntry

public boolean hasACacheEntry(java.lang.String ename,
                              java.lang.String url)
Determines whether the cache contains a (possibly stale) entry for the given name and original data URL.


isCached

public boolean isCached(java.lang.String ename,
                        java.lang.String url)
Determines whether the cache contains an (up-to-date) pair of files for the entry with the given name and original data URL.


ensureCached

public JACacheDescriptor ensureCached(java.lang.String name,
                                      java.lang.String url)
Tries to ensure that this cache contains an up-to-date pair of files for the entry with the given name and original data URL, returning the cache descriptor if successful, or null otherwise. If necessary, a new pair of cache items is created or an existing stale data item is refreshed.


getCachedDataURL

public java.net.URL getCachedDataURL(java.lang.String ename,
                                     java.lang.String durl)
Returns a URL for the local copy of the data in the cache entry for the given name and remote data URL; the result is null if the required cache entry does not exist and cannot be created.


getDataFileURL

public java.net.URL getDataFileURL(JACacheDescriptor desc)
Returns a URL for the local copy of the data in the cache entry identified by the given descriptor; if the given descriptor is null the result is also null. .


getDataFileURLStr

public java.lang.String getDataFileURLStr(JACacheDescriptor desc)
Returns the string form of the URL for the local copy of the data in the cache entry identified by the given descriptor; if the given descriptor is null the result is also null.