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