EMMA Coverage Report (generated Tue May 06 07:28:24 PDT 2008)
[all classes][org.springframework.batch.support]

COVERAGE SUMMARY FOR SOURCE FILE [BinaryExceptionClassifier.java]

nameclass, %method, %block, %line, %
BinaryExceptionClassifier.java100% (1/1)100% (4/4)100% (43/43)100% (9/9)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BinaryExceptionClassifier100% (1/1)100% (4/4)100% (43/43)100% (9/9)
BinaryExceptionClassifier (): void 100% (1/1)100% (8/8)100% (2/2)
classify (Throwable): Object 100% (1/1)100% (5/5)100% (1/1)
isDefault (Throwable): boolean 100% (1/1)100% (6/6)100% (1/1)
setExceptionClasses (Class []): void 100% (1/1)100% (24/24)100% (5/5)

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.support;
17 
18import java.util.HashMap;
19import java.util.Map;
20 
21/**
22 * A {@link ExceptionClassifier} that has only two classes of exception.
23 * Provides convenient methods for setting up and querying the classification
24 * with boolean return type.
25 * 
26 * @author Dave Syer
27 * 
28 */
29public class BinaryExceptionClassifier extends ExceptionClassifierSupport {
30 
31        /**
32         * The classifier result for a non-default exception.
33         */
34        public static final String NON_DEFAULT = "NON_DEFAULT";
35 
36        private SubclassExceptionClassifier delegate = new SubclassExceptionClassifier();
37 
38        /**
39         * Set the special exceptions. Any exception on the list, or subclasses
40         * thereof, will be classified as non-default.
41         * 
42         * @param exceptionClasses defaults to {@link Exception}.
43         */
44        public final void setExceptionClasses(Class[] exceptionClasses) {
45                Map temp = new HashMap();
46                for (int i = 0; i < exceptionClasses.length; i++) {
47                        temp.put(exceptionClasses[i], NON_DEFAULT);
48                }
49                this.delegate.setTypeMap(temp);
50        }
51 
52        /**
53         * Convenience method to return boolean if the throwable is classified as
54         * default.
55         * 
56         * @param throwable the Throwable to classify
57         * @return true if it is default classified (i.e. not on the list provided
58         * in {@link #setExceptionClasses(Class[])}.
59         */
60        public boolean isDefault(Throwable throwable) {
61                return classify(throwable).equals(DEFAULT);
62        }
63 
64        /**
65         * Returns either {@link ExceptionClassifierSupport#DEFAULT} or
66         * {@link #NON_DEFAULT} depending on the type of the throwable. If the type
67         * of the throwable or one of its ancestors is on the exception class list
68         * the classification is as {@link #NON_DEFAULT}.
69         * 
70         * @see #setExceptionClasses(Class[])
71         * @see ExceptionClassifierSupport#classify(Throwable)
72         */
73        public Object classify(Throwable throwable) {
74                return delegate.classify(throwable);
75        }
76 
77}

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