org.jruby.javasupport
Class RubyProxyFactory

java.lang.Object
  extended byorg.jruby.javasupport.RubyProxyFactory

public class RubyProxyFactory
extends java.lang.Object

A RubyProxyFactory dispenses RubyProxy objects, which provide a convenient, dynamic wrapper around Ruby objects. A RubyProxyFactory must be initialized with a Ruby instance, presumably one which has been loaded with classes which you want to instantiate from Java, and an object implementing the RubyToJavaClassMap interface, which provides a way to map between Ruby and Java classes while converting arguments to and from method calls.

The API is composed of three primary method calls: newProxyObject, which creates a new RubyObject and returns a wrapper around it, getProxyForObject, which takes an existing RubyObject and returns a wrapper around it, and getProxyForGlobal, which finds the RubyObject stored in a Ruby global variable ($variable) and returns a wrapper around it.

Version:
$Revision: 1.5 $
Author:
schwardo

Constructor Summary
RubyProxyFactory(Ruby ruby, RubyToJavaClassMap classMap)
           
 
Method Summary
 IRubyObject[] convertJavaToRuby(java.lang.Object[] obj)
          Helper methods for RubyConversion (used by RubyInvocationHandler)
 java.lang.Object convertRubyToJava(IRubyObject obj, java.lang.Class type)
           
protected  java.lang.Class getJavaClassForRubyClass(RubyClass rubyClass)
           
 RubyProxy getProxyForGlobal(java.lang.String globalVar)
           
 RubyProxy getProxyForGlobal(java.lang.String globalVar, java.lang.Class javaInterface)
           
 RubyProxy getProxyForObject(IRubyObject obj)
          Create a wrapper around the specified RubyObject.
 RubyProxy getProxyForObject(IRubyObject obj, java.lang.Class javaInterface)
           
 Ruby getRuby()
           
protected  RubyClass getRubyClassForJavaClass(java.lang.Class javaClass)
          Helper methods for RubyToJavaClassMap
 RubyProxy newProxyObject(java.lang.Class javaInterface)
          Create a new instance of the RubyClass corresponding to the specified Java interface.
 RubyProxy newProxyObject(java.lang.Class javaInterface, java.lang.Object[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RubyProxyFactory

public RubyProxyFactory(Ruby ruby,
                        RubyToJavaClassMap classMap)
Method Detail

getRuby

public Ruby getRuby()

newProxyObject

public RubyProxy newProxyObject(java.lang.Class javaInterface)
Create a new instance of the RubyClass corresponding to the specified Java interface. Return a Java object that conforms to this Java interface, but implemented by the RubyClass.


newProxyObject

public RubyProxy newProxyObject(java.lang.Class javaInterface,
                                java.lang.Object[] args)

getProxyForGlobal

public RubyProxy getProxyForGlobal(java.lang.String globalVar)

getProxyForGlobal

public RubyProxy getProxyForGlobal(java.lang.String globalVar,
                                   java.lang.Class javaInterface)

getProxyForObject

public RubyProxy getProxyForObject(IRubyObject obj)
Create a wrapper around the specified RubyObject. Any method calls will be forwarded to the implementation of the RubyObject and any returned objects will be converted to their corresponding Java objects.


getProxyForObject

public RubyProxy getProxyForObject(IRubyObject obj,
                                   java.lang.Class javaInterface)

getRubyClassForJavaClass

protected RubyClass getRubyClassForJavaClass(java.lang.Class javaClass)
Helper methods for RubyToJavaClassMap


getJavaClassForRubyClass

protected java.lang.Class getJavaClassForRubyClass(RubyClass rubyClass)

convertJavaToRuby

public IRubyObject[] convertJavaToRuby(java.lang.Object[] obj)
Helper methods for RubyConversion (used by RubyInvocationHandler)


convertRubyToJava

public java.lang.Object convertRubyToJava(IRubyObject obj,
                                          java.lang.Class type)


Copyright © 2002 Jan Arne Petersen. All Rights Reserved.