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
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,  
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 package org.hibernate.validator.internal.util.scriptengine;
 
 
 
 import static org.hibernate.validator.internal.util.logging.Messages.MESSAGES;


Factory responsible for the creation of ScriptEvaluators. This class is thread-safe.

Author(s):
Gunnar Morling
Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI
 
 public class ScriptEvaluatorFactory {
 
 	private static final Log log = LoggerFactory.make();

A reference with an instance of this factory. Allows the factory to be reused several times, but can be GC'ed if required.
 
A cache of script executors (keyed by language name).
 
 
 	private ScriptEvaluatorFactory() {
 	}

Retrieves an instance of this factory.

Returns:
A script evaluator factory. Never null.
 
 	public static synchronized ScriptEvaluatorFactory getInstance() {
 
 
 		if ( theValue == null ) {
 			theValue = new ScriptEvaluatorFactory();
 			 = new SoftReference<ScriptEvaluatorFactory>( theValue );
 		}
 
 		return theValue;
 	}

Retrieves a script executor for the given language.

Parameters:
languageName The name of a scripting language as expected by javax.script.ScriptEngineManager.getEngineByName(java.lang.String).
Returns:
A script executor for the given language. Never null.
Throws:
javax.script.ScriptException In case no JSR 223 compatible engine for the given language could be found.
 
 
 		if ( !.containsKeylanguageName ) ) {
 
 			ScriptEvaluator scriptExecutor = createNewScriptEvaluatorlanguageName );
 			.putIfAbsentlanguageNamescriptExecutor );
 		}
 
 		return .getlanguageName );
 	}

Creates a new script executor for the given language.

Parameters:
languageName A JSR 223 language name.
Returns:
A newly created script executor for the given language.
Throws:
javax.script.ScriptException In case no JSR 223 compatible engine for the given language could be found.
		ScriptEngine engine = new ScriptEngineManager().getEngineByNamelanguageName );
		if ( engine == null ) {
			throw new ScriptException.unableToFindScriptEnginelanguageName ) );
		}
		return new ScriptEvaluatorengine );
	}
New to GrepCode? Check out our FAQ X