org.norther.tammi.core.locale
Class DefaultResourceFinder

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.core.locale.DefaultResourceFinder
All Implemented Interfaces:
Serializable, NotificationBroadcaster, NotificationEmitter, Manageable, MBeanDelegate, Refreshable, CacheClient<String,Object>, ResourceFinder

public class DefaultResourceFinder
extends Adaptee
implements ResourceFinder

A default implementation of ResourceFinder.

Version:
$Id: DefaultResourceFinder.java,v 1.16 2009/09/28 15:08:44 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Constructor Summary
DefaultResourceFinder()
          Constructs a new finder.
 
Method Summary
 void clearCached()
          Clears all cached entries without notifying.
 void expireCached(long timestamp)
          Expires all cached entries notifying them about expiration.
 void expireFraction(long timestamp, float fraction)
          Expires the specified fraction of cached entries notifying them about expiration.
 ConcurrentMap<String,Object> getCache(boolean... create)
          Gets and optionally creates the cache.
 long getCacheCleared()
          Gets the timestamp of the last cache clearing or expiration.
 String getDefaultBaseName()
          Gets the default base name to be applied when an explicit one is not specified.
 String getDefaultEncoding()
          Gets the encoding to use for property files.
 Locale getDefaultLocale()
          Gets the default locale of resources.
 String getPlugInBaseName(String key)
          Gets the base name of the resource bundle class associated with the specified plug-in key.
 String getPlugInKey()
          Gets the default key for pluggable resource bundles of this resource finder.
 String getPlugInKey(Class<?> baseClass)
          Gets the most specific key for pluggable resource bundles of this resource finder.
 String getPlugInKey(String baseName)
          Gets the class specific key for pluggable resource bundles of this resource finder.
 long getRefreshed()
          Gets the last refresh timestamp.
 LookupResourceBundle getResourceBundle(Locale... locale)
          Gets the default resource bundle for the default base name and the specified locale.
 LookupResourceBundle getResourceBundle(String baseName, ClassLoader loader, Locale... locale)
          Gets the appropriate resource bundle for the given base name, specified locale and class loader.
 LookupResourceBundle getResourceBundle(String baseName, Locale... locale)
          Gets the appropriate resource bundle for the given base name and specified locale.
 LookupResourceBundle getResourceBundle(String baseName, String variant, ClassLoader loader, Locale... locale)
          Gets the appropriate resource bundle for the given base name, specified locale, optional variant and class loader.
protected  LookupResourceBundle getResourceBundle(String baseName, String localizedName, ClassLoader loader, Locale locale)
          Gets the resource bundle for the given locale.
 LookupResourceBundle getResourceBundle(String baseName, String variant, Locale... locale)
          Gets the appropriate resource bundle for the given base name, specified locale and optional variant.
 long getResourceCheckInterval()
          Gets the default interval for checking validity of cached resource bundles of this resource finder.
 long getResourceCheckInterval(Class<?> baseClass)
          Gets the most specific interval for checking validity of cached resource bundles of this resource finder.
 long getResourceCheckInterval(String className)
          Gets the class specific interval for checking validity of cached resource bundles of this resource finder.
 String getResourceKey()
          Gets the path finder key for resolving resource paths.
 ObjectName getSharedCacheName()
          Gets the the shared cache of this client.
 boolean isCachingDisabled()
          Checks whether the caching is disabled.
 void refresh()
          Refreshes the MBean.
 void removeCache()
          Removes the cache.
 void setCachingDisabled(boolean flag)
          Sets the caching disabled flag.
 void setDefaultBaseName(String baseName)
          Sets the default base name to be applied when an explicit one is not specified.
 void setDefaultEncoding(String encoding)
          Sets the encoding to use for property files.
 void setDefaultLocale(Locale locale)
          Sets the default locale of resources.
 void setPlugInKey(String key)
          Sets the default key for pluggable resource bundles of this resource finder.
 void setPlugInKey(String baseName, String key)
          Sets the default key for pluggable resource bundles of this resource finder.
 void setResourceCheckInterval(long msecs)
          Sets the default interval for checking validity of cached resource bundles of this resource finder.
 void setResourceCheckInterval(String className, long msecs)
          Sets the class specific interval of checking validity of cached resource bundles of this resource finder.
 void setResourceKey(String key)
          Sets the path finder key for resolving resource paths.
 void setSharedCacheName(ObjectName cache)
          Sets the shared cache of this client.
 void unmanaged()
          This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, postmanaged, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultResourceFinder

public DefaultResourceFinder()
Constructs a new finder.

Method Detail

unmanaged

public void unmanaged()
               throws Exception
Description copied from interface: Manageable
This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.

Specified by:
unmanaged in interface Manageable
Overrides:
unmanaged in class Adaptee
Throws:
Exception - if the adaptee refused to be unmanaged.

isCachingDisabled

public boolean isCachingDisabled()
Description copied from interface: CacheClient
Checks whether the caching is disabled.

Specified by:
isCachingDisabled in interface CacheClient<String,Object>
Returns:
true if the caching is disabled, true otherwise.

setCachingDisabled

public void setCachingDisabled(boolean flag)
Description copied from interface: CacheClient
Sets the caching disabled flag.

Specified by:
setCachingDisabled in interface CacheClient<String,Object>
Parameters:
flag - the caching disabled flag.

expireCached

public void expireCached(long timestamp)
Description copied from interface: CacheClient
Expires all cached entries notifying them about expiration.

Specified by:
expireCached in interface CacheClient<String,Object>
Parameters:
timestamp - the timestamp of the expiration.

expireFraction

public void expireFraction(long timestamp,
                           float fraction)
Description copied from interface: CacheClient
Expires the specified fraction of cached entries notifying them about expiration.

Specified by:
expireFraction in interface CacheClient<String,Object>
Parameters:
timestamp - the timestamp of the expiration.
fraction - the fraction of entries to expire (0.0..1.0).

clearCached

public void clearCached()
Description copied from interface: CacheClient
Clears all cached entries without notifying.

Specified by:
clearCached in interface CacheClient<String,Object>

getCache

public ConcurrentMap<String,Object> getCache(boolean... create)
Description copied from interface: CacheClient
Gets and optionally creates the cache.

Specified by:
getCache in interface CacheClient<String,Object>
Parameters:
create - true to create a missing cache.
Returns:
the cache or null if disabled.

removeCache

public void removeCache()
Description copied from interface: CacheClient
Removes the cache.

Specified by:
removeCache in interface CacheClient<String,Object>

getSharedCacheName

public ObjectName getSharedCacheName()
Description copied from interface: CacheClient
Gets the the shared cache of this client.

Specified by:
getSharedCacheName in interface CacheClient<String,Object>
Returns:
the object name of the shared cache or a query.

setSharedCacheName

public void setSharedCacheName(ObjectName cache)
Description copied from interface: CacheClient
Sets the shared cache of this client. If it is not set, the default one will be used.

Specified by:
setSharedCacheName in interface CacheClient<String,Object>
Parameters:
cache - the object name of the shared cache or a query.

refresh

public void refresh()
Description copied from interface: Refreshable
Refreshes the MBean.

Specified by:
refresh in interface Refreshable

getRefreshed

public long getRefreshed()
Description copied from interface: Refreshable
Gets the last refresh timestamp.

Specified by:
getRefreshed in interface Refreshable
Returns:
the timestamp of the last refresh.

getCacheCleared

public long getCacheCleared()
Description copied from interface: ResourceFinder
Gets the timestamp of the last cache clearing or expiration.

Specified by:
getCacheCleared in interface ResourceFinder
Returns:
the timestamp of the last cache clearing.

getDefaultBaseName

public String getDefaultBaseName()
Description copied from interface: ResourceFinder
Gets the default base name to be applied when an explicit one is not specified.

Specified by:
getDefaultBaseName in interface ResourceFinder
Returns:
the default base name or null.

setDefaultBaseName

public void setDefaultBaseName(String baseName)
Description copied from interface: ResourceFinder
Sets the default base name to be applied when an explicit one is not specified.

Specified by:
setDefaultBaseName in interface ResourceFinder
Parameters:
baseName - the default base name.

getDefaultLocale

public Locale getDefaultLocale()
Description copied from interface: ResourceFinder
Gets the default locale of resources.

Specified by:
getDefaultLocale in interface ResourceFinder
Returns:
the default locale.

setDefaultLocale

public void setDefaultLocale(Locale locale)
Description copied from interface: ResourceFinder
Sets the default locale of resources. The locale also specifies the character encoding, if it is not given separately.

Specified by:
setDefaultLocale in interface ResourceFinder
Parameters:
locale - the default locale.

getDefaultEncoding

public String getDefaultEncoding()
Description copied from interface: ResourceFinder
Gets the encoding to use for property files.

Specified by:
getDefaultEncoding in interface ResourceFinder
Returns:
the encoding for property files.

setDefaultEncoding

public void setDefaultEncoding(String encoding)
Description copied from interface: ResourceFinder
Sets the encoding to use for property files. If not specified, the encoding for the corresponding locale will be applied.

Specified by:
setDefaultEncoding in interface ResourceFinder
Parameters:
encoding - the encoding for property files.

getResourceKey

public String getResourceKey()
Description copied from interface: ResourceFinder
Gets the path finder key for resolving resource paths.

Specified by:
getResourceKey in interface ResourceFinder
Returns:
the path finder key.

setResourceKey

public void setResourceKey(String key)
Description copied from interface: ResourceFinder
Sets the path finder key for resolving resource paths. The default key is PathFinder.RESOURCE.

Specified by:
setResourceKey in interface ResourceFinder
Parameters:
key - the path finder key.

getPlugInKey

public String getPlugInKey()
Description copied from interface: ResourceFinder
Gets the default key for pluggable resource bundles of this resource finder.

Specified by:
getPlugInKey in interface ResourceFinder
Returns:
the plug-in key or null.

setPlugInKey

public void setPlugInKey(String key)
Description copied from interface: ResourceFinder
Sets the default key for pluggable resource bundles of this resource finder.

Specified by:
setPlugInKey in interface ResourceFinder
Parameters:
key - the plug-in key.

getPlugInKey

public String getPlugInKey(String baseName)
Description copied from interface: ResourceFinder
Gets the class specific key for pluggable resource bundles of this resource finder.

Specified by:
getPlugInKey in interface ResourceFinder
Parameters:
baseName - the base name of the resource bundle class.
Returns:
the plug-in key or null.

setPlugInKey

public void setPlugInKey(String baseName,
                         String key)
Description copied from interface: ResourceFinder
Sets the default key for pluggable resource bundles of this resource finder.

Specified by:
setPlugInKey in interface ResourceFinder
Parameters:
baseName - the base name of the resource bundle class.
key - the plug-in key.

getPlugInKey

public String getPlugInKey(Class<?> baseClass)
Description copied from interface: ResourceFinder
Gets the most specific key for pluggable resource bundles of this resource finder.

Specified by:
getPlugInKey in interface ResourceFinder
Parameters:
baseClass - the base class of the resource bundle.
Returns:
the plug-in key or null.

getPlugInBaseName

public String getPlugInBaseName(String key)
Description copied from interface: ResourceFinder
Gets the base name of the resource bundle class associated with the specified plug-in key.

Note that if there are several base names associated with the same key, an arbitrary one of the alternatives is returned.

Specified by:
getPlugInBaseName in interface ResourceFinder
Parameters:
key - the plug-in key.
Returns:
the base name of the resource bundle class.

getResourceCheckInterval

public long getResourceCheckInterval()
Description copied from interface: ResourceFinder
Gets the default interval for checking validity of cached resource bundles of this resource finder.

Specified by:
getResourceCheckInterval in interface ResourceFinder
Returns:
the resource check interval in milliseconds.

setResourceCheckInterval

public void setResourceCheckInterval(long msecs)
Description copied from interface: ResourceFinder
Sets the default interval for checking validity of cached resource bundles of this resource finder.

Specified by:
setResourceCheckInterval in interface ResourceFinder
Parameters:
msecs - the check interval in milliseconds (-1 = only once).

getResourceCheckInterval

public long getResourceCheckInterval(String className)
Description copied from interface: ResourceFinder
Gets the class specific interval for checking validity of cached resource bundles of this resource finder.

Specified by:
getResourceCheckInterval in interface ResourceFinder
Parameters:
className - the base name of the resource bundle class.
Returns:
the resource check interval in milliseconds.

setResourceCheckInterval

public void setResourceCheckInterval(String className,
                                     long msecs)
Description copied from interface: ResourceFinder
Sets the class specific interval of checking validity of cached resource bundles of this resource finder.

Specified by:
setResourceCheckInterval in interface ResourceFinder
Parameters:
className - the base name of the resource bundle class.
msecs - the check interval in milliseconds (-1 = only once).

getResourceCheckInterval

public long getResourceCheckInterval(Class<?> baseClass)
Description copied from interface: ResourceFinder
Gets the most specific interval for checking validity of cached resource bundles of this resource finder.

Specified by:
getResourceCheckInterval in interface ResourceFinder
Parameters:
baseClass - the base class of the resource bundle.
Returns:
the resource check interval in milliseconds.

getResourceBundle

public LookupResourceBundle getResourceBundle(Locale... locale)
Description copied from interface: ResourceFinder
Gets the default resource bundle for the default base name and the specified locale.

Specified by:
getResourceBundle in interface ResourceFinder
Parameters:
locale - the locale to apply.
Returns:
the resource bundle or null.

getResourceBundle

public LookupResourceBundle getResourceBundle(String baseName,
                                              Locale... locale)
Description copied from interface: ResourceFinder
Gets the appropriate resource bundle for the given base name and specified locale.

Specified by:
getResourceBundle in interface ResourceFinder
Parameters:
baseName - the base name of the resource bundle.
locale - the locale to apply.
Returns:
the resource bundle or null.

getResourceBundle

public LookupResourceBundle getResourceBundle(String baseName,
                                              String variant,
                                              Locale... locale)
Description copied from interface: ResourceFinder
Gets the appropriate resource bundle for the given base name, specified locale and optional variant. If the optional variant is not null, the one in the locale is replaced with the given variant.

Specified by:
getResourceBundle in interface ResourceFinder
Parameters:
baseName - the base name of the resource bundle.
variant - an optional variant.
locale - the locale to apply.
Returns:
the resource bundle or null.

getResourceBundle

public LookupResourceBundle getResourceBundle(String baseName,
                                              ClassLoader loader,
                                              Locale... locale)
Description copied from interface: ResourceFinder
Gets the appropriate resource bundle for the given base name, specified locale and class loader.

Specified by:
getResourceBundle in interface ResourceFinder
Parameters:
baseName - the base name of the resource bundle.
loader - the class loader to load the resource from.
locale - the locale to apply.
Returns:
the resource bundle or null.

getResourceBundle

public LookupResourceBundle getResourceBundle(String baseName,
                                              String variant,
                                              ClassLoader loader,
                                              Locale... locale)
Description copied from interface: ResourceFinder
Gets the appropriate resource bundle for the given base name, specified locale, optional variant and class loader. If the optional variant is not null, the one in the locale is replaced with the given variant.

Specified by:
getResourceBundle in interface ResourceFinder
Parameters:
baseName - the base name of the resource bundle.
variant - an optional variant.
loader - the class loader to load the resource from.
locale - the locale to apply.
Returns:
the resource bundle or null.

getResourceBundle

protected LookupResourceBundle getResourceBundle(String baseName,
                                                 String localizedName,
                                                 ClassLoader loader,
                                                 Locale locale)
Gets the resource bundle for the given locale.

Parameters:
baseName - the base name.
localizedName - the localized name.
loader - the class loader.
locale - the locale.
Returns:
the resource bundle or null.


Copyright © 2004 The Norther Organization. All rights reserved.