org.mmbase.util
Class SortedBundle

java.lang.Object
  extended by org.mmbase.util.SortedBundle

public class SortedBundle
extends Object

A bit like ResourceBundle (on which it is based), but it creates SortedMap's. The order of the entries of the Map can be influenced in tree ways. You can associate the keys with JAVA constants (and their natural ordering can be used), you can wrap the keys in a 'wrapper' (which can be of any type, the sole restriction being that there is a constructor with String argument or of the type of the assiocated JAVA constant if that happened too, and the natural order of the wrapper can be used (a wrapper of some Number type would be logical). Finally you can also explicitely specify a Comparator if no natural order is good.

Since:
MMBase-1.8
Version:
$Id: SortedBundle.java 41075 2010-02-16 13:46:53Z michiel $
Author:
Michiel Meeuwissen

Nested Class Summary
static class SortedBundle.ValueWrapper
          You can specify ValueWrapper.class as a value for the wrapper argument.
 
Field Summary
static Comparator<? super Object> NO_COMPARATOR
          Constant which can be used as an argument for getResource(java.lang.String, java.util.Locale, java.lang.ClassLoader, java.util.Map, java.lang.Class, java.util.Comparator)
static HashMap<String,Object> NO_CONSTANTSPROVIDER
          Constant which can be used as an argument for getResource(java.lang.String, java.util.Locale, java.lang.ClassLoader, java.util.Map, java.lang.Class, java.util.Comparator)
static Class<?> NO_WRAPPER
          Constant which can be used as an argument for getResource(java.lang.String, java.util.Locale, java.lang.ClassLoader, java.util.Map, java.lang.Class, java.util.Comparator)
 
Method Summary
static Object castKey(String bundleKey, Object value, Map<String,Object> constantsProvider, Class<?> wrapper)
           
protected static Object castKey(String bundleKey, Object value, Map<String,Object> constantsProvider, Class<?> wrapper, Locale locale)
          Casts a key of the bundle to the specified key-type.
static HashMap<String,Object> getConstantsProvider(Class<?> clazz)
          Returns a (serializable) Map representing all accessible static public members of given class (so, all constants).
static
<C> SortedMap<C,String>
getResource(String baseName, Locale locale, ClassLoader loader, Map<String,Object> constantsProvider, Class<?> wrapper, Comparator<? super Object> comparator)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_WRAPPER

public static final Class<?> NO_WRAPPER
Constant which can be used as an argument for getResource(java.lang.String, java.util.Locale, java.lang.ClassLoader, java.util.Map, java.lang.Class, java.util.Comparator)


NO_COMPARATOR

public static final Comparator<? super Object> NO_COMPARATOR
Constant which can be used as an argument for getResource(java.lang.String, java.util.Locale, java.lang.ClassLoader, java.util.Map, java.lang.Class, java.util.Comparator)


NO_CONSTANTSPROVIDER

public static final HashMap<String,Object> NO_CONSTANTSPROVIDER
Constant which can be used as an argument for getResource(java.lang.String, java.util.Locale, java.lang.ClassLoader, java.util.Map, java.lang.Class, java.util.Comparator)

Method Detail

getResource

public static <C> SortedMap<C,String> getResource(String baseName,
                                                  Locale locale,
                                                  ClassLoader loader,
                                                  Map<String,Object> constantsProvider,
                                                  Class<?> wrapper,
                                                  Comparator<? super Object> comparator)
Parameters:
baseName - A string identifying the resource. See ResourceBundle.getBundle(java.lang.String, java.util.Locale, java.lang.ClassLoader) for an explanation of this string.
locale - the locale for which a resource bundle is desired
loader - the class loader from which to load the resource bundle
constantsProvider - A map representing constants for the value. Can be based on a class using getConstantsProvider(Class), then the class's constants ar used to associate with the elements of this resource.
wrapper - the keys will be wrapped in objects of this type (which must have a constructor with the right type (String, or otherwise the type of the variable given by the constantsProvider), and must be Comparable. You could specify e.g. Integer.class if the keys of the map are meant to be integers. This can be null, in which case the keys will remain unwrapped (and therefore String).
comparator - the elements will be sorted (by key) using this comparator or by natural key order if this is null.
Throws:
NullPointerException - if baseName or locale is null (not if loader is null)
MissingResourceException - if no resource bundle for the specified base name can be found
IllegalArgumentExcpetion - if wrapper is not Comparable.

castKey

public static Object castKey(String bundleKey,
                             Object value,
                             Map<String,Object> constantsProvider,
                             Class<?> wrapper)

castKey

protected static Object castKey(String bundleKey,
                                Object value,
                                Map<String,Object> constantsProvider,
                                Class<?> wrapper,
                                Locale locale)
Casts a key of the bundle to the specified key-type. This type is defined by the combination of the arguments. See getResource(java.lang.String, java.util.Locale, java.lang.ClassLoader, java.util.Map, java.lang.Class, java.util.Comparator).


getConstantsProvider

public static HashMap<String,Object> getConstantsProvider(Class<?> clazz)
Returns a (serializable) Map representing all accessible static public members of given class (so, all constants).

Since:
MMBase-1.8


MMBase 2.0-SNAPSHOT - null