EMMA Coverage Report (generated Thu May 22 12:08:10 CDT 2014)
[all classes][org.springframework.batch.core.listener]

COVERAGE SUMMARY FOR SOURCE FILE [MethodInvokerMethodInterceptor.java]

nameclass, %method, %block, %line, %
MethodInvokerMethodInterceptor.java100% (1/1)80%  (4/5)87%  (78/90)88%  (23/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MethodInvokerMethodInterceptor100% (1/1)80%  (4/5)87%  (78/90)88%  (23/26)
hashCode (): int 0%   (0/1)0%   (0/4)0%   (0/1)
equals (Object): boolean 100% (1/1)86%  (12/14)75%  (3/4)
invoke (MethodInvocation): Object 100% (1/1)90%  (52/58)93%  (14/15)
MethodInvokerMethodInterceptor (Map): void 100% (1/1)100% (5/5)100% (2/2)
MethodInvokerMethodInterceptor (Map, boolean): void 100% (1/1)100% (9/9)100% (4/4)

1/*
2 * Copyright 2002-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.Map;
19import java.util.Set;
20 
21import org.aopalliance.intercept.MethodInterceptor;
22import org.aopalliance.intercept.MethodInvocation;
23import org.springframework.batch.core.ExitStatus;
24import org.springframework.batch.core.StepExecutionListener;
25import org.springframework.batch.support.MethodInvoker;
26 
27/**
28 * {@link MethodInterceptor} that, given a map of method names and
29 * {@link MethodInvoker}s, will execute all methods tied to a particular method
30 * name, with the provided arguments. The only possible return value that is
31 * handled is of type ExitStatus, since the only StepListener implementation
32 * that isn't void is
33 * {@link StepExecutionListener#afterStep(org.springframework.batch.core.StepExecution)}
34 * , which returns ExitStatus.
35 *
36 * @author Lucas Ward
37 * @since 2.0
38 * @see MethodInvoker
39 */
40public class MethodInvokerMethodInterceptor implements MethodInterceptor {
41 
42        private final Map<String, Set<MethodInvoker>> invokerMap;
43        private final boolean ordered;
44 
45        public MethodInvokerMethodInterceptor(Map<String, Set<MethodInvoker>> invokerMap) {
46                this(invokerMap, false);
47        }
48 
49        public MethodInvokerMethodInterceptor(Map<String, Set<MethodInvoker>> invokerMap, boolean ordered) {
50                this.ordered = ordered;
51                this.invokerMap = invokerMap;
52        }
53 
54        @Override
55        public Object invoke(MethodInvocation invocation) throws Throwable {
56 
57                String methodName = invocation.getMethod().getName();
58                if (ordered && methodName.equals("getOrder")) {
59                        return invocation.proceed();
60                }
61 
62                Set<MethodInvoker> invokers = invokerMap.get(methodName);
63 
64                if (invokers == null) {
65                        return null;
66                }
67                ExitStatus status = null;
68                for (MethodInvoker invoker : invokers) {
69                        Object retVal = invoker.invokeMethod(invocation.getArguments());
70                        if (retVal instanceof ExitStatus) {
71                                if (status != null) {
72                                        status = status.and((ExitStatus) retVal);
73                                }
74                                else {
75                                        status = (ExitStatus) retVal;
76                                }
77                        }
78                }
79 
80                // The only possible return values are ExitStatus or int (from Ordered)
81                return status;
82        }
83 
84        /**
85         * {@inheritDoc}
86         */
87        @Override
88        public boolean equals(Object obj) {
89                if (!(obj instanceof MethodInvokerMethodInterceptor)) {
90                        return false;
91                }
92                MethodInvokerMethodInterceptor other = (MethodInvokerMethodInterceptor) obj;
93                return invokerMap.equals(other.invokerMap);
94        }
95 
96        /**
97         * {@inheritDoc}
98         */
99        @Override
100        public int hashCode() {
101                return invokerMap.hashCode();
102        }
103 
104}

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