org.springframework.binding.format.support
Class AbstractFormatter

java.lang.Object
  extended by org.springframework.binding.format.support.AbstractFormatter
All Implemented Interfaces:
Formatter
Direct Known Subclasses:
DateFormatter, LabeledEnumFormatter, NumberFormatter, PropertyEditorFormatter

public abstract class AbstractFormatter
extends java.lang.Object
implements Formatter

Abstract base class for all formatters.

Author:
Keith Donald

Constructor Summary
protected AbstractFormatter()
          Constructs a formatter.
protected AbstractFormatter(boolean allowEmpty)
          Constructs a formatter.
 
Method Summary
protected abstract  java.lang.String doFormatValue(java.lang.Object value)
          Template method subclasses should override to encapsulate formatting logic.
protected abstract  java.lang.Object doParseValue(java.lang.String formattedString, java.lang.Class targetClass)
          Template method subclasses should override to encapsulate parsing logic.
 java.lang.String formatValue(java.lang.Object value)
          Format the value.
protected  java.lang.String getEmptyFormattedValue()
          Returns the formatted form of an empty value.
protected  java.lang.Object getEmptyValue()
          Returns the empty value (resulting from parsing an empty input string).
protected  java.lang.String getExpectedFormat(java.lang.Class targetClass)
          Returns the expected string format for the given target class.
 boolean isAllowEmpty()
          Allow formatting of empty (null or blank) values?
protected  boolean isEmpty(java.lang.Object o)
          Is given object empty (null or empty string)?
 java.lang.Object parseValue(java.lang.String formattedString, java.lang.Class targetClass)
          Parse the formatted string representation of a value, restoring the value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractFormatter

protected AbstractFormatter()
Constructs a formatter.


AbstractFormatter

protected AbstractFormatter(boolean allowEmpty)
Constructs a formatter.

Parameters:
allowEmpty - allow formatting of empty (null or blank) values?
Method Detail

isAllowEmpty

public boolean isAllowEmpty()
Allow formatting of empty (null or blank) values?


formatValue

public final java.lang.String formatValue(java.lang.Object value)
Description copied from interface: Formatter
Format the value.

Specified by:
formatValue in interface Formatter
Parameters:
value - the value to format
Returns:
the formatted string, fit for display in a UI

doFormatValue

protected abstract java.lang.String doFormatValue(java.lang.Object value)
Template method subclasses should override to encapsulate formatting logic.

Parameters:
value - the value to format
Returns:
the formatted string representation

getEmptyFormattedValue

protected java.lang.String getEmptyFormattedValue()
Returns the formatted form of an empty value. Default implementation just returns the empty string.


parseValue

public final java.lang.Object parseValue(java.lang.String formattedString,
                                         java.lang.Class targetClass)
                                  throws InvalidFormatException
Description copied from interface: Formatter
Parse the formatted string representation of a value, restoring the value.

Specified by:
parseValue in interface Formatter
Parameters:
formattedString - the formatted string representation
targetClass - the target class to convert the formatted value to
Returns:
the parsed value
Throws:
InvalidFormatException - the string was in an invalid form

doParseValue

protected abstract java.lang.Object doParseValue(java.lang.String formattedString,
                                                 java.lang.Class targetClass)
                                          throws InvalidFormatException,
                                                 java.text.ParseException
Template method subclasses should override to encapsulate parsing logic.

Parameters:
formattedString - the formatted string to parse
Returns:
the parsed value
Throws:
InvalidFormatException - an exception occured parsing
java.text.ParseException - when parse exceptions occur

getEmptyValue

protected java.lang.Object getEmptyValue()
Returns the empty value (resulting from parsing an empty input string). This default implementation just returns null.


getExpectedFormat

protected java.lang.String getExpectedFormat(java.lang.Class targetClass)
Returns the expected string format for the given target class. The default implementation just returns null.


isEmpty

protected boolean isEmpty(java.lang.Object o)
Is given object empty (null or empty string)?



Copyright � 2004-2007. All Rights Reserved.