nl.openedge.baritus
Class ConverterRegistry

java.lang.Object
  extended bynl.openedge.baritus.ConverterRegistry

public final class ConverterRegistry
extends java.lang.Object

Global registry for converters. This serves as the alternative for ConvertUtils. We use this instead of ConvertUtils for the following reasons:

Author:
Eelco Hillenius

Method Summary
 void clear()
          clear all registrations
 void deregister(java.lang.Class clazz)
          Remove any registered Converter for the specified destination Class.
 void deregister(java.lang.Class clazz, java.util.Locale locale)
          Remove any registered Converter for the specified destination Class and Locale.
 void deregister(LocaleConverter converter)
          Remove the instances of registered LocaleConverter
 void deregister(java.lang.String key)
          Remove any registered Formatter for the specified key
 void deregister(java.lang.String key, java.util.Locale locale)
          deregister a global formatter with the given key and locale
 void deregisterByConverterClass(java.lang.Class clazz)
          Remove all instances registered Converter by class of converter
static ConverterRegistry getInstance()
          access to singleton
static boolean isReturnNoopConverterWhenNotFound()
          Whether to return a noopConverter as a fallback.
 Converter lookup(java.lang.Class clazz)
          Look up and return any registered Converter for the specified destination class.
 Converter lookup(java.lang.Class clazz, java.util.Locale locale)
          Look up and return any registered Converter for the specified destination class and locale.
 Formatter lookup(java.lang.String key)
          lookup a globally registered formatter
 Formatter lookup(java.lang.String key, java.util.Locale locale)
          Look up and return any registered Formatter for the specified destination key and locale; if there is no registered Formatter, return null.
 void register(Converter converter, java.lang.Class clazz)
          Register a custom Converter for the specified destination Class, replacing any previously registered Converter.
 void register(Formatter formatter, java.lang.String key)
          register a global formatter with the given key
 void register(LocaleConverter converter, java.lang.Class clazz)
          Register a custom LocaleConverter for the specified destination Class, replacing any previously registered Converter.
 void register(LocaleConverter converter, java.lang.Class clazz, java.util.Locale locale)
          Register a custom LocaleConverter for the specified destination Class, replacing any previously registered Converter.
 void register(LocaleFormatter formatter, java.lang.String key)
          register a global locale aware formatter with the given key
 void register(LocaleFormatter formatter, java.lang.String key, java.util.Locale locale)
          register a global locale aware formatter with the given key and locale
static void setReturnNoopConverterWhenNotFound(boolean b)
          Whether to return a noopConverter as a fallback.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ConverterRegistry getInstance()
access to singleton

Returns:
ConverterRegistry singleton instance

register

public void register(Converter converter,
                     java.lang.Class clazz)
Register a custom Converter for the specified destination Class, replacing any previously registered Converter.

Parameters:
converter - Converter to be registered
clazz - Destination class for conversions performed by this Converter

register

public void register(LocaleConverter converter,
                     java.lang.Class clazz)
Register a custom LocaleConverter for the specified destination Class, replacing any previously registered Converter.

Parameters:
converter - LocaleConverter to be registered
clazz - Destination class for conversions performed by this Converter

register

public void register(LocaleConverter converter,
                     java.lang.Class clazz,
                     java.util.Locale locale)
Register a custom LocaleConverter for the specified destination Class, replacing any previously registered Converter.

Parameters:
converter - LocaleConverter to be registered
clazz - Destination class for conversions performed by this Converter
locale - Locale class

register

public void register(Formatter formatter,
                     java.lang.String key)
register a global formatter with the given key

Parameters:
formatter - the formatter
key - the key to register the instance of Formatter with

register

public void register(LocaleFormatter formatter,
                     java.lang.String key,
                     java.util.Locale locale)
register a global locale aware formatter with the given key and locale

Parameters:
formatter - the formatter
key - the key to register the instance of Formatter with
locale - the locale

register

public void register(LocaleFormatter formatter,
                     java.lang.String key)
register a global locale aware formatter with the given key

Parameters:
formatter - the formatter
key - the key to register the instance of Formatter with

deregister

public void deregister(java.lang.Class clazz,
                       java.util.Locale locale)
Remove any registered Converter for the specified destination Class and Locale.

Parameters:
clazz - Class for which to remove a registered Converter

deregister

public void deregister(java.lang.Class clazz)
Remove any registered Converter for the specified destination Class.

Parameters:
clazz - Class for which to remove a registered Converter

deregisterByConverterClass

public void deregisterByConverterClass(java.lang.Class clazz)
Remove all instances registered Converter by class of converter

Parameters:
clazz - Class of converter to remove. Removes all subclasses as well.

deregister

public void deregister(LocaleConverter converter)
Remove the instances of registered LocaleConverter

Parameters:
converter - instance of converter to remove

deregister

public void deregister(java.lang.String key)
Remove any registered Formatter for the specified key

Parameters:
key - key for which to remove a registered Formatter

deregister

public void deregister(java.lang.String key,
                       java.util.Locale locale)
deregister a global formatter with the given key and locale

Parameters:
key - the key of the formatter
locale - the locale

clear

public void clear()
clear all registrations


lookup

public Formatter lookup(java.lang.String key)
lookup a globally registered formatter

Parameters:
key - key of formatter
Returns:
Formatter instance of Formatter that was registered with the specified key or null if not found

lookup

public Converter lookup(java.lang.Class clazz)
                 throws java.lang.NoSuchMethodException,
                        java.lang.IllegalArgumentException,
                        java.lang.InstantiationException,
                        java.lang.IllegalAccessException,
                        java.lang.reflect.InvocationTargetException
Look up and return any registered Converter for the specified destination class. If there is no registered Converter, return an instance of NoopConverter if returnNoopConverterWhenNotFound == true or else null.

Parameters:
clazz - Class for which to return a registered Converter
Returns:
Converter converter
Throws:
java.lang.NoSuchMethodException
java.lang.IllegalArgumentException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

lookup

public Converter lookup(java.lang.Class clazz,
                        java.util.Locale locale)
                 throws java.lang.NoSuchMethodException,
                        java.lang.IllegalArgumentException,
                        java.lang.InstantiationException,
                        java.lang.IllegalAccessException,
                        java.lang.reflect.InvocationTargetException
Look up and return any registered Converter for the specified destination class and locale. If there is no registered Converter, return an instance of NoopConverter if returnNoopConverterWhenNotFound == true or else null. Precedence: if a locale is given the first search is for a converter that was registered for the given type and locale. If it is not found, the second search is for any converter of the type LocaleConverter that was registered for the given type. If it is found, a new instance will be created for the given locale, the pattern will be copied if possible and the newly instantiated converter will be registered for the given type and locale (and thus will be found at the first search next time). If it is not found, the search is the same as when no locale was given (locale == null): the 'normal', not localized registry will be searched for an entry with the given type. If still no Converter is found after this, and returnNoopConverterWhenNotFound is true an instance of NoopConverter is returned, so that clients allways get a valid converter. If returnNoopConverterWhenNotFound is false, null will be returned.

Parameters:
clazz - Class for which to return a registered Converter
locale - The Locale
Returns:
Converter converter
Throws:
java.lang.NoSuchMethodException
java.lang.IllegalArgumentException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

lookup

public Formatter lookup(java.lang.String key,
                        java.util.Locale locale)
                 throws java.lang.NoSuchMethodException,
                        java.lang.IllegalArgumentException,
                        java.lang.InstantiationException,
                        java.lang.IllegalAccessException,
                        java.lang.reflect.InvocationTargetException
Look up and return any registered Formatter for the specified destination key and locale; if there is no registered Formatter, return null. Precedence: if a locale is given the first search is for a formatter that was registered for the given type and locale. If it is not found, the second search is for any formatter of the type LocaleFormatter that was registered for the given key. If it is found, a new instance will be created for the given locale and the newly instantiated formatter will be registered for the given key and locale (and thus will be found at the first search next time). If it is not found, the search is the same as when no locale was given (locale == null): the 'normal', not localized registry will be searched for an entry with the given key. If this is not found either, null will be returned.

Parameters:
key - key that the formatter was registered with
locale - the Locale
Throws:
java.lang.NoSuchMethodException
java.lang.IllegalArgumentException
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

isReturnNoopConverterWhenNotFound

public static boolean isReturnNoopConverterWhenNotFound()
Whether to return a noopConverter as a fallback.

Returns:
boolean when true, a noopConverter is returned as a fallback. When false, null is returned

setReturnNoopConverterWhenNotFound

public static void setReturnNoopConverterWhenNotFound(boolean b)
Whether to return a noopConverter as a fallback. false, null is returned

Parameters:
b - when true, a noopConverter is returned as a fallback. When false, null is returned


Copyright © 2003-2004 Open Edge. All Rights Reserved.