EMMA Coverage Report (generated Fri Aug 21 15:59:46 BST 2009)
[all classes][org.springframework.batch.core.listener]

COVERAGE SUMMARY FOR SOURCE FILE [CompositeStepExecutionListener.java]

nameclass, %method, %block, %line, %
CompositeStepExecutionListener.java100% (1/1)100% (5/5)100% (63/63)100% (16/16)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CompositeStepExecutionListener100% (1/1)100% (5/5)100% (63/63)100% (16/16)
CompositeStepExecutionListener (): void 100% (1/1)100% (8/8)100% (2/2)
afterStep (StepExecution): ExitStatus 100% (1/1)100% (28/28)100% (6/6)
beforeStep (StepExecution): void 100% (1/1)100% (16/16)100% (4/4)
register (StepExecutionListener): void 100% (1/1)100% (5/5)100% (2/2)
setListeners (StepExecutionListener []): void 100% (1/1)100% (6/6)100% (2/2)

1/*
2 * Copyright 2006-2007 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.springframework.batch.core.listener;
17 
18import java.util.Arrays;
19import java.util.Iterator;
20 
21import org.springframework.batch.core.ExitStatus;
22import org.springframework.batch.core.StepExecution;
23import org.springframework.batch.core.StepExecutionListener;
24import org.springframework.core.Ordered;
25 
26/**
27 * @author Lucas Ward
28 * @author Dave Syer
29 * 
30 */
31public class CompositeStepExecutionListener implements StepExecutionListener {
32 
33        private OrderedComposite<StepExecutionListener> list = new OrderedComposite<StepExecutionListener>();
34 
35        /**
36         * Public setter for the listeners.
37         * 
38         * @param listeners
39         */
40        public void setListeners(StepExecutionListener[] listeners) {
41                list.setItems(Arrays.asList(listeners));
42        }
43 
44        /**
45         * Register additional listener.
46         * 
47         * @param stepExecutionListener
48         */
49        public void register(StepExecutionListener stepExecutionListener) {
50                list.add(stepExecutionListener);
51        }
52 
53        /**
54         * Call the registered listeners in reverse order, respecting and
55         * prioritising those that implement {@link Ordered}.
56         * @see org.springframework.batch.core.StepExecutionListener#afterStep(StepExecution)
57         */
58        public ExitStatus afterStep(StepExecution stepExecution) {
59                ExitStatus status = null;
60                for (Iterator<StepExecutionListener> iterator = list.reverse(); iterator.hasNext();) {
61                        StepExecutionListener listener = (StepExecutionListener) iterator.next();
62                        ExitStatus close = listener.afterStep(stepExecution);
63                        status = status != null ? status.and(close) : close;
64                }
65                return status;
66        }
67 
68        /**
69         * Call the registered listeners in order, respecting and prioritising those
70         * that implement {@link Ordered}.
71         * @see org.springframework.batch.core.StepExecutionListener#beforeStep(StepExecution)
72         */
73        public void beforeStep(StepExecution stepExecution) {
74                for (Iterator<StepExecutionListener> iterator = list.iterator(); iterator.hasNext();) {
75                        StepExecutionListener listener = (StepExecutionListener) iterator.next();
76                        listener.beforeStep(stepExecution);
77                }
78        }
79 
80}

[all classes][org.springframework.batch.core.listener]
EMMA 2.0.5312 (C) Vladimir Roubtsov