ca.weblite.objc
Class TypeMapper

java.lang.Object
  extended by ca.weblite.objc.TypeMapper
All Implemented Interfaces:
TypeMapping

public class TypeMapper
extends Object
implements TypeMapping

Maps Objective-C types to Java types. This provides automatic conversion to message inputs and outputs (unless coercion is disabled in the message request). In many cases, it just passes the values straight through (e.g. primitive types. Notably, Java Strings are mapped to NSStrings if the signature of the argument context is an NSString, and NSObjects are mapped as Proxy wrapper objects.

Author:
shannah

Constructor Summary
TypeMapper()
           
 
Method Summary
 TypeMapper addMapping(TypeMapping mapping, String... signatures)
          Adds a TypeMapping that is meant to handle one or more signatures.
 Object cToJ(Object cVar, String signature, TypeMapping root)
          Converts a C variable to the corresponding Java type based on the specified signature.
static TypeMapper getInstance()
          Obtains the singleton instance of the TypeMapper
 Object jToC(Object jVar, String signature, TypeMapping root)
          Converts a Java variable to the corresponding C type based on the specified signature.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeMapper

public TypeMapper()
Method Detail

getInstance

public static TypeMapper getInstance()
Obtains the singleton instance of the TypeMapper

Returns:

addMapping

public TypeMapper addMapping(TypeMapping mapping,
                             String... signatures)
Adds a TypeMapping that is meant to handle one or more signatures.

Parameters:
mapping - The TypeMapping object meant to handle conversions for the given signatures.
signatures - One or more signatures following Objective-C type encodings.
Returns:
Self for chaining.

cToJ

public Object cToJ(Object cVar,
                   String signature,
                   TypeMapping root)
Converts a C variable to the corresponding Java type based on the specified signature. By default, this will map scalars straight across without change. Strings are mapped to NSStrings.

Specified by:
cToJ in interface TypeMapping
Parameters:
cVar - The C variable that is to be converted.
signature - The signature that provides the context of what the variable is expected to be in the Objective-C runtime. This follows Objective-C type encoding conventions.
root - This should be the root TypeMapping. Usually you just pass TypeMapper.getInstance() here.
Returns:
The converted Java object.

jToC

public Object jToC(Object jVar,
                   String signature,
                   TypeMapping root)
Converts a Java variable to the corresponding C type based on the specified signature. By default, this will map scalars straight across without change. Strings are mapped to NSStrings.
Example Usage

The following is a modified snippet from the NSObject class that shows (roughly) how the jToC method is used to take the output of a Java method and set the return value in an NSInvocation object to a corresponding C type.:

Specified by:
jToC in interface TypeMapping
Parameters:
jVar - The C variable that is to be converted.
signature - The signature that provides the context of what the variable is expected to be in the Objective-C runtime. This follows Objective-C type encoding conventions.
root - This should be the root TypeMapping. Usually you just pass TypeMapper.getInstance() here.
Returns:
The converted C value.


Copyright © 2012–2014 Web Lite Solutions Corp.. All rights reserved.