org.hd.d.pg2k.svrCore
Class LocaleBeanBase

java.lang.Object
  extended by org.hd.d.pg2k.svrCore.LocaleBeanBase
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
LocaleBean

public class LocaleBeanBase
extends java.lang.Object
implements java.io.Serializable

Created by IntelliJ IDEA. User: DHD Date: 04-Sep-2006 Time: 16:34:48 To change this template use File | Settings | File Templates.

See Also:
Serialized Form

Field Summary
private static MemoryTools.SimpleLRUMapAutoSizeForHitRate<java.util.Locale,java.util.Locale> _cacheCommonRealLocales
          Private LRU cache from requested common locale to actual locale.
private static java.util.concurrent.ConcurrentMap<java.util.Locale,java.util.ResourceBundle> _cachedCommonBundles
          Cache mapping from the actual common bundle locale to the bundle itself.
private static int EST_COMMON_BUNDLES
          Estimated maximum number of real/used common resource bundles available; strictly positive.
protected static java.util.Locale SAFE_LOCALE
          ``Safe'' locale is the one we want all activity to default to.
private static long serialVersionUID
          Unique Serialisation class ID generated by http://random.hd.org/.
private  java.util.Locale userLocale
          Locale retrieved by setRequest, or a safe locale value; never null.
 
Constructor Summary
LocaleBeanBase()
          Public no-arg constructor for ease of use as a JavaBean.
LocaleBeanBase(java.util.Locale l)
          Public no-arg constructor for ease of use as a JavaBean.
 
Method Summary
static java.util.ResourceBundle getCommonResourceBundle(java.util.Locale l)
          Gets the (properties-only) common resource bundle for the given locale.
 java.util.Locale getLocale()
          Retrieve the current locale; never null.
 java.lang.String getLocalisedMessage(java.lang.String msgName)
          Gets the appropriate localised message from the common set.
 java.lang.String getLocalisedMessage(java.lang.String msgName, java.lang.Object... args)
          Get localised message from the common set with embedded formatting to apply to its argument(s).
private  void readObject(java.io.ObjectInputStream in)
          Deserialise.
protected  void setLocale(java.util.Locale l)
          Mechanism by which deriving classes can set the locale (never null).
 java.lang.String toString()
          Human-readable text representation; never null.
 void validateObject()
          Validate fields/state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SAFE_LOCALE

protected static final java.util.Locale SAFE_LOCALE
``Safe'' locale is the one we want all activity to default to. This locale is one that we should always be able to support.


userLocale

private volatile java.util.Locale userLocale
Locale retrieved by setRequest, or a safe locale value; never null. Volatile to allow thread-safe access without a lock.


EST_COMMON_BUNDLES

private static final int EST_COMMON_BUNDLES
Estimated maximum number of real/used common resource bundles available; strictly positive. Should ideally be a power of two a little larger than the true value, or at least of those used other than very infrequently, for maximum efficiency.

See Also:
Constant Field Values

_cachedCommonBundles

private static final java.util.concurrent.ConcurrentMap<java.util.Locale,java.util.ResourceBundle> _cachedCommonBundles
Cache mapping from the actual common bundle locale to the bundle itself. Assumed to be bounded in size by the actual concrete common bundles available.

We expect to need relatively little write concurrency, even at start-up.


_cacheCommonRealLocales

private static final MemoryTools.SimpleLRUMapAutoSizeForHitRate<java.util.Locale,java.util.Locale> _cacheCommonRealLocales
Private LRU cache from requested common locale to actual locale. Should be large enough to keep the hit rate acceptable, but otherwise effectively size-bounded with unused items purged.

Sized on the basis that there may be up to 10s of 'alias' locales for each actual supported common bundle locale, eg many 'en'/'fr'/'de'/'es' variants requested for each actually supported.


serialVersionUID

private static final long serialVersionUID
Unique Serialisation class ID generated by http://random.hd.org/.

See Also:
Constant Field Values
Constructor Detail

LocaleBeanBase

public LocaleBeanBase()
Public no-arg constructor for ease of use as a JavaBean. Sets to a safe locale.


LocaleBeanBase

public LocaleBeanBase(java.util.Locale l)
Public no-arg constructor for ease of use as a JavaBean. This defers as much work as it reasonably can.

Parameters:
l - initial locale; never null
Method Detail

getLocale

public java.util.Locale getLocale()
Retrieve the current locale; never null.


setLocale

protected void setLocale(java.util.Locale l)
Mechanism by which deriving classes can set the locale (never null).


toString

public java.lang.String toString()
Human-readable text representation; never null.

Overrides:
toString in class java.lang.Object

getCommonResourceBundle

public static java.util.ResourceBundle getCommonResourceBundle(java.util.Locale l)
Gets the (properties-only) common resource bundle for the given locale. Assume that this is safe since the bundle should be immutable.

Canonicalises the requested locale to a concrete available common bundle, and then looks that up to get the bundle.

Both parts of this lookup are cached.

Thread-safe and allows concurrency.

We do not search for class-based resources.


getLocalisedMessage

public java.lang.String getLocalisedMessage(java.lang.String msgName)
Gets the appropriate localised message from the common set. In case of a missing message this returns the key itself.

If the name is null, the result is null.


getLocalisedMessage

public java.lang.String getLocalisedMessage(java.lang.String msgName,
                                            java.lang.Object... args)
Get localised message from the common set with embedded formatting to apply to its argument(s). In case of a missing message this returns the key itself.

If the name is null, the result is null.


readObject

private void readObject(java.io.ObjectInputStream in)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Deserialise.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

validateObject

public void validateObject()
                    throws java.io.InvalidObjectException
Validate fields/state. Called in the constructor and possibly after de-serialising.

Barf if something bad is found. (Maybe allow some extra info in debug version.)

Throws:
java.io.InvalidObjectException

DHD Multimedia Gallery V1.57.21

Copyright (c) 1996-2011, Damon Hart-Davis. All rights reserved.