to.etc.webapp.nls
Class BundleStack

java.lang.Object
  extended by to.etc.webapp.nls.BundleBase
      extended by to.etc.webapp.nls.BundleStack
All Implemented Interfaces:
IBundle, NlsMessageProvider

@Immutable
public class BundleStack
extends BundleBase
implements IBundle

Represents a stack of message bundles that behaves as a single message bundle. Keys are looked up from the top to the bottom, and the 1st matching one is returned.

Author:
Frits Jalvingh Created on Dec 31, 2010

Constructor Summary
BundleStack(java.util.List<? extends NlsMessageProvider> reflist)
           
BundleStack(NlsMessageProvider[] bundleStack)
           
 
Method Summary
static BundleStack createStack(java.lang.Class<?> clz)
          Create a bundle stack for the specified class.
 java.lang.String findMessage(java.util.Locale loc, java.lang.String code)
          Locate the specified key for the specified locale.
 
Methods inherited from class to.etc.webapp.nls.BundleBase
formatMessage, getString, getString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface to.etc.webapp.nls.IBundle
formatMessage, getString, getString
 

Constructor Detail

BundleStack

public BundleStack(@Nonnull
                   NlsMessageProvider[] bundleStack)

BundleStack

public BundleStack(@Nonnull
                   java.util.List<? extends NlsMessageProvider> reflist)
Method Detail

createStack

@Nullable
public static BundleStack createStack(java.lang.Class<?> clz)
Create a bundle stack for the specified class. For every class in that class's hierarchy including the class itself, it tries to find both "classname" and "messages" as bundle names inside the class' package dir. When found this is added to the list of bundles for the class. The parent lookup stops at any base class that is part of the "java." or "javax." hierarchy. It only follows classes; interfaces are not followed, and it is illegal to pass an interface as the class parameter.

If no bundles are located at all this returns null.

This makes message bundles follow the same hierarchy as the classes itself, and allows classes that extend other classes to also "extend" the messages for the base class.

Parameters:
clz -
Returns:

findMessage

public java.lang.String findMessage(java.util.Locale loc,
                                    java.lang.String code)
Locate the specified key for the specified locale. This does fallback, meaning that if the exact locale is not matched it will try a less restrictive one, until the empty (default) locale has been reached. The first match is returned; if not even the empty locale returns a match this returns null.

Specified by:
findMessage in interface NlsMessageProvider
Specified by:
findMessage in class BundleBase
Returns: