001/*
002 * Copyright 2002-2016 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.expression.spel;
018
019import org.springframework.expression.ParseException;
020
021/**
022 * Root exception for Spring EL related exceptions. Rather than holding a hard coded
023 * string indicating the problem, it records a message key and the inserts for the
024 * message. See {@link SpelMessage} for the list of all possible messages that can occur.
025 *
026 * @author Andy Clement
027 * @author Juergen Hoeller
028 * @since 3.0
029 */
030@SuppressWarnings("serial")
031public class SpelParseException extends ParseException {
032
033        private final SpelMessage message;
034
035        private final Object[] inserts;
036
037
038        public SpelParseException(String expressionString, int position, SpelMessage message, Object... inserts) {
039                super(expressionString, position, message.formatMessage(inserts));
040                this.message = message;
041                this.inserts = inserts;
042        }
043
044        public SpelParseException(int position, SpelMessage message, Object... inserts) {
045                super(position, message.formatMessage(inserts));
046                this.message = message;
047                this.inserts = inserts;
048        }
049
050        public SpelParseException(int position, Throwable cause, SpelMessage message, Object... inserts) {
051                super(position, message.formatMessage(inserts), cause);
052                this.message = message;
053                this.inserts = inserts;
054        }
055
056
057        /**
058         * Return the message code.
059         */
060        public SpelMessage getMessageCode() {
061                return this.message;
062        }
063
064        /**
065         * Return the message inserts.
066         */
067        public Object[] getInserts() {
068                return this.inserts;
069        }
070
071}