01: /*
02: * Copyright 2002-2006 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.xml;
18:
19: import org.xml.sax.SAXException;
20: import org.xml.sax.SAXParseException;
21:
22: import org.springframework.beans.factory.BeanDefinitionStoreException;
23:
24: /**
25: * XML-specific BeanDefinitionStoreException subclass that wraps a
26: * {@link org.xml.sax.SAXException}, typically a {@link org.xml.sax.SAXParseException}
27: * which contains information about the error location.
28: *
29: * @author Juergen Hoeller
30: * @since 2.0.2
31: * @see #getLineNumber()
32: * @see org.xml.sax.SAXParseException
33: */
34: public class XmlBeanDefinitionStoreException extends
35: BeanDefinitionStoreException {
36:
37: /**
38: * Create a new XmlBeanDefinitionStoreException.
39: * @param resourceDescription description of the resource that the bean definition came from
40: * @param msg the detail message (used as exception message as-is)
41: * @param cause the SAXException (typically a SAXParseException) root cause
42: * @see org.xml.sax.SAXParseException
43: */
44: public XmlBeanDefinitionStoreException(String resourceDescription,
45: String msg, SAXException cause) {
46: super (resourceDescription, msg, cause);
47: }
48:
49: /**
50: * Return the line number in the XML resource that failed.
51: * @return the line number if available (in case of a SAXParseException); -1 else
52: * @see org.xml.sax.SAXParseException#getLineNumber()
53: */
54: public int getLineNumber() {
55: Throwable cause = getCause();
56: if (cause instanceof SAXParseException) {
57: return ((SAXParseException) cause).getLineNumber();
58: }
59: return -1;
60: }
61:
62: }
|