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

COVERAGE SUMMARY FOR SOURCE FILE [MethodInvokingTaskletAdapter.java]

nameclass, %method, %block, %line, %
MethodInvokingTaskletAdapter.java100% (1/1)100% (3/3)100% (19/19)100% (6/6)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MethodInvokingTaskletAdapter100% (1/1)100% (3/3)100% (19/19)100% (6/6)
MethodInvokingTaskletAdapter (): void 100% (1/1)100% (3/3)100% (1/1)
execute (StepContribution, ChunkContext): RepeatStatus 100% (1/1)100% (8/8)100% (2/2)
mapResult (Object): ExitStatus 100% (1/1)100% (8/8)100% (3/3)

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.step.tasklet;
17 
18import org.springframework.batch.core.ExitStatus;
19import org.springframework.batch.core.StepContribution;
20import org.springframework.batch.core.scope.context.ChunkContext;
21import org.springframework.batch.item.adapter.AbstractMethodInvokingDelegator;
22import org.springframework.batch.repeat.RepeatStatus;
23 
24/**
25 * A {@link Tasklet} that wraps a method in a POJO. By default the return
26 * value is {@link ExitStatus#COMPLETED} unless the delegate POJO itself returns
27 * an {@link ExitStatus}. The POJO method is usually going to have no arguments,
28 * but a static argument or array of arguments can be used by setting the
29 * arguments property.
30 * 
31 * @see AbstractMethodInvokingDelegator
32 * 
33 * @author Dave Syer
34 * 
35 */
36public class MethodInvokingTaskletAdapter extends AbstractMethodInvokingDelegator<Object> implements Tasklet {
37 
38        /**
39         * Delegate execution to the target object and translate the return value to
40         * an {@link ExitStatus} by invoking a method in the delegate POJO. Ignores
41         * the {@link StepContribution} and the attributes.
42         * 
43         * @see Tasklet#execute(StepContribution, ChunkContext)
44         */
45        public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
46                contribution.setExitStatus(mapResult(invokeDelegateMethod()));
47                return RepeatStatus.FINISHED;
48        }
49 
50        /**
51         * If the result is an {@link ExitStatus} already just return that,
52         * otherwise return {@link ExitStatus#COMPLETED}.
53         * 
54         * @param result the value returned by the delegate method
55         * @return an {@link ExitStatus} consistent with the result
56         */
57        protected ExitStatus mapResult(Object result) {
58                if (result instanceof ExitStatus) {
59                        return (ExitStatus) result;
60                }
61                return ExitStatus.COMPLETED;
62        }
63 
64}

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