org.mmbase.util
Class LocalizedEntryListFactory

java.lang.Object
  extended byorg.mmbase.util.LocalizedEntryListFactory
All Implemented Interfaces:
Cloneable, Serializable

public class LocalizedEntryListFactory
extends Object
implements Serializable, Cloneable

These factories can produce Collections based on a Locale (The get(java.util.Locale) method is essential). The other methods besides get are methods to define these lists. There are two ways to add entries to the produced collections. The first one is to explicitely add them, using the add(java.util.Locale, java.io.Serializable, java.io.Serializable) method. This gives precise control, and the collections can have different orders for different languages. The size of the collections are always the same, so if for a certain locale less entries are added, these are completed with the unused keys. If for a certain locale no entries are added, it will behave itself like as the default locale of LocalizedString.getDefault(). It is also possible to add entire 'bundles'. For this use addBundle(java.lang.String, java.lang.ClassLoader, java.lang.Class, java.lang.Class, java.util.Comparator). When a Collection instance for a certain Locale is requested these informations are used to call SortedBundle.getResource(java.lang.String, java.util.Locale, java.lang.ClassLoader, java.util.Map, java.lang.Class, java.util.Comparator). It is possible to mix both methods, so having an enumeration partially defined by a bundle, partially by explicit values, though this is not recommended.

Since:
MMBase-1.8
Version:
$Id: LocalizedEntryListFactory.java,v 1.38 2006/04/19 20:02:28 michiel Exp $
Author:
Michiel Meeuwissen
See Also:
Serialized Form

Constructor Summary
LocalizedEntryListFactory()
           
 
Method Summary
protected  List add(Locale locale, Object entry)
          Add entry to 'localized'
 Map.Entry add(Locale locale, Serializable key, Serializable value)
          Adds a value for a certain key and Locale
 void addBundle(String baseName, ClassLoader classLoader, Class constantsProvider, Class wrapper, Comparator comparator)
          Adds a bundle, to the (current) end of all maintained collections.
 void addQuery(Locale locale, Document queryElement)
           
 Object castKey(Object key)
           
 Object castKey(Object key, Cloud cloud)
          Since keys may be somehow wrapped, you can also 'unwrap' by this.
 void clear()
          Clears all added keys, bundles and queries.
 Object clone()
           
 void fillFromXml(Element enumerationElement, Class wrapperDefault)
          Given a certain DOM parent element, it configures this LocalizedEntryListFactory with sub tags of type 'entry' and 'query'
 List get(Locale locale)
          Defaulting version of get(Locale, Cloud).
 List get(Locale locale, Cloud cloud)
          Returns a Collection of Map.Entries for the given Locale.
protected  Cloud getCloud(Locale locale)
           
 boolean isEmpty()
           
static void main(String[] argv)
          For testing only.
 int size()
           
 int size(Cloud cloud)
          The size of the collections returned by get(java.util.Locale)
 String toString()
           
 Element toXml()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LocalizedEntryListFactory

public LocalizedEntryListFactory()
Method Detail

isEmpty

public boolean isEmpty()

add

public Map.Entry add(Locale locale,
                     Serializable key,
                     Serializable value)
Adds a value for a certain key and Locale

Returns:
The created Map.Entry.

add

protected List add(Locale locale,
                   Object entry)
Add entry to 'localized'

Parameters:
entry - the object, which has not Locale support of itself (Entry, DocumentSerializable)
locale - Can be null too, in which case the default locale is used
Returns:
List of currently unused keys for this locale.

addBundle

public void addBundle(String baseName,
                      ClassLoader classLoader,
                      Class constantsProvider,
                      Class wrapper,
                      Comparator comparator)
Adds a bundle, to the (current) end of all maintained collections. Actually, only the definition of the bundle is added, it is instantiated only later, when requested for a specific locale.


addQuery

public void addQuery(Locale locale,
                     Document queryElement)

get

public List get(Locale locale)
Defaulting version of get(Locale, Cloud). Using default anonymous cloud.


getCloud

protected Cloud getCloud(Locale locale)

get

public List get(Locale locale,
                Cloud cloud)
Returns a Collection of Map.Entries for the given Locale. The collection is kind of 'virtual', it only reflects the underlying memory structures. This collection does have a well defined iteration order.

Parameters:
locale - The locale of null for the default locale.
cloud - The cloud to use. Can be null if no queries added (see addQuery(java.util.Locale, org.w3c.dom.Document)). If Locale is null, but cloud isn't, the locale of the cloud is used.

size

public int size(Cloud cloud)
The size of the collections returned by get(java.util.Locale)


size

public int size()

castKey

public Object castKey(Object key)

castKey

public Object castKey(Object key,
                      Cloud cloud)
Since keys may be somehow wrapped, you can also 'unwrap' by this. If e.g. a constants provider was used, that values can be indicated by the name of the constants and this method casts to the value.


clone

public Object clone()

clear

public void clear()
Clears all added keys, bundles and queries.


fillFromXml

public void fillFromXml(Element enumerationElement,
                        Class wrapperDefault)
Given a certain DOM parent element, it configures this LocalizedEntryListFactory with sub tags of type 'entry' and 'query'


toXml

public Element toXml()

toString

public String toString()

main

public static void main(String[] argv)
For testing only.



MMBase build 1.8.1.20060716