org.clapper.util.scripting
Class UnifiedScriptEngineManager

java.lang.Object
  extended by org.clapper.util.scripting.UnifiedScriptEngineManager
Direct Known Subclasses:
BSFScriptEngineManager, JavaxScriptEngineManager

public abstract class UnifiedScriptEngineManager
extends java.lang.Object

A script engine manager that provides a common interface between the Apache Jakarta Bean Scripting Framework (BSF) and the Java 6 JSR 223 (javax.script) framework, allowing callers to use either underlying framework without changing code. This class is modeled on the JSR 223 interface, though it is much simpler.

Version:
$Revision: 6735 $

Constructor Summary
protected UnifiedScriptEngineManager()
          Creates a new instance of UnifiedScriptEngineManager
 
Method Summary
abstract  void clearBindings()
          Clear all current bindings.
abstract  java.lang.Object get(java.lang.String key)
          Get the value for a specified key in the object bindings.
abstract  java.util.Map<java.lang.String,java.lang.Object> getBindings()
          Get the global object bindings.
abstract  UnifiedScriptEngine getEngineByExtension(java.lang.String extension)
          Get a UnifiedScriptEngine for the specified language, by mapping a file name extension to the language.
abstract  UnifiedScriptEngine getEngineByName(java.lang.String language)
          Get a UnifiedScriptEngine for the specified language.
 UnifiedScriptEngine getEngineForFile(java.io.File file)
          Get a UnifiedScriptEngine for a given file, by using the file's extension.
static UnifiedScriptEngineManager getManager(ScriptFrameworkType type)
          Get the script engine manager for a specific underlying scripting framework.
static UnifiedScriptEngineManager getManager(ScriptFrameworkType[] types)
          Get the UnifiedScriptEngineManager for the first available underlying scripting framework.
abstract  ScriptFrameworkType getType()
          Get the framework type (ScriptFrameworkType associated with the UnifiedScriptEngineManager object.
abstract  void put(java.lang.String name, java.lang.Object object)
          Put an object into the script environment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnifiedScriptEngineManager

protected UnifiedScriptEngineManager()
Creates a new instance of UnifiedScriptEngineManager

Method Detail

getManager

public static final UnifiedScriptEngineManager getManager(ScriptFrameworkType type)
                                                   throws UnifiedScriptException
Get the script engine manager for a specific underlying scripting framework.

Parameters:
type - which underlying scripting framework to use
Throws:
UnifiedScriptException - on error
See Also:
getManager(ScriptFrameworkType[])

getManager

public static final UnifiedScriptEngineManager getManager(ScriptFrameworkType[] types)
                                                   throws UnifiedScriptException
Get the UnifiedScriptEngineManager for the first available underlying scripting framework. The order the frameworks are checked is the order they appear in the passed-in array.

Parameters:
types - the framework types to check, in order.
Returns:
the first framework found
Throws:
UnifiedScriptException - if no script managers could be found
See Also:
getType(), getManager(ScriptFrameworkType)

getType

public abstract ScriptFrameworkType getType()
Get the framework type (ScriptFrameworkType associated with the UnifiedScriptEngineManager object.

Returns:
the framework type

getBindings

public abstract java.util.Map<java.lang.String,java.lang.Object> getBindings()
                                                                      throws UnifiedScriptException
Get the global object bindings. Unlike JSR 223, this interface only supports global bindings (largely because BSF doesn't easily support anything other than global bindings.

Returns:
a Map of global bindings
Throws:
UnifiedScriptException - on error
See Also:
clearBindings(), put(java.lang.String, java.lang.Object)

clearBindings

public abstract void clearBindings()
                            throws UnifiedScriptException
Clear all current bindings.

Throws:
UnifiedScriptException - on error
See Also:
put(java.lang.String, java.lang.Object)

put

public abstract void put(java.lang.String name,
                         java.lang.Object object)
                  throws UnifiedScriptException
Put an object into the script environment. This operation is also known as "binding" an object to the scripting environment. If the scripting infrastructure supports different scopes (e.g., JSR 223), then this method puts the object in the global scope.

Parameters:
name - the name by which the object will be known to scripts
object - the object
Throws:
UnifiedScriptException - on error

get

public abstract java.lang.Object get(java.lang.String key)
Get the value for a specified key in the object bindings.

Parameters:
key - the key
Returns:
the bound object, or null

getEngineByName

public abstract UnifiedScriptEngine getEngineByName(java.lang.String language)
                                             throws UnifiedScriptException
Get a UnifiedScriptEngine for the specified language.

Parameters:
language - the language name
Returns:
the script engine, or null if no engine for that language can be found
Throws:
UnifiedScriptException - on error

getEngineByExtension

public abstract UnifiedScriptEngine getEngineByExtension(java.lang.String extension)
                                                  throws UnifiedScriptException
Get a UnifiedScriptEngine for the specified language, by mapping a file name extension to the language.

Parameters:
extension - the extension
Returns:
the script engine, or null if no engine for that language can be found
Throws:
UnifiedScriptException - on error

getEngineForFile

public UnifiedScriptEngine getEngineForFile(java.io.File file)
                                     throws UnifiedScriptException
Get a UnifiedScriptEngine for a given file, by using the file's extension.

Parameters:
file - the file
Returns:
he script engine, or null if no engine for that language can be found
Throws:
UnifiedScriptException - on error
See Also:
getEngineByExtension(java.lang.String)


Copyright © 2004-2007 Brian M. Clapper. All Rights Reserved.