diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/BatchListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/BatchListener.java new file mode 100644 index 000000000..4f5ea859b --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/BatchListener.java @@ -0,0 +1,29 @@ +/* + * Copyright 2006-2008 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.core.domain; + +/** + * Marker interface that acts as a parent to all Batch + * domain listeners, such as: {@link StepListener}, + * {@link ChunkListener}, {@link ItemReadListener} and + * {@link ItemWriteListener} + * + * @author Lucas Ward + * + */ +public interface BatchListener { + +} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ChunkListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ChunkListener.java index 5c8c25beb..a8aabb9cf 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ChunkListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ChunkListener.java @@ -23,7 +23,7 @@ package org.springframework.batch.core.domain; * @author Lucas Ward * */ -public interface ChunkListener { +public interface ChunkListener extends BatchListener { void beforeChunk(); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ItemFailureHandler.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ItemFailureHandler.java deleted file mode 100644 index 8f7d97b52..000000000 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ItemFailureHandler.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2006-2008 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.core.domain; - -/** - * Interface for defining the contract to log out read and write - * failures encountered during batch processing. - * - * @author Lucas Ward - */ -public interface ItemFailureHandler { - - /** - * Handle read failure. This will usually be done - * by logging out the details of the exception to either a - * file or database table. It is expected that any implementors of this - * of this method will not throw an exception. - * - * @param ex - */ - void handleReadFailure(Exception ex); - - /** - * Handle read failure. This will usually be done - * by logging out the details of the exception to either a - * file or database table. It is expected that any implementors of this - * of this method will not throw an exception. - * - * @param ex - */ - void handleWriteFailure(Object item, Exception ex); - -} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ItemReadListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ItemReadListener.java index 8d489e955..0ad2b0f2e 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ItemReadListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ItemReadListener.java @@ -24,7 +24,7 @@ import org.springframework.batch.item.ItemWriter; * @author Lucas Ward * */ -public interface ItemReadListener { +public interface ItemReadListener extends BatchListener { /** * Called before {@link ItemReader#read()} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ItemWriteListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ItemWriteListener.java index 429786db8..6520cb2f1 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ItemWriteListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/ItemWriteListener.java @@ -23,7 +23,7 @@ import org.springframework.batch.item.ItemWriter; * @author Lucas Ward * */ -public interface ItemWriteListener { +public interface ItemWriteListener extends BatchListener { /** * Called before {@link ItemWriter#write(Object)} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepListener.java index 8411e42a0..105cb2cd5 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepListener.java @@ -24,7 +24,7 @@ import org.springframework.batch.repeat.ExitStatus; * @author Dave Syer * */ -public interface StepListener { +public interface StepListener extends BatchListener { /** * Initialise the state of the listener with the {@link StepExecution} from diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/CompositeChunkListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/CompositeChunkListener.java deleted file mode 100644 index b6db011f4..000000000 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/CompositeChunkListener.java +++ /dev/null @@ -1,72 +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.core.interceptor; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.springframework.batch.core.domain.ChunkListener; - -/** - * @author Lucas Ward - * - */ -public class CompositeChunkListener implements ChunkListener { - - private List listeners = new ArrayList(); - - /** - * Public setter for the listeners. - * - * @param listeners - */ - public void setListeners(ChunkListener[] listeners) { - this.listeners = Arrays.asList(listeners); - } - - /** - * Register additional listener. - * - * @param stepListener - */ - public void register(ChunkListener chunkListener) { - if (!listeners.contains(chunkListener)) { - listeners.add(chunkListener); - } - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.ChunkListener#afterChunk() - */ - public void afterChunk() { - for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { - ChunkListener listener = (ChunkListener) iterator.next(); - listener.afterChunk(); - } - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.ChunkListener#beforeChunk() - */ - public void beforeChunk() { - for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { - ChunkListener listener = (ChunkListener) iterator.next(); - listener.beforeChunk(); - } - } -} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/CompositeItemReadListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/CompositeItemReadListener.java deleted file mode 100644 index d5f04db23..000000000 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/CompositeItemReadListener.java +++ /dev/null @@ -1,74 +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.core.interceptor; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.springframework.batch.core.domain.ChunkListener; -import org.springframework.batch.core.domain.ItemReadListener; - -/** - * @author Lucas Ward - * - */ -public class CompositeItemReadListener implements ItemReadListener { - - private List listeners = new ArrayList(); - - /** - * Public setter for the listeners. - * - * @param listeners - */ - public void setListeners(ChunkListener[] listeners) { - this.listeners = Arrays.asList(listeners); - } - - /** - * Register additional listener. - * - * @param itemReaderListener - */ - public void register(ItemReadListener itemReaderListener) { - if (!listeners.contains(itemReaderListener)) { - listeners.add(itemReaderListener); - } - } - - public void afterRead(Object item) { - for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { - ItemReadListener listener = (ItemReadListener) iterator.next(); - listener.afterRead(item); - } - } - - public void beforeRead() { - for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { - ItemReadListener listener = (ItemReadListener) iterator.next(); - listener.beforeRead(); - } - } - - public void onReadError(Exception ex) { - for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { - ItemReadListener listener = (ItemReadListener) iterator.next(); - listener.onReadError(ex); - } - } -} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/CompositeItemWriteListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/CompositeItemWriteListener.java deleted file mode 100644 index a4a4c0650..000000000 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/CompositeItemWriteListener.java +++ /dev/null @@ -1,75 +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.core.interceptor; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.springframework.batch.core.domain.ChunkListener; -import org.springframework.batch.core.domain.ItemReadListener; -import org.springframework.batch.core.domain.ItemWriteListener; - -/** - * @author Lucas Ward - * - */ -public class CompositeItemWriteListener implements ItemWriteListener { - - private List listeners = new ArrayList(); - - /** - * Public setter for the listeners. - * - * @param listeners - */ - public void setListeners(ChunkListener[] listeners) { - this.listeners = Arrays.asList(listeners); - } - - /** - * Register additional listener. - * - * @param itemReaderListener - */ - public void register(ItemWriteListener itemReaderListener) { - if (!listeners.contains(itemReaderListener)) { - listeners.add(itemReaderListener); - } - } - - public void afterWrite() { - for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { - ItemWriteListener listener = (ItemWriteListener) iterator.next(); - listener.afterWrite(); - } - } - - public void beforeWrite(Object item) { - for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { - ItemWriteListener listener = (ItemWriteListener) iterator.next(); - listener.beforeWrite(item); - } - } - - public void onWriteError(Exception ex, Object item) { - for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { - ItemWriteListener listener = (ItemWriteListener) iterator.next(); - listener.onWriteError(ex, item); - } - } -} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/CompositeJobListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/CompositeJobListener.java deleted file mode 100644 index 0ceeb8290..000000000 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/CompositeJobListener.java +++ /dev/null @@ -1,74 +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.core.interceptor; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.springframework.batch.core.domain.JobExecution; -import org.springframework.batch.core.domain.JobListener; - -/** - * @author Dave Syer - * - */ -public class CompositeJobListener implements JobListener { - - private List listeners = new ArrayList(); - - /** - * Public setter for the listeners. - * - * @param listeners - */ - public void setListeners(JobListener[] listeners) { - this.listeners = Arrays.asList(listeners); - } - - /** - * Register additional listener. - * - * @param stepListener - */ - public void register(JobListener stepListener) { - if (!listeners.contains(stepListener)) { - listeners.add(stepListener); - } - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.StepListener#close() - */ - public void afterJob() { - for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { - JobListener listener = (JobListener) iterator.next(); - listener.afterJob(); - } - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.StepListener#open(org.springframework.batch.core.domain.JobParameters) - */ - public void beforeJob(JobExecution jobExecution) { - for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { - JobListener listener = (JobListener) iterator.next(); - listener.beforeJob(jobExecution); - } - } - -} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/CompositeStepListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/CompositeStepListener.java deleted file mode 100644 index f93a7a868..000000000 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/CompositeStepListener.java +++ /dev/null @@ -1,90 +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.core.interceptor; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.springframework.batch.core.domain.StepExecution; -import org.springframework.batch.core.domain.StepListener; -import org.springframework.batch.repeat.ExitStatus; - -/** - * @author Lucas Ward - * - */ -public class CompositeStepListener implements StepListener { - - private List listeners = new ArrayList(); - - /** - * Public setter for the listeners. - * - * @param listeners - */ - public void setListeners(StepListener[] listeners) { - this.listeners = Arrays.asList(listeners); - } - - /** - * Register additional listener. - * - * @param stepListener - */ - public void register(StepListener stepListener) { - if (!listeners.contains(stepListener)) { - listeners.add(stepListener); - } - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.StepListener#close() - */ - public ExitStatus afterStep() { - ExitStatus status = null; - for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { - StepListener listener = (StepListener) iterator.next(); - ExitStatus close = listener.afterStep(); - status = status!=null ? status.and(close): close; - } - return status; - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.StepListener#open(org.springframework.batch.core.domain.JobParameters) - */ - public void beforeStep(StepExecution stepExecution) { - for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { - StepListener listener = (StepListener) iterator.next(); - listener.beforeStep(stepExecution); - } - } - - /* (non-Javadoc) - * @see org.springframework.batch.core.domain.StepListener#onError(java.lang.Throwable) - */ - public ExitStatus onErrorInStep(Throwable e) { - ExitStatus status = null; - for (Iterator iterator = listeners.iterator(); iterator.hasNext();) { - StepListener listener = (StepListener) iterator.next(); - ExitStatus close = listener.onErrorInStep(e); - status = status!=null ? status.and(close): close; - } - return status; - } -} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/BatchListenerSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/BatchListenerSupport.java new file mode 100644 index 000000000..7d7f3f80f --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/BatchListenerSupport.java @@ -0,0 +1,103 @@ +/* + * Copyright 2006-2008 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.core.listener; + +import org.springframework.batch.core.domain.BatchListener; +import org.springframework.batch.core.domain.ChunkListener; +import org.springframework.batch.core.domain.ItemReadListener; +import org.springframework.batch.core.domain.ItemWriteListener; +import org.springframework.batch.core.domain.StepExecution; +import org.springframework.batch.core.domain.StepListener; +import org.springframework.batch.repeat.ExitStatus; + +/** + * Basic no-op implementations of all {@link BatchListener} implementations. + * + * @author Lucas Ward + * + */ +public class BatchListenerSupport implements StepListener, ChunkListener, + ItemReadListener, ItemWriteListener { + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.StepListener#afterStep() + */ + public ExitStatus afterStep() { + return null; + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.StepListener#beforeStep(org.springframework.batch.core.domain.StepExecution) + */ + public void beforeStep(StepExecution stepExecution) { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.StepListener#onErrorInStep(java.lang.Throwable) + */ + public ExitStatus onErrorInStep(Throwable e) { + return null; + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ChunkListener#afterChunk() + */ + public void afterChunk() { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ChunkListener#beforeChunk() + */ + public void beforeChunk() { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemReadListener#afterRead(java.lang.Object) + */ + public void afterRead(Object item) { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemReadListener#beforeRead() + */ + public void beforeRead() { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemReadListener#onReadError(java.lang.Exception) + */ + public void onReadError(Exception ex) { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemWriteListener#afterWrite() + */ + public void afterWrite() { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemWriteListener#beforeWrite(java.lang.Object) + */ + public void beforeWrite(Object item) { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemWriteListener#onWriteError(java.lang.Exception, java.lang.Object) + */ + public void onWriteError(Exception ex, Object item) { + } + +} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ChunkListenerSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ChunkListenerSupport.java new file mode 100644 index 000000000..704e77023 --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ChunkListenerSupport.java @@ -0,0 +1,40 @@ +/* + * Copyright 2006-2008 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.core.listener; + +import org.springframework.batch.core.domain.ChunkListener; + +/** + * Basic support implementation of {@link ChunkListener} + * + * @author Lucas Ward + * + */ +public class ChunkListenerSupport implements ChunkListener { + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ChunkListener#afterChunk() + */ + public void afterChunk() { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ChunkListener#beforeChunk() + */ + public void beforeChunk() { + } + +} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ItemListenerSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ItemListenerSupport.java new file mode 100644 index 000000000..22d9b2475 --- /dev/null +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/ItemListenerSupport.java @@ -0,0 +1,67 @@ +/* + * Copyright 2006-2008 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.core.listener; + +import org.springframework.batch.core.domain.ItemReadListener; +import org.springframework.batch.core.domain.ItemWriteListener; + +/** + * Basic no-op implementation of both the {@link ItemWriteListener} and + * {@link ItemReadListener} interfaces. Both are implemented, since it is + * very common that both may need to be implemented at once. + * + * @author Lucas Ward + * + */ +public class ItemListenerSupport implements ItemWriteListener, ItemReadListener { + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemWriteListener#afterWrite() + */ + public void afterWrite() { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemWriteListener#beforeWrite(java.lang.Object) + */ + public void beforeWrite(Object item) { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemWriteListener#onWriteError(java.lang.Exception, java.lang.Object) + */ + public void onWriteError(Exception ex, Object item) { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemReadListener#afterRead(java.lang.Object) + */ + public void afterRead(Object item) { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemReadListener#beforeRead() + */ + public void beforeRead() { + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.domain.ItemReadListener#onReadError(java.lang.Exception) + */ + public void onReadError(Exception ex) { + } + +} diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/JobListenerSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobListenerSupport.java similarity index 95% rename from spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/JobListenerSupport.java rename to spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobListenerSupport.java index 60d90a9c5..20a24b5a6 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/JobListenerSupport.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/JobListenerSupport.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.batch.core.interceptor; +package org.springframework.batch.core.listener; import org.springframework.batch.core.domain.JobExecution; import org.springframework.batch.core.domain.JobListener; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/StepListenerSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerSupport.java similarity index 96% rename from spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/StepListenerSupport.java rename to spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerSupport.java index 6e4c4e5ea..2caa673a0 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/interceptor/StepListenerSupport.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerSupport.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.batch.core.interceptor; +package org.springframework.batch.core.listener; import org.springframework.batch.core.domain.StepExecution; import org.springframework.batch.core.domain.StepListener; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/interceptor/CompositeJobListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/interceptor/CompositeJobListenerTests.java deleted file mode 100644 index 1b44d4173..000000000 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/interceptor/CompositeJobListenerTests.java +++ /dev/null @@ -1,84 +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.core.interceptor; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.springframework.batch.core.domain.JobExecution; -import org.springframework.batch.core.domain.JobInstance; -import org.springframework.batch.core.domain.JobListener; -import org.springframework.batch.core.domain.JobSupport; - -/** - * @author Dave Syer - * - */ -public class CompositeJobListenerTests extends TestCase { - - private CompositeJobListener listener = new CompositeJobListener(); - - private List list = new ArrayList(); - - /** - * Test method for - * {@link org.springframework.batch.core.interceptor.CompositeJobListener#setListeners(org.springframework.batch.core.domain.JobListener[])}. - */ - public void testSetListeners() { - listener.setListeners(new JobListener[] { new JobListenerSupport() { - public void afterJob() { - list.add("fail"); - } - }, new JobListenerSupport() { - public void afterJob() { - list.add("continue"); - } - } }); - listener.afterJob(); - assertEquals(2, list.size()); - } - - /** - * Test method for - * {@link org.springframework.batch.core.interceptor.CompositeJobListener#setListener(org.springframework.batch.core.domain.JobListener)}. - */ - public void testSetListener() { - listener.register(new JobListenerSupport() { - public void afterJob() { - list.add("fail"); - } - }); - listener.afterJob(); - assertEquals(1, list.size()); - } - - /** - * Test method for - * {@link org.springframework.batch.core.interceptor.CompositeJobListener#beforeJob(JobExecution)}. - */ - public void testOpen() { - listener.register(new JobListenerSupport() { - public void beforeJob(JobExecution stepExecution) { - list.add("foo"); - } - }); - listener.beforeJob(new JobExecution(new JobInstance(new Long(11L), null, new JobSupport()))); - assertEquals(1, list.size()); - } - -} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/interceptor/CompositeStepListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/interceptor/CompositeStepListenerTests.java deleted file mode 100644 index 2e95e16da..000000000 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/interceptor/CompositeStepListenerTests.java +++ /dev/null @@ -1,102 +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.core.interceptor; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.springframework.batch.core.domain.StepExecution; -import org.springframework.batch.core.domain.StepListener; -import org.springframework.batch.core.domain.StepSupport; -import org.springframework.batch.repeat.ExitStatus; - -/** - * @author Dave Syer - * - */ -public class CompositeStepListenerTests extends TestCase { - - private CompositeStepListener listener = new CompositeStepListener(); - - private List list = new ArrayList(); - - /** - * Test method for - * {@link org.springframework.batch.core.interceptor.CompositeStepListener#setListeners(org.springframework.batch.core.domain.StepListener[])}. - */ - public void testSetListeners() { - listener.setListeners(new StepListener[] { new StepListenerSupport() { - public ExitStatus afterStep() { - list.add("fail"); - return ExitStatus.FAILED; - } - }, new StepListenerSupport() { - public ExitStatus afterStep() { - list.add("continue"); - return ExitStatus.CONTINUABLE; - } - } }); - assertFalse(listener.afterStep().isContinuable()); - assertEquals(2, list.size()); - } - - /** - * Test method for - * {@link org.springframework.batch.core.interceptor.CompositeStepListener#setListener(org.springframework.batch.core.domain.StepListener)}. - */ - public void testSetListener() { - listener.register(new StepListenerSupport() { - public ExitStatus afterStep() { - list.add("fail"); - return ExitStatus.FAILED; - } - }); - assertFalse(listener.afterStep().isContinuable()); - assertEquals(1, list.size()); - } - - /** - * Test method for - * {@link org.springframework.batch.core.interceptor.CompositeStepListener#beforeStep(StepExecution)}. - */ - public void testOpen() { - listener.register(new StepListenerSupport() { - public void beforeStep(StepExecution stepExecution) { - list.add("foo"); - } - }); - listener.beforeStep(new StepExecution(new StepSupport("foo"), null)); - assertEquals(1, list.size()); - } - - /** - * Test method for - * {@link org.springframework.batch.core.interceptor.CompositeStepListener#beforeStep(StepExecution)}. - */ - public void testOnError() { - listener.register(new StepListenerSupport() { - public ExitStatus onErrorInStep(Throwable e) { - list.add("foo"); - return null; - } - }); - listener.onErrorInStep(new RuntimeException()); - assertEquals(1, list.size()); - } - -}