org.springframework.scripting.jruby
Class JRubyScriptUtils

java.lang.Object
  extended by org.springframework.scripting.jruby.JRubyScriptUtils

public abstract class JRubyScriptUtils
extends java.lang.Object

Utility methods for handling JRuby-scripted objects.

As of Spring 3.0, this class requires JRuby 1.1 or higher.

Since:
2.0
Author:
Rob Harrop, Juergen Hoeller, Rick Evans

Nested Class Summary
static class JRubyScriptUtils.JRubyExecutionException
          Exception thrown in response to a JRuby RaiseException being thrown from a JRuby method invocation.
private static class JRubyScriptUtils.RubyObjectInvocationHandler
          InvocationHandler that invokes a JRuby script method.
 
Constructor Summary
JRubyScriptUtils()
           
 
Method Summary
static java.lang.Object createJRubyObject(java.lang.String scriptSource, java.lang.Class[] interfaces)
          Create a new JRuby-scripted object from the given script source, using the default ClassLoader.
static java.lang.Object createJRubyObject(java.lang.String scriptSource, java.lang.Class[] interfaces, java.lang.ClassLoader classLoader)
          Create a new JRuby-scripted object from the given script source.
private static java.lang.String findClassName(Node rootNode)
          Given the root Node in a JRuby AST will locate the name of the class defined by that AST.
private static ClassNode findClassNode(Node node)
          Find the first ClassNode under the supplied Node.
private static Ruby initializeRuntime()
          Initializes an instance of the org.jruby.Ruby runtime.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JRubyScriptUtils

public JRubyScriptUtils()
Method Detail

createJRubyObject

public static java.lang.Object createJRubyObject(java.lang.String scriptSource,
                                                 java.lang.Class[] interfaces)
                                          throws JumpException
Create a new JRuby-scripted object from the given script source, using the default ClassLoader.

Parameters:
scriptSource - the script source text
interfaces - the interfaces that the scripted Java object is to implement
Returns:
the scripted Java object
Throws:
JumpException - in case of JRuby parsing failure
See Also:
ClassUtils.getDefaultClassLoader()

createJRubyObject

public static java.lang.Object createJRubyObject(java.lang.String scriptSource,
                                                 java.lang.Class[] interfaces,
                                                 java.lang.ClassLoader classLoader)
Create a new JRuby-scripted object from the given script source.

Parameters:
scriptSource - the script source text
interfaces - the interfaces that the scripted Java object is to implement
classLoader - the ClassLoader to create the script proxy with
Returns:
the scripted Java object
Throws:
JumpException - in case of JRuby parsing failure

initializeRuntime

private static Ruby initializeRuntime()
Initializes an instance of the org.jruby.Ruby runtime.


findClassName

private static java.lang.String findClassName(Node rootNode)
Given the root Node in a JRuby AST will locate the name of the class defined by that AST.

Throws:
java.lang.IllegalArgumentException - if no class is defined by the supplied AST

findClassNode

private static ClassNode findClassNode(Node node)
Find the first ClassNode under the supplied Node.

Returns:
the found ClassNode, or null if no ClassNode is found