View Javadoc
1   /*
2    * Copyright 2002-2013 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  package org.springframework.expression.spel;
17  
18  import org.springframework.expression.ParseException;
19  
20  /**
21   * Root exception for Spring EL related exceptions. Rather than holding a hard coded
22   * string indicating the problem, it records a message key and the inserts for the
23   * message. See {@link SpelMessage} for the list of all possible messages that can occur.
24   *
25   * @author Andy Clement
26   * @since 3.0
27   */
28  @SuppressWarnings("serial")
29  public class SpelParseException extends ParseException {
30  
31  	private final SpelMessage message;
32  
33  	private final Object[] inserts;
34  
35  
36  	public SpelParseException(String expressionString, int position, SpelMessage message, Object... inserts) {
37  		super(expressionString, position, message.formatMessage(position,inserts));
38  		this.position = position;
39  		this.message = message;
40  		this.inserts = inserts;
41  	}
42  
43  	public SpelParseException(int position, SpelMessage message, Object... inserts) {
44  		super(position, message.formatMessage(position,inserts));
45  		this.position = position;
46  		this.message = message;
47  		this.inserts = inserts;
48  	}
49  
50  	public SpelParseException(int position, Throwable cause, SpelMessage message, Object... inserts) {
51  		super(position, message.formatMessage(position,inserts), cause);
52  		this.position = position;
53  		this.message = message;
54  		this.inserts = inserts;
55  	}
56  
57  
58  	/**
59  	 * @return a formatted message with inserts applied
60  	 */
61  	@Override
62  	public String getMessage() {
63  		return (this.message != null ? this.message.formatMessage(this.position, this.inserts)
64  				: super.getMessage());
65  	}
66  
67  	/**
68  	 * @return the message code
69  	 */
70  	public SpelMessage getMessageCode() {
71  		return this.message;
72  	}
73  
74  	/**
75  	 * @return the message inserts
76  	 */
77  	public Object[] getInserts() {
78  		return this.inserts;
79  	}
80  
81  }