org.springframework.batch.core.converter
Class DefaultJobParametersConverter

java.lang.Object
  extended by org.springframework.batch.core.converter.DefaultJobParametersConverter
All Implemented Interfaces:
JobParametersConverter

public class DefaultJobParametersConverter
extends Object
implements JobParametersConverter

Converter for JobParameters instances using a simple naming convention for property keys. Key names ending with "(<type>)" where type is one of string, date, long are converted to the corresponding type. The default type is string. E.g.

 schedule.date(date)=2007/12/11
 department.id(long)=2345
 
The literal values are converted to the correct type using the default Spring strategies, augmented if necessary by the custom editors provided.

Author:
Dave Syer

Field Summary
static String DATE_TYPE
           
static String LONG_TYPE
           
static String STRING_TYPE
           
 
Constructor Summary
DefaultJobParametersConverter()
           
 
Method Summary
 JobParameters getJobParameters(Properties props)
          Check for suffix on keys and use those to decide how to convert the value.
 Properties getProperties(JobParameters params)
          Use the same suffixes to create properties (omitting the string suffix because it is the default).
 void setDateFormat(DateFormat dateFormat)
          Public setter for injecting a date format.
 void setNumberFormat(NumberFormat numberFormat)
          Public setter for the NumberFormat.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATE_TYPE

public static final String DATE_TYPE
See Also:
Constant Field Values

STRING_TYPE

public static final String STRING_TYPE
See Also:
Constant Field Values

LONG_TYPE

public static final String LONG_TYPE
See Also:
Constant Field Values
Constructor Detail

DefaultJobParametersConverter

public DefaultJobParametersConverter()
Method Detail

getJobParameters

public JobParameters getJobParameters(Properties props)
Check for suffix on keys and use those to decide how to convert the value.

Specified by:
getJobParameters in interface JobParametersConverter
Parameters:
props - the runtime parameters in the form of String literals.
Returns:
a JobParameters properties converted to the correct types.
Throws:
IllegalArgumentException - if a number or date is passed in that cannot be parsed, or cast to the correct type.
See Also:
JobParametersConverter.getJobParameters(java.util.Properties)

getProperties

public Properties getProperties(JobParameters params)
Use the same suffixes to create properties (omitting the string suffix because it is the default).

Specified by:
getProperties in interface JobParametersConverter
Returns:
a representation of the parameters as properties
See Also:
JobParametersConverter.getProperties(org.springframework.batch.core.JobParameters)

setDateFormat

public void setDateFormat(DateFormat dateFormat)
Public setter for injecting a date format.

Parameters:
dateFormat - a DateFormat, defaults to "yyyy/MM/dd"

setNumberFormat

public void setNumberFormat(NumberFormat numberFormat)
Public setter for the NumberFormat. Used to parse longs, so must not contain decimal place (e.g. use "#" or "#,###").

Parameters:
numberFormat - the NumberFormat to set


Copyright © 2009 SpringSource. All Rights Reserved.