org.scopemvc.util.convertor
Class DateStringConvertor

java.lang.Object
  |
  +--org.scopemvc.util.convertor.NullStringConvertor
        |
        +--org.scopemvc.util.convertor.DateStringConvertor
All Implemented Interfaces:
StringConvertor
Direct Known Subclasses:
DateTimeStringConvertor, TimeStringConvertor

public class DateStringConvertor
extends NullStringConvertor

String convertor for type java.util.Date. The Time part of Date instances are ignored. See DateTimeStringConvertor and TimeStringConvertor.

It uses one java.text.DateFormat for converting into String and set of DateFormats for parsing. Parsing formats are successively used to try to parse until one is successful.

Formats are picked up from config (see DefaultScopeConfig for details) or if none in config, the default formatter is:

 DateFormat.getDateInstance(DateFormat.MEDIUM)
 
and default parsers are:
 DateFormat.getDateInstance(DateFormat.FULL);
 DateFormat.getDateInstance(DateFormat.LONG);
 DateFormat.getDateInstance(DateFormat.MEDIUM);
 DateFormat.getDateInstance(DateFormat.SHORT);
 
Note: the default parsing set is initialized during class loading and based on default platform locale. If application uses other locales, there will be need to set parsing objects explicitly.

Version:
$Revision: 1.8 $ $Date: 2002/09/05 15:41:46 $
Author:
Daniel Michalik
, Steve Meyfroidt
See Also:
DateTimeStringConvertor, TimeStringConvertor

Constructor Summary
DateStringConvertor()
          Creates new DateStringConvertor.
DateStringConvertor(java.text.DateFormat inFormatter, java.text.DateFormat[] inParsers)
          Creates new DateStringConvertor with specified formatter and parsers.
 
Method Summary
protected  java.text.DateFormat[] getDefaultParsers()
          Gets the default parsers
protected  void initDefaults()
          TODO: document the method
 void setFormatter(java.lang.Object inFormat)
          Sets format used by this convertor for converting Dates into Strings.
 void setParsers(java.lang.Object[] inParsers)
          Set parser array for this converter.
 java.lang.Object stringAsValue(java.lang.String inString)
          Returns instance of java.util.Date.Parsing formats are successively used to try to parse until one is successful or exception is thrown.
 java.lang.String valueAsString(java.lang.Object inValue)
          Formats object into String.
 
Methods inherited from class org.scopemvc.util.convertor.NullStringConvertor
getNullAsString, isNull, setNullAsString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateStringConvertor

public DateStringConvertor()
Creates new DateStringConvertor. If formats and parsers are specified in config then use those else use current locale default format and platform locale default parsers.


DateStringConvertor

public DateStringConvertor(java.text.DateFormat inFormatter,
                           java.text.DateFormat[] inParsers)
Creates new DateStringConvertor with specified formatter and parsers.

Parameters:
inFormatter - TODO: Describe the Parameter
inParsers - TODO: Describe the Parameter
Method Detail

setFormatter

public final void setFormatter(java.lang.Object inFormat)
Sets format used by this convertor for converting Dates into Strings.

Parameters:
inFormat - The new formatter value
Throws:
java.lang.IllegalArgumentException - if passed format is null or not a DateFormat or not a String.

setParsers

public final void setParsers(java.lang.Object[] inParsers)
Set parser array for this converter.

Parameters:
inParsers - The new parsers value
Throws:
java.lang.IllegalArgumentException - if the array is null or contains a non-String or non-DateFormat object.

stringAsValue

public java.lang.Object stringAsValue(java.lang.String inString)
                               throws java.lang.IllegalArgumentException
Returns instance of java.util.Date.Parsing formats are successively used to try to parse until one is successful or exception is thrown.

Empty, null and getNullAsString() strings are converted into null.

Parameters:
inString - TODO: Describe the Parameter
Returns:
TODO: Describe the Return Value
Throws:
java.lang.IllegalArgumentException - if can't convert from String using current DateFormat

valueAsString

public java.lang.String valueAsString(java.lang.Object inValue)
                               throws java.lang.IllegalArgumentException
Description copied from interface: StringConvertor
Formats object into String. It never return a null. Implementing class can offer posibility to set string representation of null (such as "null" or ""), however default representation should be "". Slightly different null handling is performed in StringStringConvertor class.

Parameters:
inValue - TODO: Describe the Parameter
Returns:
text representation of Date object. For null argument is called method getNullAsString
Throws:
java.lang.IllegalArgumentException - it argument is not instance of java.util.Date

getDefaultParsers

protected java.text.DateFormat[] getDefaultParsers()
Gets the default parsers

Returns:
The defaultParsers value

initDefaults

protected void initDefaults()
TODO: document the method



Copyright © 2000-2002 The Scope Team. All Rights Reserved.