Purge ItemProcessor

This commit is contained in:
dsyer
2008-01-29 09:13:47 +00:00
parent 0e27ea6660
commit 63594415ca
63 changed files with 196 additions and 216 deletions

View File

@@ -30,10 +30,10 @@ import java.util.Properties;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.io.exception.BatchEnvironmentException;
import org.springframework.batch.io.file.transform.Converter;
import org.springframework.batch.io.support.AbstractTransactionalIoSource;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.ResourceLifecycle;
import org.springframework.batch.item.writer.ItemTransformer;
import org.springframework.batch.restart.GenericRestartData;
import org.springframework.batch.restart.RestartData;
import org.springframework.batch.restart.Restartable;
@@ -64,16 +64,6 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
ItemWriter, ResourceLifecycle, Restartable, StatisticsProvider, InitializingBean,
DisposableBean {
/**
* @author dsyer
*
*/
public static class BooleanHolder {
public boolean value;
}
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
public static final String WRITTEN_STATISTICS_NAME = "written";
@@ -90,12 +80,20 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
private OutputState state = new OutputState();
private Converter converter = new Converter() {
public Object convert(Object input) {
private ItemTransformer transformer = new ItemTransformer() {
public Object transform(Object input) {
return "" + input;
}
};
private static class BooleanHolder {
public boolean value;
}
/**
* Assert that mandatory properties (resource) are set.
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception {
Assert.notNull(resource);
File file = resource.getFile();
@@ -106,10 +104,10 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
* Public setter for the converter. If not-null this will be used to convert
* the input data before it is output.
*
* @param converter the converter to set
* @param transformer the converter to set
*/
public void setConverter(Converter converter) {
this.converter = converter;
public void setTransformer(ItemTransformer transformer) {
this.transformer = transformer;
}
/**
@@ -152,17 +150,19 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
*
* @param data Object (a String or Object that can be converted) to be
* written to output stream
* @throws Exception if the transformer or file output fail
*/
public void write(Object data) {
convertAndWrite(data, new BooleanHolder());
public void write(Object data) throws Exception {
transformAndWrite(data, new BooleanHolder());
}
/**
* Convert the date to a format that can be output and then write it out.
* @param data
* @param converted
* @throws Exception
*/
private void convertAndWrite(Object data, BooleanHolder converted) {
private void transformAndWrite(Object data, BooleanHolder converted) throws Exception {
if (data instanceof Collection) {
converted.value = false;
@@ -190,7 +190,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
else if (!converted.value) {
// (recursive)
converted.value = true;
convertAndWrite(converter.convert(data), converted);
transformAndWrite(transformer.transform(data), converted);
return;
}
else {

View File

@@ -19,6 +19,8 @@ package org.springframework.batch.io.file.transform;
* Generic converter interface for transforming an object into another form for
* output or after input.
*
* TODO: replace with ItemTransformer
*
* @author Dave Syer
*
*/

View File

@@ -1,36 +0,0 @@
/*
* 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;
/**
* @author Dave Syer
*
*/
public interface ItemProcessor {
/**
* Process the supplied data element. Will be called multiple times during a
* larger batch operation. Will not be called with null data in normal
* operation.
*
* @throws Exception if there are errors. If the processor is used inside a
* retry or a batch the framework will catch the exception and convert or
* rethrow it as appropriate.
*/
void process(Object data) throws Exception;
}

View File

@@ -18,20 +18,22 @@ package org.springframework.batch.item;
/**
* Basic interface for generic output operations. Class implementing this
* interface will be responsible for serializing objects. Generally, it is
* responsibility of implementing class to decide which technology to use for
* mapping and how it should be configured.
* interface will be responsible for serializing objects ias necessary.
* Generally, it is responsibility of implementing class to decide which
* technology to use for mapping and how it should be configured.
*
* @author Dave Syer
*/
public interface ItemWriter {
/**
* Writes provided object to an output stream or similar.
* Process the supplied data element. Will be called multiple times during a
* larger batch operation. Will not be called with null data in normal
* operation.
*
* @param item
* the object to write.
* @throws Exception if something goes wrong
* @throws Exception if there are errors. If the processor is used inside a
* retry or a batch the framework will catch the exception and convert or
* rethrow it as appropriate.
*/
public void write(Object item) throws Exception;
}

View File

@@ -1,4 +1,4 @@
package org.springframework.batch.item.processor;
package org.springframework.batch.item.writer;
import java.util.Iterator;
import java.util.List;

View File

@@ -1,4 +1,4 @@
package org.springframework.batch.item.processor;
package org.springframework.batch.item.writer;
import java.util.ArrayList;
import java.util.Iterator;
@@ -6,7 +6,6 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.restart.GenericRestartData;
@@ -100,14 +99,13 @@ public class CompositeItemWriter implements ItemWriter, Restartable {
/**
* @param extractor used to extract Properties from {@link ItemReader}s
* @return compound Properties containing all the Properties from injected
* {@link ItemProcessor}s with property keys prefixed by list index.
* {@link ItemWriter}s with property keys prefixed by list index.
*/
private Properties createCompoundProperties(PropertiesExtractor extractor) {
Properties stats = new Properties();
int index = 0;
for (Iterator iterator = delegates.listIterator(); iterator.hasNext();) {
ItemProcessor processor = (ItemProcessor) iterator.next();
Properties processorStats = extractor.extractProperties(processor);
Properties processorStats = extractor.extractProperties(iterator.next());
if (processorStats != null) {
for (Iterator iterator2 = processorStats.entrySet().iterator(); iterator2.hasNext();) {
Map.Entry entry = (Map.Entry) iterator2.next();

View File

@@ -1,4 +1,4 @@
package org.springframework.batch.item.processor;
package org.springframework.batch.item.writer;
import java.util.Properties;
@@ -26,7 +26,7 @@ public class DelegatingItemWriter implements ItemWriter, Restartable, Skippable,
* delegate {@link ItemWriter}.
* @throws Exception
*
* @see org.springframework.batch.item.ItemProcessor#process(java.lang.Object)
* @see ItemWriter#process(java.lang.Object)
*/
final public void write(Object item) throws Exception {
Object result = doProcess(item);

View File

@@ -1,4 +1,4 @@
package org.springframework.batch.item.processor;
package org.springframework.batch.item.writer;
/**
* Interface for item transformations during processing phase.

View File

@@ -1,4 +1,4 @@
package org.springframework.batch.item.processor;
package org.springframework.batch.item.writer;
import org.springframework.batch.item.ItemWriter;
import org.springframework.util.Assert;

View File

@@ -14,9 +14,9 @@
* limitations under the License.
*/
package org.springframework.batch.item.processor;
package org.springframework.batch.item.writer;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.support.AbstractMethodInvokingDelegator;
@@ -28,9 +28,9 @@ import org.springframework.batch.support.AbstractMethodInvokingDelegator;
*
* @author Robert Kasanicky
*/
public class ItemProcessorAdapter extends AbstractMethodInvokingDelegator implements ItemProcessor {
public class ItemWriterAdapter extends AbstractMethodInvokingDelegator implements ItemWriter {
public void process(Object item) throws Exception {
public void write(Object item) throws Exception {
invokeDelegateMethodWithArgument(item);
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.item.processor;
package org.springframework.batch.item.writer;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.support.AbstractMethodInvokingDelegator;
@@ -26,7 +26,7 @@ import org.springframework.util.Assert;
* Delegates processing to a custom method - extracts property values
* from item object and uses them as arguments for the delegate method.
*
* @see ItemProcessorAdapter
* @see ItemWriterAdapter
*
* @author Robert Kasanicky
*/