001/*
002 * Copyright 2002-2014 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.standard;
018
019import org.springframework.expression.ParseException;
020import org.springframework.expression.ParserContext;
021import org.springframework.expression.common.TemplateAwareExpressionParser;
022import org.springframework.expression.spel.SpelParserConfiguration;
023import org.springframework.util.Assert;
024
025/**
026 * SpEL parser. Instances are reusable and thread-safe.
027 *
028 * @author Andy Clement
029 * @author Juergen Hoeller
030 * @since 3.0
031 */
032public class SpelExpressionParser extends TemplateAwareExpressionParser {
033
034        private final SpelParserConfiguration configuration;
035
036
037        /**
038         * Create a parser with default settings.
039         */
040        public SpelExpressionParser() {
041                this.configuration = new SpelParserConfiguration();
042        }
043
044        /**
045         * Create a parser with the specified configuration.
046         * @param configuration custom configuration options
047         */
048        public SpelExpressionParser(SpelParserConfiguration configuration) {
049                Assert.notNull(configuration, "SpelParserConfiguration must not be null");
050                this.configuration = configuration;
051        }
052
053
054        public SpelExpression parseRaw(String expressionString) throws ParseException {
055                return doParseExpression(expressionString, null);
056        }
057
058        @Override
059        protected SpelExpression doParseExpression(String expressionString, ParserContext context) throws ParseException {
060                return new InternalSpelExpressionParser(this.configuration).doParseExpression(expressionString, context);
061        }
062
063}