Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 * JBoss, Home of Professional Open Source
 * Copyright 2010, Red Hat, Inc. and/or its affiliates, and individual contributors
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,  
* See the License for the specific language governing permissions and
* limitations under the License.
package org.hibernate.validator.internal.util.scriptengine;
A wrapper around JSR 223 javax.script.ScriptEngines. This class is thread-safe.

Gunnar Morling
Kevin Pollet <> (C) 2011 SERLI
public class ScriptEvaluator {
	private final ScriptEngine engine;

Creates a new script executor.

engine The engine to be wrapped.
	public ScriptEvaluator(ScriptEngine engine) {
		this. = engine;

Makes the given object available in then engine-scoped script context and executes the given script. The execution of the script happens either synchronized or unsynchronized, depending on the engine's threading abilities.

script The script to be executed.
obj The object to be put into the context.
objectAlias The name under which the given object shall be put into the context.
The script's result.
javax.script.ScriptException In case of any errors during script execution.
	public Object evaluate(String scriptObject objString objectAliasthrows ScriptException {
			return doEvaluatescriptobjobjectAlias );
		else {
			synchronized (  ) {
				return doEvaluatescriptobjobjectAlias );
	private Object doEvaluate(String scriptObject objString objectAliasthrows ScriptException {
		.putobjectAliasobj );
		return .evalscript );

Checks, whether the given engine is thread-safe or not.

True, if the given engine is thread-safe, false otherwise.
		String threadingType = (String.getFactory().getParameter"THREADING" );
		return "THREAD-ISOLATED".equalsthreadingType ) || "STATELESS".equalsthreadingType );
New to GrepCode? Check out our FAQ X