EMMA Coverage Report (generated Fri Aug 21 15:59:46 BST 2009)
[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%  (22/25)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MethodInvokerMethodInterceptor100% (1/1)80%  (4/5)87%  (78/90)88%  (22/25)
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%  (13/14)
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-2008 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        public Object invoke(MethodInvocation invocation) throws Throwable {
55 
56                String methodName = invocation.getMethod().getName();
57                if (ordered && methodName.equals("getOrder")) {
58                        return invocation.proceed();
59                }
60 
61                Set<MethodInvoker> invokers = invokerMap.get(methodName);
62 
63                if (invokers == null) {
64                        return null;
65                }
66                ExitStatus status = null;
67                for (MethodInvoker invoker : invokers) {
68                        Object retVal = invoker.invokeMethod(invocation.getArguments());
69                        if (retVal instanceof ExitStatus) {
70                                if (status != null) {
71                                        status = status.and((ExitStatus) retVal);
72                                }
73                                else {
74                                        status = (ExitStatus) retVal;
75                                }
76                        }
77                }
78 
79                // The only possible return values are ExitStatus or int (from Ordered)
80                return status;
81        }
82 
83        /**
84         * {@inheritDoc}
85         */
86        @Override
87        public boolean equals(Object obj) {
88                if (!(obj instanceof MethodInvokerMethodInterceptor)) {
89                        return false;
90                }
91                MethodInvokerMethodInterceptor other = (MethodInvokerMethodInterceptor) obj;
92                return invokerMap.equals(other.invokerMap);
93        }
94        
95        /**
96         * {@inheritDoc}
97         */
98        @Override
99        public int hashCode() {
100                return invokerMap.hashCode();
101        }
102 
103}

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