jdynamicCompile: Dynamically Compile a Java Class

Description Usage Arguments Author(s) References Examples

Description

This uses the dynamic byte-code generator facility in Omegahat to create a new Java class with a given name. By default, the new class extends the RForeignReference class and implements a specifiable collection of Java interfaces. Each method in these interfaces is implemented by calling the corresponding R function in the R reference object.

Usage

1
2
3
jdynamicCompile(interface, newClass,
                generatorClass="ForeignReferenceClassGenerator",
                load=TRUE)

Arguments

interface

the (fully qualified) name of one or more Java interface classes that the new class should implement. The methods in these interfaces are implemented as calls to the correspondingly named R function in the R object identified by the RForeignReference's key.

newClass

the name of the new class to be created.

generatorClass

the name of the Java class to which is to be used as the dynamic compiler. This is rarely specified, but allows one to use classes that implement the code differently, e.g. by extending ForeignReferenceClassGenerator.

load

logical value indicating whether the new class should be loaded into the Omegahat list of available classes. If this is FALSE, one usually writes the newly generated class definition to a file.

Author(s)

Duncan Temple Lang

References

http://www.omegahat.org

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
 ## Not run: 
  jdynamicCompile("java.awt.event.ActionListener", "RActionListener")
  l <- .JNew("RActionListener",
             foreignReference(list(actionPerformed=function() print("ok"))))
  button$add(l)
 
## End(Not run)

## Not run: 
  def <- jdynamicCompile("java.awt.event.ActionListener",
                         "RActionListener", load=F)
  def$write()
 
## End(Not run)

SJava documentation built on Oct. 5, 2016, 4:17 a.m.

Related to jdynamicCompile in SJava...