KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2002-2006 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.springframework.util.Assert;
20
21 /**
22  * Represents a problem with a bean definition configuration.
23  * Mainly serves as common argument passed into a {@link ProblemReporter}.
24  *
25  * <p>May indicate a potentially fatal problem (an error) or just a warning.
26  *
27  * @author Rob Harrop
28  * @author Juergen Hoeller
29  * @since 2.0
30  * @see ProblemReporter
31  */

32 public class Problem {
33
34     private final String JavaDoc message;
35
36     private final Location location;
37
38     private final ParseState parseState;
39
40     private final Throwable JavaDoc rootCause;
41
42
43     /**
44      * Create a new instance of the {@link Problem} class.
45      * @param message a message detailing the problem
46      * @param location the location within a bean configuration source that triggered the error
47      */

48     public Problem(String JavaDoc message, Location location) {
49         this(message, location, null, null);
50     }
51
52     /**
53      * Create a new instance of the {@link Problem} class.
54      * @param message a message detailing the problem
55      * @param parseState the {@link ParseState} at the time of the error
56      * @param location the location within a bean configuration source that triggered the error
57      */

58     public Problem(String JavaDoc message, Location location, ParseState parseState) {
59         this(message, location, parseState, null);
60     }
61
62     /**
63      * Create a new instance of the {@link Problem} class.
64      * @param message a message detailing the problem
65      * @param rootCause the underlying expection that caused the error (may be <code>null</code>)
66      * @param parseState the {@link ParseState} at the time of the error
67      * @param location the location within a bean configuration source that triggered the error
68      */

69     public Problem(String JavaDoc message, Location location, ParseState parseState, Throwable JavaDoc rootCause) {
70         Assert.notNull(message, "Message must not be null");
71         Assert.notNull(location, "Location must not be null");
72         this.message = message;
73         this.location = location;
74         this.parseState = parseState;
75         this.rootCause = rootCause;
76     }
77
78
79     /**
80      * Get the message detailing the problem.
81      */

82     public String JavaDoc getMessage() {
83         return message;
84     }
85
86     /**
87      * Get the location within a bean configuration source that triggered the error.
88      */

89     public Location getLocation() {
90         return location;
91     }
92
93     /**
94      * Get the description of the bean configuration source that triggered the error,
95      * as contained within this Problem's Location object.
96      * @see #getLocation()
97      */

98     public String JavaDoc getResourceDescription() {
99         return getLocation().getResource().getDescription();
100     }
101
102     /**
103      * Get the {@link ParseState} at the time of the error (may be <code>null</code>).
104      */

105     public ParseState getParseState() {
106         return this.parseState;
107     }
108
109     /**
110      * Get the underlying expection that caused the error (may be <code>null</code>).
111      */

112     public Throwable JavaDoc getRootCause() {
113         return rootCause;
114     }
115
116
117     public String JavaDoc toString() {
118         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
119         sb.append("Configuration problem: ");
120         sb.append(getMessage());
121         sb.append("\nOffending resource: ").append(getResourceDescription());
122         if (getParseState() != null) {
123             sb.append('\n').append(getParseState());
124         }
125         return sb.toString();
126     }
127
128 }
129
Popular Tags