Top Description Inners Constructors Methods
org.springframework.scripting.bsh

public abstract Class BshScriptUtils

extends Object
Class Inheritance
Imports
java.lang.reflect.InvocationHandler, .Method, .Proxy, bsh.EvalError, .Interpreter, .Primitive, .XThis, org.springframework.core.NestedRuntimeException, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .ObjectUtils, .ReflectionUtils

Utility methods for handling BeanShell-scripted objects.
Authors
Rob Harrop, Juergen Hoeller
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
BshScriptUtils.BshExecutionException

Exception to be thrown on script execution failure.

private static class
BshScriptUtils.BshObjectInvocationHandler

InvocationHandler that invokes a BeanShell script method.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static Object

Returns:

the scripted Java object
createBshObject
(String
the script source text
scriptSource
)

Create a new BeanShell-scripted object from the given script source.

public static Object

Returns:

the scripted Java object
createBshObject
(String
the script source text
scriptSource
,
Class<?>...
the interfaces that the scripted Java object is supposed to implement (may be null or empty if the script itself declares a full class or returns an actual instance of the scripted object)
scriptInterfaces
)

Create a new BeanShell-scripted object from the given script source, using the default ClassLoader.

public static Object

Returns:

the scripted Java object
createBshObject
(String
the script source text
scriptSource
,
Class<?>[]
the interfaces that the scripted Java object is supposed to implement (may be null or empty if the script itself declares a full class or returns an actual instance of the scripted object)
scriptInterfaces
,
ClassLoader
the ClassLoader to use for evaluating the script
classLoader
)

Create a new BeanShell-scripted object from the given script source.

pack-priv static Class<?>

Returns:

the scripted Java class, or null if none could be determined
determineBshObjectType
(String
the script source text
scriptSource
,
ClassLoader
the ClassLoader to use for evaluating the script
classLoader
)

Evaluate the specified BeanShell script based on the given script source, returning the Class defined by the script.

pack-priv static Object

Returns:

the scripted Java class or Java object
evaluateBshScript
(String
the script source text
scriptSource
,
Class<?>[]
the interfaces that the scripted Java object is supposed to implement (may be null or empty if the script itself declares a full class or returns an actual instance of the scripted object)
scriptInterfaces
,
ClassLoader
the ClassLoader to use for evaluating the script
classLoader
)

Evaluate the specified BeanShell script based on the given script source, keeping a returned script Class or script Object as-is.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

BshScriptUtilsback to summary
public BshScriptUtils()

Method Detail

createBshObjectback to summary
public static Object createBshObject(String scriptSource) throws EvalError

Create a new BeanShell-scripted object from the given script source.

With this createBshObject variant, the script needs to declare a full class or return an actual instance of the scripted object.

Parameters
scriptSource:String

the script source text

Returns:Object

the scripted Java object

Exceptions
EvalError:
in case of BeanShell parsing failure
createBshObjectback to summary
public static Object createBshObject(String scriptSource, Class<?>... scriptInterfaces) throws EvalError

Create a new BeanShell-scripted object from the given script source, using the default ClassLoader.

The script may either be a simple script that needs a corresponding proxy generated (implementing the specified interfaces), or declare a full class or return an actual instance of the scripted object (in which case the specified interfaces, if any, need to be implemented by that class/instance).

Parameters
scriptSource:String

the script source text

scriptInterfaces:Class<?>[]

the interfaces that the scripted Java object is supposed to implement (may be null or empty if the script itself declares a full class or returns an actual instance of the scripted object)

Returns:Object

the scripted Java object

Exceptions
EvalError:
in case of BeanShell parsing failure
See Also
createBshObject(String, Class[], ClassLoader)
createBshObjectback to summary
public static Object createBshObject(String scriptSource, Class<?>[] scriptInterfaces, ClassLoader classLoader) throws EvalError

Create a new BeanShell-scripted object from the given script source.

The script may either be a simple script that needs a corresponding proxy generated (implementing the specified interfaces), or declare a full class or return an actual instance of the scripted object (in which case the specified interfaces, if any, need to be implemented by that class/instance).

Parameters
scriptSource:String

the script source text

scriptInterfaces:Class<?>[]

the interfaces that the scripted Java object is supposed to implement (may be null or empty if the script itself declares a full class or returns an actual instance of the scripted object)

classLoader:ClassLoader

the ClassLoader to use for evaluating the script

Returns:Object

the scripted Java object

Exceptions
EvalError:
in case of BeanShell parsing failure
determineBshObjectTypeback to summary
pack-priv static Class<?> determineBshObjectType(String scriptSource, ClassLoader classLoader) throws EvalError

Evaluate the specified BeanShell script based on the given script source, returning the Class defined by the script.

The script may either declare a full class or return an actual instance of the scripted object (in which case the Class of the object will be returned). In any other case, the returned Class will be null.

Parameters
scriptSource:String

the script source text

classLoader:ClassLoader

the ClassLoader to use for evaluating the script

Returns:Class<?>

the scripted Java class, or null if none could be determined

Annotations
@Nullable
Exceptions
EvalError:
in case of BeanShell parsing failure
evaluateBshScriptback to summary
pack-priv static Object evaluateBshScript(String scriptSource, Class<?>[] scriptInterfaces, ClassLoader classLoader) throws EvalError

Evaluate the specified BeanShell script based on the given script source, keeping a returned script Class or script Object as-is.

The script may either be a simple script that needs a corresponding proxy generated (implementing the specified interfaces), or declare a full class or return an actual instance of the scripted object (in which case the specified interfaces, if any, need to be implemented by that class/instance).

Parameters
scriptSource:String

the script source text

scriptInterfaces:Class<?>[]

the interfaces that the scripted Java object is supposed to implement (may be null or empty if the script itself declares a full class or returns an actual instance of the scripted object)

classLoader:ClassLoader

the ClassLoader to use for evaluating the script

Returns:Object

the scripted Java class or Java object

Exceptions
EvalError:
in case of BeanShell parsing failure
org.springframework.scripting.bsh back to summary

public final Class BshScriptUtils.BshExecutionException

extends NestedRuntimeException
Class Inheritance
Annotations
@SuppressWarnings:serial

Exception to be thrown on script execution failure.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from org.springframework.core.NestedRuntimeException:
containsgetMostSpecificCausegetRootCause

Constructor Detail

BshExecutionExceptionback to summary
private BshExecutionException(EvalError ex)
org.springframework.scripting.bsh back to summary

private Class BshScriptUtils.BshObjectInvocationHandler

extends Object
implements InvocationHandler
Class Inheritance
  • java.lang.Object
  • org.springframework.scripting.bsh.BshScriptUtils.BshObjectInvocationHandler
All Implemented Interfaces
java.lang.reflect.InvocationHandler

InvocationHandler that invokes a BeanShell script method.

Field Summary

Modifier and TypeField and Description
private final XThis

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object
invoke(Object
the proxy instance that the method was invoked on
proxy
,
Method
the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.
method
,
Object[]
an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.
args
)

Implements java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result.
private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

xtback to summary
private final XThis xt

Constructor Detail

BshObjectInvocationHandlerback to summary
public BshObjectInvocationHandler(XThis xt)

Method Detail

invokeback to summary
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable

Implements java.lang.reflect.InvocationHandler.invoke.

Doc from java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.

Parameters
proxy:Object

the proxy instance that the method was invoked on

method:Method

the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.

args:Object[]

an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.

Returns:Object

the value to return from the method invocation on the proxy instance. If the declared return type of the interface method is a primitive type, then the value returned by this method must be an instance of the corresponding primitive wrapper class; otherwise, it must be a type assignable to the declared return type. If the value returned by this method is null and the interface method's return type is primitive, then a NullPointerException will be thrown by the method invocation on the proxy instance. If the value returned by this method is otherwise not compatible with the interface method's declared return type as described above, a ClassCastException will be thrown by the method invocation on the proxy instance.

Annotations
@Override
@Nullable
Exceptions
Throwable:
the exception to throw from the method invocation on the proxy instance. The exception's type must be assignable either to any of the exception types declared in the throws clause of the interface method or to the unchecked exception types java.lang.RuntimeException or java.lang.Error. If a checked exception is thrown by this method that is not assignable to any of the exception types declared in the throws clause of the interface method, then an UndeclaredThrowableException containing the exception that was thrown by this method will be thrown by the method invocation on the proxy instance.
isProxyForSameBshObjectback to summary
private boolean isProxyForSameBshObject(Object obj)