com.cc.framework.convert.imp
Class DateTimeConverter

java.lang.Object
  extended bycom.cc.framework.convert.imp.DateTimeConverter
All Implemented Interfaces:
Converter, StatefullConverter

public class DateTimeConverter
extends java.lang.Object
implements StatefullConverter

Converter for Date and time (as in the Java Server Faces Specification)

Version:
$Revision$
Author:
Harald Schulz

Field Summary
static java.lang.String CONVERTER_ID
          Converter Id
private  java.lang.String dateStyle
           
private static java.util.TimeZone DEFAULT_TIME_ZONE
           
private  java.util.Locale locale
           
private  java.lang.String pattern
           
private  java.lang.String timeStyle
           
private  java.util.TimeZone timeZone
           
private  java.lang.String type
           
 
Constructor Summary
DateTimeConverter()
          Default constructor
 
Method Summary
 java.lang.Object getAsObject(RequestContext context, java.lang.String value)
          Converts the given String value into the Converters Datatype
 java.lang.String getAsString(RequestContext context, java.lang.Object value)
          Converts the Object of the converters Datatype into it's String representation
private  java.text.DateFormat getDateFormat(RequestContext context, java.util.Locale locale)
          Creates a DateFormat Object from the Converter Attributes
 java.lang.String getDateStyle()
           
private  java.util.Locale getLocale(RequestContext context)
          Retrieves the Locale for this Converter
 java.lang.String getPattern()
           
private  int getStyle(java.lang.String name)
          Converts the given Date Style in one of the DateFormat Constants
 java.lang.String getTimeStyle()
           
 java.util.TimeZone getTimeZone()
           
 java.lang.String getType()
           
 void restoreState(RequestContext context, java.lang.Object state)
          Perform any processing required to restore the state from the entries in the state Object.
 java.lang.Object saveState(RequestContext context)
          Gets the state of the instance as a Serializable Object.
 void setDateStyle(java.lang.String dateStyle)
           
 void setLocale(java.util.Locale locale)
           
 void setPattern(java.lang.String pattern)
           
 void setTimeStyle(java.lang.String timeStyle)
           
 void setTimeZone(java.util.TimeZone timeZone)
           
 void setType(java.lang.String type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONVERTER_ID

public static final java.lang.String CONVERTER_ID
Converter Id

See Also:
Constant Field Values

DEFAULT_TIME_ZONE

private static final java.util.TimeZone DEFAULT_TIME_ZONE

dateStyle

private java.lang.String dateStyle

locale

private java.util.Locale locale

pattern

private java.lang.String pattern

timeStyle

private java.lang.String timeStyle

timeZone

private java.util.TimeZone timeZone

type

private java.lang.String type
Constructor Detail

DateTimeConverter

public DateTimeConverter()
Default constructor

Method Detail

getDateStyle

public java.lang.String getDateStyle()
Returns:
Predefined formatting style which determines how the date component of a date string is to be formatted and parsed. Applied only if type is "date" or "both". Valid values are "default", "short", "medium", "long", and "full". Default value is "default".

setDateStyle

public void setDateStyle(java.lang.String dateStyle)
Parameters:
dateStyle - Predefined formatting style which determines how the date component of a date string is to be formatted and parsed. Applied only if type is "date" or "both". Valid values are "default", "short", "medium", "long", and "full". Default value is "default".

setLocale

public void setLocale(java.util.Locale locale)
Parameters:
locale - Locale whose predefined styles for dates and times are used during formatting or parsing. If not specified, the Locale returned by FacesContext.getViewRoot().getLocale() will be used. Value must be either a VB expression that evaluates to a java.util.Locale instance, or a String that is valid to pass as the first argument to the constructor java.util.Locale(String language, String country). The empty string is passed as the second argument.

getPattern

public java.lang.String getPattern()
Returns:
Custom formatting pattern which determines how the date/time string should be formatted and parsed.

setPattern

public void setPattern(java.lang.String pattern)
Parameters:
pattern - Custom formatting pattern which determines how the date/time string should be formatted and parsed.

getTimeStyle

public java.lang.String getTimeStyle()
Returns:
Predefined formatting style which determines how the time component of a date string is to be formatted and parsed. Applied only if type is "time" or "both". Valid values are "default", "short", "medium", "long", and "full". Default value is "default".

setTimeStyle

public void setTimeStyle(java.lang.String timeStyle)
Parameters:
timeStyle - Predefined formatting style which determines how the time component of a date string is to be formatted and parsed. Applied only if type is "time" or "both". Valid values are "default", "short", "medium", "long", and "full". Default value is "default".

getTimeZone

public java.util.TimeZone getTimeZone()
Returns:
Time zone in which to interpret any time information in the date String. Value must be either a VB expression that evaluates to a java.util.TimeZone instance, or a String that is a timezone ID as described in the javadocs for java.util.TimeZone.getTimeZone().

setTimeZone

public void setTimeZone(java.util.TimeZone timeZone)
Parameters:
timeZone - Time zone in which to interpret any time information in the date String. Value must be either a VB expression that evaluates to a java.util.TimeVone instance, or a String that is a timezone ID as described in the javadocs for java.util.TimeZone.getTimeZone().

getType

public java.lang.String getType()
Returns:
Specifies what contents the string value will be formatted to include, or parsed expecting. Valid values are "date", "time", and "both". Default value is "date".

setType

public void setType(java.lang.String type)
Parameters:
type - Specifies what contents the string value will be formatted to include, or parsed expecting. Valid values are "date", "time", and "both". Default value is "date".

getAsObject

public java.lang.Object getAsObject(RequestContext context,
                                    java.lang.String value)
                             throws ConverterException
Description copied from interface: Converter
Converts the given String value into the Converters Datatype

Specified by:
getAsObject in interface Converter
Parameters:
context - Request Context
value - The String Value to convert
Returns:
Object of the Converters Datatype
Throws:
ConverterException - is thrown when a conversion error occurs
See Also:
Converter.getAsObject(com.cc.framework.adapter.RequestContext, java.lang.String)

getAsString

public java.lang.String getAsString(RequestContext context,
                                    java.lang.Object value)
                             throws ConverterException
Description copied from interface: Converter
Converts the Object of the converters Datatype into it's String representation

Specified by:
getAsString in interface Converter
Parameters:
context - Request Context
value - The Object to convert
Returns:
String
Throws:
ConverterException - is thrown when a conversion error occurs
See Also:
Converter.getAsString(com.cc.framework.adapter.RequestContext, java.lang.Object)

getDateFormat

private java.text.DateFormat getDateFormat(RequestContext context,
                                           java.util.Locale locale)
                                    throws ConverterException
Creates a DateFormat Object from the Converter Attributes

Parameters:
context - RequestContext
locale - The Locale to use
Returns:
DateFormat
Throws:
ConverterException - Is thrown when the Converter Attributes are not valid

getLocale

private java.util.Locale getLocale(RequestContext context)
Retrieves the Locale for this Converter

Parameters:
context - The RequestContext
Returns:
Locale

getStyle

private int getStyle(java.lang.String name)
              throws ConverterException
Converts the given Date Style in one of the DateFormat Constants

Parameters:
name - The Style Name
Returns:
One of the DateFormat Constants
Throws:
ConverterException - Is thrown when the style identifier is unknown

saveState

public java.lang.Object saveState(RequestContext context)
Description copied from interface: StatefullConverter
Gets the state of the instance as a Serializable Object. This method must not alter the state of the implementing object. In other words, after executing this code:
 Object state = component.saveState(ctx);
 
Component should be the same as before executing it.

Specified by:
saveState in interface StatefullConverter
Parameters:
context - The RequestContext object
Returns:
The return from this method must be Serializable
See Also:
StatefullConverter.saveState(com.cc.framework.adapter.RequestContext)

restoreState

public void restoreState(RequestContext context,
                         java.lang.Object state)
Description copied from interface: StatefullConverter
Perform any processing required to restore the state from the entries in the state Object.

Specified by:
restoreState in interface StatefullConverter
Parameters:
context - The RequestContext object
state - the serialized state
See Also:
StatefullConverter.restoreState(com.cc.framework.adapter.RequestContext, java.lang.Object)


Copyright © 2000-2005 SCC Informationssysteme GmbH. All Rights Reserved.