001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.beans.factory.xml;
018
019import org.xml.sax.SAXException;
020import org.xml.sax.SAXParseException;
021
022import org.springframework.beans.factory.BeanDefinitionStoreException;
023
024/**
025 * XML-specific BeanDefinitionStoreException subclass that wraps a
026 * {@link org.xml.sax.SAXException}, typically a {@link org.xml.sax.SAXParseException}
027 * which contains information about the error location.
028 *
029 * @author Juergen Hoeller
030 * @since 2.0.2
031 * @see #getLineNumber()
032 * @see org.xml.sax.SAXParseException
033 */
034@SuppressWarnings("serial")
035public class XmlBeanDefinitionStoreException extends BeanDefinitionStoreException {
036
037        /**
038         * Create a new XmlBeanDefinitionStoreException.
039         * @param resourceDescription description of the resource that the bean definition came from
040         * @param msg the detail message (used as exception message as-is)
041         * @param cause the SAXException (typically a SAXParseException) root cause
042         * @see org.xml.sax.SAXParseException
043         */
044        public XmlBeanDefinitionStoreException(String resourceDescription, String msg, SAXException cause) {
045                super(resourceDescription, msg, cause);
046        }
047
048        /**
049         * Return the line number in the XML resource that failed.
050         * @return the line number if available (in case of a SAXParseException); -1 else
051         * @see org.xml.sax.SAXParseException#getLineNumber()
052         */
053        public int getLineNumber() {
054                Throwable cause = getCause();
055                if (cause instanceof SAXParseException) {
056                        return ((SAXParseException) cause).getLineNumber();
057                }
058                return -1;
059        }
060
061}