001/* 002 * Copyright 2002-2015 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.scripting; 018 019import java.util.Map; 020 021import org.springframework.lang.Nullable; 022 023/** 024 * Spring's strategy interface for evaluating a script. 025 * 026 * <p>Aside from language-specific implementations, Spring also ships 027 * a version based on the standard {@code javax.script} package (JSR-223): 028 * {@link org.springframework.scripting.support.StandardScriptEvaluator}. 029 * 030 * @author Juergen Hoeller 031 * @author Costin Leau 032 * @since 4.0 033 */ 034public interface ScriptEvaluator { 035 036 /** 037 * Evaluate the given script. 038 * @param script the ScriptSource for the script to evaluate 039 * @return the return value of the script, if any 040 * @throws ScriptCompilationException if the evaluator failed to read, 041 * compile or evaluate the script 042 */ 043 @Nullable 044 Object evaluate(ScriptSource script) throws ScriptCompilationException; 045 046 /** 047 * Evaluate the given script with the given arguments. 048 * @param script the ScriptSource for the script to evaluate 049 * @param arguments the key-value pairs to expose to the script, 050 * typically as script variables (may be {@code null} or empty) 051 * @return the return value of the script, if any 052 * @throws ScriptCompilationException if the evaluator failed to read, 053 * compile or evaluate the script 054 */ 055 @Nullable 056 Object evaluate(ScriptSource script, @Nullable Map<String, Object> arguments) throws ScriptCompilationException; 057 058}