Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2006-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.converter;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParameter;
import org.springframework.batch.core.JobParameter.ParameterType;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
/**
* Converter for {@link JobParameters} instances using a simple naming
* convention for property keys. Key names that are prefixed with a - are
* considered non-identifying and will not contribute to the identity of a
* {@link JobInstance}. 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.
*
*
*
* The literal values are converted to the correct type using the default Spring
* strategies, augmented if necessary by the custom editors provided.
*
*
*
* If you need to be able to parse and format local-specific dates and numbers,
* you can inject formatters ({@link #setDateFormat(DateFormat)} and
* {@link #setNumberFormat(NumberFormat)}).
*
* @author Dave Syer
* @author Michael Minella
* @author Mahmoud Ben Hassine
*
*/
public class DefaultJobParametersConverter implements JobParametersConverter {
public static final String DATE_TYPE = "(date)";
public static final String STRING_TYPE = "(string)";
public static final String LONG_TYPE = "(long)";
private static final String DOUBLE_TYPE = "(double)";
private static final String NON_IDENTIFYING_FLAG = "-";
private static final String IDENTIFYING_FLAG = "+";
private static NumberFormat DEFAULT_NUMBER_FORMAT = NumberFormat.getInstance(Locale.US);
private DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
private NumberFormat numberFormat = DEFAULT_NUMBER_FORMAT;
private final NumberFormat longNumberFormat = new DecimalFormat("#");
/**
* Check for suffix on keys and use those to decide how to convert the
* value.
*
* @throws IllegalArgumentException if a number or date is passed in that
* cannot be parsed, or cast to the correct type.
*
* @see org.springframework.batch.core.converter.JobParametersConverter#getJobParameters(java.util.Properties)
*/
@Override
public JobParameters getJobParameters(@Nullable Properties props) {
if (props == null || props.isEmpty()) {
return new JobParameters();
}
JobParametersBuilder propertiesBuilder = new JobParametersBuilder();
for (Iterator> it = props.entrySet().iterator(); it.hasNext();) {
Entry