SJava (version 0.98.0)

setJavaConverter: Add a converter from Java to an R object

Description

Register a C routine which converts a Java object to an R object. This occurs when a value is returned from a Java method (or constructor) call via .Java or .JavaConstructor.

Usage

setJavaConverter(handler, matcher=-1, autoArray=TRUE, description="", userObject=NULL, register = TRUE)

Arguments

handler
The name of a C routine that performs the conversion from the Java object to the R object. This is given the Java object, the class of that object, the JNI environment and the element in the converter object is to be called when the the matcher determines that
matcher
The name of a routine that is used to determine whether this converter can handle a specific object. This can also be specified as an element of the vector .javaMatchFunctions, either as (part of) a name of an element or the integer value. These are then used to identify one of the built-in converter matching functions.
autoArray
A logical value indicating whether this converter routine can be called element-wise for an array of the class type it matches (TRUE) , or whether it wishes to defer the handling of such an array to another converter or deal with it all in one step.
description
A string that describes the action of the converter (e.g. the type of source Java class and target R object on which it operates). This is stored with the internal converter and accessible to users via the getJavaConverterDescriptions.
userObject
If the matcher argument identifies one of the built-in matching routines (i.e. assignable from, instance of, equals) this is interpreted as a Java class identifier. That is either a class name (which is resoloved, and expanded as necessary, by Omegahat) and used to parameterize the particular use matching routine.
register
a logical value indicating whether this call should also notify Java that the specified class (i.e. that given in userObject) is convertible. This calls setJavaConvertible with the class and matching mechanism specified for this function.

Value

This returns the expanded named of the class used to parameterize the matching function and the identifier for the matching function itself.
match
the value passed to the C routine identifying the matching function. This is either an element from .javaMatchFunctions (hence a named integer) or a string identifying the C routine.
class
The name of the class used to parameterize the matching function, if the latter is one of the built-in routines named in .javaMatchFunctions. The class name is resolved by Omegahat and converted to use `/' instead of `.' to separate the Java packages. This is so that it can be easily used in the native C code.
index
the position in the list into which this converter was added. This is useful if we want to remove the converter at a later stage via removeJavaConverter.
description
the description argument passed to this function call. As with the index field, this is useful when we wish to remove the converter as it acts as an identifier for the converter. See removeJavaConverter.

References

http://www.omegahat.org, http://www.javasoft.com

See Also

getJavaConverterDescriptions getNumJavaConverters setJavaConvertible

Examples

Run this code
## Not run: 
#  setJavaConverter(.RSJava.symbol("RealVariableConverter"),
#                   matcher="AssignableFrom",
#                   autoArray=TRUE,
#                   description="Omegahat RealVariable to numeric vector",
#                   userObject="RealVariable")
# ## End(Not run)

Run the code above in your browser using DataLab