Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.scopemvc.util.convertor
Class DateStringConvertor  view DateStringConvertor download DateStringConvertor.java

java.lang.Object
  extended byorg.scopemvc.util.convertor.NullStringConvertor
      extended byorg.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 org.scopemvc.util.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.5 $ $Date: 2002/01/26 09:46:20 $

Field Summary
private static java.text.DateFormat[] defaultParsers
           
private  java.text.DateFormat formatter
           
private static org.apache.commons.logging.Log LOG
           
private  java.text.DateFormat[] parsers
           
 
Fields inherited from class org.scopemvc.util.convertor.NullStringConvertor
 
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()
           
protected  void initDefaults()
           
 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
 

Field Detail

LOG

private static final org.apache.commons.logging.Log LOG

formatter

private java.text.DateFormat formatter

parsers

private java.text.DateFormat[] parsers

defaultParsers

private static final java.text.DateFormat[] defaultParsers
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.

Method Detail

initDefaults

protected void initDefaults()

getDefaultParsers

protected java.text.DateFormat[] getDefaultParsers()

setFormatter

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


setParsers

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


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() 55 strings are converted into null.


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.