NativeRuntime

public abstract class NativeRuntime

The parent of every NativeRuntime.

The runtimes are responsible for handling language environments like C, Objective-C and others. The runtimes have three kinds of default Mapper implementations: object, string and callback mappers. Whenever a native method or one of its arguments has no explicitly given mapper specified with the org.moe.natj.general.ann.MappedReturn or org.moe.natj.general.ann.Mapped annotations, then NatJ will use one of these default mappers of the determined responsible runtime instance.

Fields

callbackMapper

protected Mapper callbackMapper

Default mapper for handling callbacks.

objectMapper

protected Mapper objectMapper

Default mapper for handling objects.

stringMapper

protected Mapper stringMapper

Default mapper for handling strings.

Constructors

NativeRuntime

protected NativeRuntime(Class<?> objectMapperClass, Class<?> stringMapperClass, Class<?> callbackMapperClass)

Constructs the runtime and registers the default mappers.

Parameters:
  • objectMapperClass – The default mapper for objects
  • stringMapperClass – The default mapper for strings
  • callbackMapperClass – The default mapper for callbacks

Methods

createMapper

protected Mapper createMapper(Class<?> mapperClass)

Constructs a mapper of the given mapperClass class.

Parameters:
  • mapperClass – The mapper class we want to instantiate
Returns:

The instance

doRegistration

protected abstract void doRegistration(Class<?> type)

Registers a class.

Parameters:
  • type – The type we want to register.

getCallbackMapper

public Mapper getCallbackMapper()

Returns the default mapper for callbacks.

Returns:The default callback mapper.

getDefaultUnboxPolicy

public abstract byte getDefaultUnboxPolicy()

Returns the default unbox policy for variadic arguments.

Returns:The default unbox policy.

getMapper

public Mapper getMapper(Class<?> mapperClass)

Returns an instance of a the given mapperClass class.

The instances are cached in the class2mapper collection, so every class will have only one instance.

Parameters:
  • mapperClass – The mapper class we want to get an instance of
Returns:

The instance

getObjectMapper

public Mapper getObjectMapper()

Returns the default mapper for objects.

Returns:The default object mapper.

getStringMapper

public Mapper getStringMapper()

Returns the default mapper for strings.

Returns:The default string mapper.

tryToDisposeCallback

public abstract void tryToDisposeCallback(Object callback)

Disposes the callbacks created for the given object.

Parameters:
  • callback – The callback we want to dispose.