|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.stripes.format.DefaultFormatterFactory
public class DefaultFormatterFactory
Implementation of FormatterFactory
that contains a set of built-in formatters. Additional
formatters can be registered by calling add(Class, Class)
. If there is no registered
formatter for a specific class, then it attempts to find the best available formatter by
searching for a match against the target implemented interfaces, class's superclasses, and
interface superclasses.
Constructor Summary | |
---|---|
DefaultFormatterFactory()
|
Method Summary | |
---|---|
void |
add(Class<?> targetType,
Class<? extends Formatter<?>> formatterClass)
Adds a Formatter to the set of registered Formatters, overriding an existing formatter if one was registered for the type. |
protected Class<? extends Formatter<?>> |
cacheFormatterClass(Class<?> clazz,
Class<? extends Formatter<?>> formatterClass)
Add formatter class formatterClass for formatting objects of type clazz . |
protected void |
clearCache()
Clear the class and instance caches. |
protected Class<? extends Formatter<?>> |
findFormatterClass(Class<?> targetClass)
Search for a formatter class that best matches the requested class, first checking the specified class, then all the interfaces it implements, then all its superclasses and the interfaces they implement, and finally all the superclasses of the interfaces implemented by targetClass . |
protected Class<? extends Formatter<?>> |
findInInterfaces(Class<?> targetClass,
Class<?>... ifaces)
Called second by findFormatterClass(Class) , after
findInSuperclasses(Class) . |
protected Class<? extends Formatter<?>> |
findInSuperclasses(Class<?> targetClass)
Called first by findFormatterClass(Class) . |
protected Configuration |
getConfiguration()
Allows subclasses to access the stored configuration if needed. |
Formatter<?> |
getFormatter(Class<?> clazz,
Locale locale,
String formatType,
String formatPattern)
Check to see if the there is a Formatter for the specified clazz. |
protected Map<Class<?>,Class<? extends Formatter<?>>> |
getFormatters()
Gets the (rather confusing) Map of Formatter objects. |
Formatter<?> |
getInstance(Class<? extends Formatter<?>> clazz,
String formatType,
String formatPattern,
Locale locale)
Gets an instance of the Formatter class specified. |
void |
init(Configuration configuration)
Stores a reference to the configuration and configures the default formatters. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DefaultFormatterFactory()
Method Detail |
---|
public void init(Configuration configuration) throws Exception
init
in interface ConfigurableComponent
configuration
- the Configuration object being used by Stripes
Exception
- should be thrown if the component cannot be configured well enough to use.protected Configuration getConfiguration()
protected Map<Class<?>,Class<? extends Formatter<?>>> getFormatters()
public void add(Class<?> targetType, Class<? extends Formatter<?>> formatterClass)
add
in interface FormatterFactory
targetType
- the type for which the formatter will handle formattingformatterClass
- the implementation class that will handle the formattingprotected void clearCache()
add(Class, Class)
.
public Formatter<?> getFormatter(Class<?> clazz, Locale locale, String formatType, String formatPattern)
getFormatter
in interface FormatterFactory
clazz
- the type of object being formattedlocale
- the Locale into which the object should be formattedformatType
- the type of output to produce (e.g. date, time etc.)formatPattern
- a named format string, or a format pattern
protected Class<? extends Formatter<?>> findFormatterClass(Class<?> targetClass)
targetClass
.
targetClass
- the class of the object that needs to be formatted
protected Class<? extends Formatter<?>> findInSuperclasses(Class<?> targetClass)
findFormatterClass(Class)
. Search for a formatter class that best
matches the requested class, first checking the specified class, second all the interfaces it
implements, third annotations. If no match is found, repeat the process for each superclass.
targetClass
- the class of the object that needs to be formatted
protected Class<? extends Formatter<?>> findInInterfaces(Class<?> targetClass, Class<?>... ifaces)
findFormatterClass(Class)
, after
findInSuperclasses(Class)
. Search for a formatter class that best matches the
requested class by checking the superclasses of every interface implemented by
targetClass
.
targetClass
- the class of the object that needs to be formattedifaces
- an array of interfaces to search
protected Class<? extends Formatter<?>> cacheFormatterClass(Class<?> clazz, Class<? extends Formatter<?>> formatterClass)
formatterClass
for formatting objects of type clazz
.
clazz
- the type of object being formattedformatterClass
- the class of the formatter
targetType
parameterpublic Formatter<?> getInstance(Class<? extends Formatter<?>> clazz, String formatType, String formatPattern, Locale locale) throws Exception
clazz
- the Formatter type that is desired
Exception
- if there is a problem instantiating the Formatter
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |