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