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