01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: * Set the {@link Log logger} that is to be used to report warnings.
43: * <p>If set to <code>null</code> then a default {@link Log logger} set to
44: * the name of the instance class will be used.
45: * @param logger the {@link Log logger} that is to be used to report warnings
46: */
47: public void setLogger(Log logger) {
48: this .logger = (logger != null ? logger : LogFactory
49: .getLog(getClass()));
50: }
51:
52: /**
53: * Throws a {@link BeanDefinitionParsingException} detailing the error
54: * that has occurred.
55: * @param problem the source of the error
56: */
57: public void fatal(Problem problem) {
58: throw new BeanDefinitionParsingException(problem);
59: }
60:
61: /**
62: * Throws a {@link BeanDefinitionParsingException} detailing the error
63: * that has occurred.
64: * @param problem the source of the error
65: */
66: public void error(Problem problem) {
67: throw new BeanDefinitionParsingException(problem);
68: }
69:
70: /**
71: * Writes the supplied {@link Problem} to the {@link Log} at <code>WARN</code> level.
72: * @param problem the source of the warning
73: */
74: public void warning(Problem problem) {
75: this.logger.warn(problem, problem.getRootCause());
76: }
77:
78: }
|