org.jruby.runtime
Class MethodFactory

java.lang.Object
  extended by org.jruby.runtime.MethodFactory
Direct Known Subclasses:
InvocationMethodFactory, ReflectionMethodFactory

public abstract class MethodFactory
extends java.lang.Object

MethodFactory is used to generate "invokers" or "method handles" given a target class, method name, and other characteristics. In order to bind methods into Ruby's reified class hierarchy, we need a way to treat individual methods as objects. Implementers of this class provide that functionality.


Nested Class Summary
static interface MethodFactory.MethodDefiningCallback
          For batched method construction, the logic necessary to bind resulting method objects into a target module/class must be provided as a callback.
 
Field Summary
static java.lang.Class[] COMPILED_METHOD_PARAMS
          A Class[] representing the signature of compiled Ruby method.
 
Constructor Summary
MethodFactory()
           
 
Method Summary
static MethodFactory createFactory(java.lang.ClassLoader classLoader)
          Based on optional properties, create a new MethodFactory.
abstract  void defineIndexedAnnotatedMethods(RubyModule implementationClass, java.lang.Class containingClass, MethodFactory.MethodDefiningCallback callback)
          Add all annotated methods on the target Java class to the specified Ruby class using the semantics of getAnnotatedMethod, calling back to the specified callback for each method to allow the caller to bind each method.
abstract  DynamicMethod getAnnotatedMethod(RubyModule implementationClass, JavaMethodDescriptor desc)
          Based on an annotated Java method object, generate a method handle using the annotation and the target signature.
abstract  DynamicMethod getAnnotatedMethod(RubyModule implementationClass, java.util.List<JavaMethodDescriptor> desc)
          Based on a list of annotated Java methods, generate a method handle using the annotation and the target signatures.
abstract  DynamicMethod getCompiledMethod(RubyModule implementationClass, java.lang.String method, Arity arity, Visibility visibility, StaticScope scope, java.lang.Object scriptObject, CallConfiguration callConfig)
          Get a new method handle based on the target JRuby-compiled method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPILED_METHOD_PARAMS

public static final java.lang.Class[] COMPILED_METHOD_PARAMS
A Class[] representing the signature of compiled Ruby method.

Constructor Detail

MethodFactory

public MethodFactory()
Method Detail

createFactory

public static MethodFactory createFactory(java.lang.ClassLoader classLoader)
Based on optional properties, create a new MethodFactory. By default, this will create a code-generation-based InvocationMethodFactory. If security restricts code generation, ReflectionMethodFactory will be used. If we are dumping class definitions, DumpingInvocationMethodFactory will be used. See MethodFactory's static initializer for more details.

Parameters:
classLoader - The classloader to use for searching for and dynamically loading code.
Returns:
A new MethodFactory.

getCompiledMethod

public abstract DynamicMethod getCompiledMethod(RubyModule implementationClass,
                                                java.lang.String method,
                                                Arity arity,
                                                Visibility visibility,
                                                StaticScope scope,
                                                java.lang.Object scriptObject,
                                                CallConfiguration callConfig)
Get a new method handle based on the target JRuby-compiled method. Because compiled Ruby methods have additional requirements and characteristics not typically found in Java-based methods, this is provided as a separate way to define such method handles.

Parameters:
implementationClass - The class to which the method will be bound.
method - The name of the method
arity - The Arity of the method
visibility - The method's visibility on the target type.
scope - The methods static scoping information.
scriptObject - An instace of the target compiled method class.
callConfig - The call configuration to use for this method.
Returns:
A new method handle for the target compiled method.

getAnnotatedMethod

public abstract DynamicMethod getAnnotatedMethod(RubyModule implementationClass,
                                                 java.util.List<JavaMethodDescriptor> desc)
Based on a list of annotated Java methods, generate a method handle using the annotation and the target signatures. The annotation and signatures will be used to dynamically generate the appropriate call logic for the handle. This differs from the single-method version in that it will dispatch multiple specific-arity paths to different target methods.

Parameters:
implementationClass - The target class or module on which the method will be bound.
descs - A list of JavaMethodDescriptors describing the target methods
Returns:
A method handle for the target object.

getAnnotatedMethod

public abstract DynamicMethod getAnnotatedMethod(RubyModule implementationClass,
                                                 JavaMethodDescriptor desc)
Based on an annotated Java method object, generate a method handle using the annotation and the target signature. The annotation and signature will be used to dynamically generate the appropriate call logic for the handle.

Parameters:
implementationClass - The target class or module on which the method will be bound.
desc - A JavaMethodDescriptor describing the target method
Returns:
A method handle for the target object.

defineIndexedAnnotatedMethods

public abstract void defineIndexedAnnotatedMethods(RubyModule implementationClass,
                                                   java.lang.Class containingClass,
                                                   MethodFactory.MethodDefiningCallback callback)
Add all annotated methods on the target Java class to the specified Ruby class using the semantics of getAnnotatedMethod, calling back to the specified callback for each method to allow the caller to bind each method.

Parameters:
implementationClass - The target class or module on which the method will be bound.
containingClass - The Java class containined annotated methods to be bound.
callback - A callback provided by the caller which handles binding each method.


Copyright © 2002-2007 JRuby Team. All Rights Reserved.