net.sourceforge.stripes.format
Interface Formatter<T>

All Known Implementing Classes:
DateFormatter, EnumFormatter, NumberFormatter, ObjectFormatter

public interface Formatter<T>

Interface that is used to provide a relatively simple formatting interface to the rest of the system. Designed to wrap the complexity of the java.text format classes in an interface that can take two (or three if you include Locale) parameters from tags and apply formats in an intelligent way.

In terms of lifecycle, a formatter will be instantiated, have setFormatType(), setFormatString() and setLocale() called in rapid succession. If no values were supplied, setFormatType() and setFormatString() may not be called - and implementations should select reasonable defaults. Locale will always be provided. After the setters have been called, init() will be called, and the Formatter should use this opportunity to construct any internal objects necessary to perform formatting. The format() method will then be called one or more times before the Formatter is eventually dereferenced.

Author:
Tim Fennell

Method Summary
 String format(T input)
          Formats the supplied value as a String.
 void init()
          Called once all setters have been invoked, to allow Formatter to prepare itself.
 void setFormatPattern(String formatPattern)
          Sets a named format, or format pattern to use in formatting objects.
 void setFormatType(String formatType)
          Sets the type of format that should be created.
 void setLocale(Locale locale)
          Sets the Locale into which the object should be formatted.
 

Method Detail

setFormatType

void setFormatType(String formatType)
Sets the type of format that should be created.


setFormatPattern

void setFormatPattern(String formatPattern)
Sets a named format, or format pattern to use in formatting objects.


setLocale

void setLocale(Locale locale)
Sets the Locale into which the object should be formatted.


init

void init()
Called once all setters have been invoked, to allow Formatter to prepare itself.


format

String format(T input)
Formats the supplied value as a String. If the value cannot be formatted because it is an inappropriate type, or because faulty pattern information was supplied, should fail loudly by throwing a RuntimeException or subclass thereof. Therefore this method should never return null.

Parameters:
input - an object of a type that the formatter knows how to format
Returns:
a non-null, String version of the input, formatted for the chosen locale


? Copyright 2005-2006, Stripes Development Team.