EMMA Coverage Report (generated Thu May 22 12:08:10 CDT 2014)
[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% (60/60)100% (17/17)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CompositeStepExecutionListener100% (1/1)100% (5/5)100% (60/60)100% (17/17)
CompositeStepExecutionListener (): void 100% (1/1)100% (8/8)100% (2/2)
afterStep (StepExecution): ExitStatus 100% (1/1)100% (25/25)100% (6/6)
beforeStep (StepExecution): void 100% (1/1)100% (16/16)100% (5/5)
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-2013 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         * prioritizing those that implement {@link Ordered}.
56         * @see org.springframework.batch.core.StepExecutionListener#afterStep(StepExecution)
57         */
58        @Override
59        public ExitStatus afterStep(StepExecution stepExecution) {
60                for (Iterator<StepExecutionListener> iterator = list.reverse(); iterator.hasNext();) {
61                        StepExecutionListener listener = iterator.next();
62                        ExitStatus close = listener.afterStep(stepExecution);
63                        stepExecution.setExitStatus(stepExecution.getExitStatus().and(close));
64                }
65                return stepExecution.getExitStatus();
66        }
67 
68        /**
69         * Call the registered listeners in order, respecting and prioritizing those
70         * that implement {@link Ordered}.
71         * @see org.springframework.batch.core.StepExecutionListener#beforeStep(StepExecution)
72         */
73        @Override
74        public void beforeStep(StepExecution stepExecution) {
75                for (Iterator<StepExecutionListener> iterator = list.iterator(); iterator.hasNext();) {
76                        StepExecutionListener listener = iterator.next();
77                        listener.beforeStep(stepExecution);
78                }
79        }
80 
81}

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