KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > factory > parsing > FailFastProblemReporter


1 /*
2  * Copyright 2002-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
17 package org.springframework.beans.factory.parsing;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21
22 /**
23  * Simple {@link ProblemReporter} implementation that exhibits fail-fast
24  * behavior when errors are encountered.
25  *
26  * <p>The first error encountered results in a {@link BeanDefinitionParsingException}
27  * being thrown.
28  *
29  * <p>Warnings are written to
30  * {@link #setLogger(org.apache.commons.logging.Log) the log} for this class.
31  *
32  * @author Rob Harrop
33  * @author Juergen Hoeller
34  * @author Rick Evans
35  * @since 2.0
36  */

37 public class FailFastProblemReporter implements ProblemReporter {
38
39     private Log logger = LogFactory.getLog(getClass());
40
41
42     /**
43      * Set the {@link Log logger} that is to be used to report warnings.
44      * <p>If set to <code>null</code> then a default {@link Log logger} set to
45      * the name of the instance class will be used.
46      * @param logger the {@link Log logger} that is to be used to report warnings
47      */

48     public void setLogger(Log logger) {
49         this.logger = (logger != null ? logger : LogFactory.getLog(getClass()));
50     }
51
52
53     /**
54      * Throws a {@link BeanDefinitionParsingException} detailing the error
55      * that has occurred.
56      * @param problem the source of the error
57      */

58     public void fatal(Problem problem) {
59         throw new BeanDefinitionParsingException(problem);
60     }
61
62     /**
63      * Throws a {@link BeanDefinitionParsingException} detailing the error
64      * that has occurred.
65      * @param problem the source of the error
66      */

67     public void error(Problem problem) {
68         throw new BeanDefinitionParsingException(problem);
69     }
70
71     /**
72      * Writes the supplied {@link Problem} to the {@link Log} at <code>WARN</code> level.
73      * @param problem the source of the warning
74      */

75     public void warning(Problem problem) {
76         this.logger.warn(problem, problem.getRootCause());
77     }
78
79 }
80
Popular Tags