diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PassThroughLineMapper.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PassThroughLineMapper.java index bc5698efe..c5b21ddd8 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PassThroughLineMapper.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PassThroughLineMapper.java @@ -1,25 +1,30 @@ -/* - * Copyright 2006-2007 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 - * - * http://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.item.file.mapping; - -public class PassThroughLineMapper implements LineMapper{ - - public String mapLine(String line, int lineNumber) throws Exception { - return line; - } - -} +/* + * Copyright 2006-2007 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 + * + * http://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.item.file.mapping; + +/** + * Pass through {@link LineMapper} useful for passing the original + * {@link String} back directly rather than a mapped object. + * + */ +public class PassThroughLineMapper implements LineMapper{ + + public String mapLine(String line, int lineNumber) throws Exception { + return line; + } + +} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineAggregator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineAggregator.java index 05a815962..e96bd5429 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineAggregator.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineAggregator.java @@ -1,43 +1,46 @@ -/* - * Copyright 2006-2007 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 - * - * http://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.item.file.transform; - -import org.springframework.util.StringUtils; - -/** - * @author Dave Syer - * - */ -public class DelimitedLineAggregator extends ExtractorLineAggregator { - - private String delimiter = ","; - - /** - * Public setter for the delimiter. - * @param delimiter the delimiter to set - */ - public void setDelimiter(String delimiter) { - this.delimiter = delimiter; - } - - /** - * @see org.springframework.batch.item.file.transform.ExtractorLineAggregator#doAggregate(java.lang.Object[]) - */ - public String doAggregate(Object[] item) { - return StringUtils.arrayToDelimitedString(item, this.delimiter); - } - -} +/* + * Copyright 2006-2007 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 + * + * http://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.item.file.transform; + +import org.springframework.util.StringUtils; + +/** + * A {@link LineAggregator} implementation that converts an object into a + * delimited list of strings. The default delimiter is a comma. + * + * @author Dave Syer + * + */ +public class DelimitedLineAggregator extends ExtractorLineAggregator { + + private String delimiter = ","; + + /** + * Public setter for the delimiter. + * @param delimiter the delimiter to set + */ + public void setDelimiter(String delimiter) { + this.delimiter = delimiter; + } + + /** + * @see org.springframework.batch.item.file.transform.ExtractorLineAggregator#doAggregate(java.lang.Object[]) + */ + public String doAggregate(Object[] item) { + return StringUtils.arrayToDelimitedString(item, this.delimiter); + } + +} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java index 66bb095a6..8c1bf5750 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizer.java @@ -23,6 +23,9 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** + * A {@link LineTokenizer} implementation that splits the input String on a + * configurable delimiter. This implementation also supports the use of an + * escape character to escape delimiters and line endings. * * @author Rob Harrop * @author Dave Syer diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/ExtractorLineAggregator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/ExtractorLineAggregator.java index caa191ffe..2679492b0 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/ExtractorLineAggregator.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/ExtractorLineAggregator.java @@ -1,57 +1,62 @@ -/* - * Copyright 2006-2007 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 - * - * http://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.item.file.transform; - -import org.springframework.util.Assert; - -/** - * @author Dan Garrette - * @since 2.0 - */ -public abstract class ExtractorLineAggregator implements LineAggregator { - - private FieldExtractor fieldExtractor = new PassThroughFieldExtractor(); - - /** - * Public setter for the field extractor responsible for splitting an input - * object up into an array of objects. Defaults to - * {@link PassThroughFieldExtractor}. - * - * @param fieldExtractor The field extractor to set - */ - public void setFieldExtractor(FieldExtractor fieldExtractor) { - this.fieldExtractor = fieldExtractor; - } - - /** - * Extract fields from the given item using the {@link FieldExtractor} and - * then aggregate them. Null items are not allowed. - * - * @see org.springframework.batch.item.file.transform.LineAggregator#aggregate(java.lang.Object) - */ - public String aggregate(T item) { - Assert.notNull(item); - return this.doAggregate(this.fieldExtractor.extract(item)); - } - - /** - * Aggregate provided fields into single String. - * - * @param fields An array of the fields that must be aggregated - * @return aggregated string - */ - protected abstract String doAggregate(Object[] fields); -} +/* + * Copyright 2006-2007 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 + * + * http://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.item.file.transform; + +import org.springframework.util.Assert; + +/** + * An abstract {@link LineAggregator} implementation that utilizes a + * {@link FieldExtractor} to convert the incoming object to an array of its + * parts. Extending classes must decide how those parts will be aggregated + * together. + * + * @author Dan Garrette + * @since 2.0 + */ +public abstract class ExtractorLineAggregator implements LineAggregator { + + private FieldExtractor fieldExtractor = new PassThroughFieldExtractor(); + + /** + * Public setter for the field extractor responsible for splitting an input + * object up into an array of objects. Defaults to + * {@link PassThroughFieldExtractor}. + * + * @param fieldExtractor The field extractor to set + */ + public void setFieldExtractor(FieldExtractor fieldExtractor) { + this.fieldExtractor = fieldExtractor; + } + + /** + * Extract fields from the given item using the {@link FieldExtractor} and + * then aggregate them. Null items are not allowed. + * + * @see org.springframework.batch.item.file.transform.LineAggregator#aggregate(java.lang.Object) + */ + public String aggregate(T item) { + Assert.notNull(item); + return this.doAggregate(this.fieldExtractor.extract(item)); + } + + /** + * Aggregate provided fields into single String. + * + * @param fields An array of the fields that must be aggregated + * @return aggregated string + */ + protected abstract String doAggregate(Object[] fields); +} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FieldExtractor.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FieldExtractor.java index 53ed8a3b9..f5c902b3c 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FieldExtractor.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/FieldExtractor.java @@ -1,26 +1,32 @@ -/* - * Copyright 2006-2007 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 - * - * http://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.item.file.transform; - -/** - * @author Dave Syer - * - */ -public interface FieldExtractor { - - Object[] extract(T item); - -} +/* + * Copyright 2006-2007 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 + * + * http://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.item.file.transform; + +/** + * This class will convert an object to an array of its parts. + * + * @author Dave Syer + * + */ +public interface FieldExtractor { + + /** + * @param item + * @return an array containing item's parts + */ + Object[] extract(T item); + +} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/PassThroughLineAggregator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/PassThroughLineAggregator.java index e88adda30..cd3bbbb60 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/PassThroughLineAggregator.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/PassThroughLineAggregator.java @@ -1,31 +1,35 @@ -/* - * Copyright 2006-2007 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 - * - * http://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.item.file.transform; - - -public class PassThroughLineAggregator implements LineAggregator { - - /** - * Simply convert to a String with toString(). - * - * @see org.springframework.batch.item.file.transform.LineAggregator#aggregate(java.lang.Object) - */ - public String aggregate(T item) { - return item.toString(); - } - -} +/* + * Copyright 2006-2007 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 + * + * http://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.item.file.transform; + +/** + * A {@link LineAggregator} implementation that simply calls + * {@link Object#toString()} on the given object + * + */ +public class PassThroughLineAggregator implements LineAggregator { + + /** + * Simply convert to a String with toString(). + * + * @see org.springframework.batch.item.file.transform.LineAggregator#aggregate(java.lang.Object) + */ + public String aggregate(T item) { + return item.toString(); + } + +} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/PrefixMatchingCompositeLineTokenizer.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/PrefixMatchingCompositeLineTokenizer.java index ec0d2091e..93179cb1c 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/PrefixMatchingCompositeLineTokenizer.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/transform/PrefixMatchingCompositeLineTokenizer.java @@ -21,6 +21,16 @@ import java.util.LinkedHashMap; import java.util.Map; +/** + * A {@link LineTokenizer} implementation that stores a mapping of String + * prefixes to delegate {@link LineTokenizer}s. Each line tokenizied will be + * checked for its prefix. If the prefix matches a key in the map of delegates, + * then the corresponding delegate {@link LineTokenizer} will be used. + * Otherwise, the default {@link LineTokenizer} will be used. The default + * {@link LineTokenizer} can be configured in the delegate map by setting its + * corresponding prefix to the empty string. + * + */ public class PrefixMatchingCompositeLineTokenizer implements LineTokenizer { private Map tokenizers = new HashMap();