com.metamatrix.connector.text
Class StringToDateTranslator

java.lang.Object
  extended by com.metamatrix.connector.text.StringToDateTranslator

public class StringToDateTranslator
extends java.lang.Object

This is a helper class for TextTranslators that can be used to translate any String that is a representation of a date to a java.util.Date object. This class is created by passing it a properties object that contains at least one property. The value of this property is a String that can be a delimited list of date format Strings. Date format Strings can be any format String that a java.text.SimpleDateFormat can be created with. There is also an optional property that defines the delimiter for the list of Date format Strings. If this property is not specified then the entire String value of the DateFormatStrings property will be used as the only format that this class can translate.

After this class is created it can the be used to translate Strings into java.util.Date object using the translateStringToDate(String) method.


Constructor Summary
StringToDateTranslator(java.util.Properties props, ConnectorLogger logger)
          This class is created by passing it a properties object that contains at least one property.
 
Method Summary
 boolean hasFormatters()
          This method is used to check the status of this translator object.
 java.util.Date translateStringToDate(java.lang.String string)
          This method is used to translate String representations of dates into java.util.Date objects using a set of formats passed into this class at creation time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringToDateTranslator

public StringToDateTranslator(java.util.Properties props,
                              ConnectorLogger logger)

This class is created by passing it a properties object that contains at least one property. The value of this property is a String that can be a delimited list of date format Strings. Date format Strings can be any format String that a java.text.SimpleDateFormat can be created with. There is also an optional property that defines the delimiter for the list of Date format Strings. If this property is not specified then the entire String value of the DateFormatStrings property will be used as the only format that this class can translate.

Note that the order of the list of date format strings is important because the translator attempts to translate the String passed to it in the order of the date format Strings in the delimited property value.

After this class is created it can the be used to translate Strings into java.util.Date object using the translateStringToDate(String) method.

 The properties that are required in construction of this class are as 
 follows:

 PropertyName: TextPropertyNames.DATE_RESULT_FORMATS
 PropertyValue: Delimited list of date format Strings: ie MM/dd/yy' 'hh:mm:ss

 PropertyName: TextPropertyNames.DATE_RESULT_FORMATS_DELIMITER
 PropertyValue: Delimiter for value of TextPropertyNames.DATE_RESULT_FORMATS
 

Method Detail

translateStringToDate

public java.util.Date translateStringToDate(java.lang.String string)
                                     throws java.text.ParseException
This method is used to translate String representations of dates into java.util.Date objects using a set of formats passed into this class at creation time. Has formatters should always be called on this class prior to the use of this method to determine whether or not there are any formatters this class can use to translate the String value passed in. If there are no formatters and this method is called, it will throw a parse Exception.

Parameters:
string - the String to be parsed into a java.util.Date
Returns:
the java.util.Date representation of the passed in String
Throws:
java.text.ParseException - if the String passed in could not be parsed

hasFormatters

public boolean hasFormatters()
This method is used to check the status of this translator object. It will return true if this translator has any 'formatters' to do parsing of Strings in the translateStringToDate() method. This method should always be called prior to using the translateStringToDate() method. If there are no formatters for the instance of this class, all calls to the translateStringToDate() method will throw a ParseException.

Returns:
true if this class has formatters to parse Strings to Dates


Copyright © 2009. All Rights Reserved.