EMMA Coverage Report (generated Thu Jan 24 13:37:04 CST 2013)
[all classes][org.springframework.batch.repeat.exception]

COVERAGE SUMMARY FOR SOURCE FILE [LogOrRethrowExceptionHandler.java]

nameclass, %method, %block, %line, %
LogOrRethrowExceptionHandler.java100% (2/2)71%  (5/7)93%  (113/122)99%  (19.8/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class LogOrRethrowExceptionHandler$Level100% (1/1)50%  (2/4)84%  (49/58)97%  (4.8/5)
valueOf (String): LogOrRethrowExceptionHandler$Level 0%   (0/1)0%   (0/5)0%   (0/1)
values (): LogOrRethrowExceptionHandler$Level [] 0%   (0/1)0%   (0/4)0%   (0/1)
<static initializer> 100% (1/1)100% (44/44)100% (5/5)
LogOrRethrowExceptionHandler$Level (String, int): void 100% (1/1)100% (5/5)100% (1/1)
     
class LogOrRethrowExceptionHandler100% (1/1)100% (3/3)100% (64/64)100% (15/15)
LogOrRethrowExceptionHandler (): void 100% (1/1)100% (13/13)100% (3/3)
handleException (RepeatContext, Throwable): void 100% (1/1)100% (47/47)100% (10/10)
setExceptionClassifier (Classifier): void 100% (1/1)100% (4/4)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 */
16 
17package org.springframework.batch.repeat.exception;
18 
19import org.apache.commons.logging.Log;
20import org.apache.commons.logging.LogFactory;
21import org.springframework.batch.classify.Classifier;
22import org.springframework.batch.classify.ClassifierSupport;
23import org.springframework.batch.repeat.RepeatContext;
24import org.springframework.batch.repeat.RepeatException;
25 
26/**
27 * Implementation of {@link ExceptionHandler} based on an {@link Classifier}.
28 * The classifier determines whether to log the exception or rethrow it. The
29 * keys in the classifier must be the same as the static enum in this class.
30 * 
31 * @author Dave Syer
32 * 
33 */
34public class LogOrRethrowExceptionHandler implements ExceptionHandler {
35 
36        /**
37         * Logging levels for the handler.
38         * 
39         * @author Dave Syer
40         * 
41         */
42        public static enum Level {
43 
44                /**
45                 * Key for {@link Classifier} signalling that the throwable should be
46                 * rethrown. If the throwable is not a RuntimeException it is wrapped in
47                 * a {@link RepeatException}.
48                 */
49                RETHROW,
50 
51                /**
52                 * Key for {@link Classifier} signalling that the throwable should be
53                 * logged at debug level.
54                 */
55                DEBUG,
56 
57                /**
58                 * Key for {@link Classifier} signalling that the throwable should be
59                 * logged at warn level.
60                 */
61                WARN,
62 
63                /**
64                 * Key for {@link Classifier} signalling that the throwable should be
65                 * logged at error level.
66                 */
67                ERROR
68 
69        }
70 
71        protected final Log logger = LogFactory.getLog(LogOrRethrowExceptionHandler.class);
72 
73        private Classifier<Throwable, Level> exceptionClassifier = new ClassifierSupport<Throwable, Level>(Level.RETHROW);
74 
75        /**
76         * Setter for the {@link Classifier} used by this handler. The default is to
77         * map all throwable instances to {@link Level#RETHROW}.
78         * 
79         * @param exceptionClassifier the ExceptionClassifier to use
80         */
81        public void setExceptionClassifier(Classifier<Throwable, Level> exceptionClassifier) {
82                this.exceptionClassifier = exceptionClassifier;
83        }
84 
85        /**
86         * Classify the throwables and decide whether to rethrow based on the
87         * result. The context is not used.
88         * 
89         * @throws Throwable
90         * 
91         * @see ExceptionHandler#handleException(RepeatContext, Throwable)
92         */
93        public void handleException(RepeatContext context, Throwable throwable) throws Throwable {
94 
95                Level key = exceptionClassifier.classify(throwable);
96                if (Level.ERROR.equals(key)) {
97                        logger.error("Exception encountered in batch repeat.", throwable);
98                }
99                else if (Level.WARN.equals(key)) {
100                        logger.warn("Exception encountered in batch repeat.", throwable);
101                }
102                else if (Level.DEBUG.equals(key) && logger.isDebugEnabled()) {
103                        logger.debug("Exception encountered in batch repeat.", throwable);
104                }
105                else if (Level.RETHROW.equals(key)) {
106                        throw throwable;
107                }
108 
109        }
110 
111}

[all classes][org.springframework.batch.repeat.exception]
EMMA 2.0.5312 (C) Vladimir Roubtsov