public class DefaultTypeMapper extends java.lang.Object implements TypeMapper
Derived classes should install additional converters using
addToNativeConverter(java.lang.Class<?>, com.sun.jna.ToNativeConverter)
and/or addFromNativeConverter(java.lang.Class<?>, com.sun.jna.FromNativeConverter)
in the default constructor. Classes
for primitive types will automatically register for the corresponding
Object type and vice versa (i.e. you don't have to register both
int.class
and Integer.class
).
If you want different mapping behavior than the default, simply override
getToNativeConverter(java.lang.Class<?>)
and getFromNativeConverter(java.lang.Class<?>)
.
Library.OPTION_TYPE_MAPPER
Constructor and Description |
---|
DefaultTypeMapper() |
Modifier and Type | Method and Description |
---|---|
void |
addFromNativeConverter(java.lang.Class<?> cls,
FromNativeConverter converter)
Add a
FromNativeConverter to convert a native result type into the
given Java type. |
void |
addToNativeConverter(java.lang.Class<?> cls,
ToNativeConverter converter)
Add a
ToNativeConverter to define the conversion into a native
type from arguments of the given Java type. |
void |
addTypeConverter(java.lang.Class<?> cls,
TypeConverter converter)
Add a
TypeConverter to provide bidirectional mapping between
a native and Java type. |
FromNativeConverter |
getFromNativeConverter(java.lang.Class<?> javaType)
Return the
FromNativeConverter appropriate for the given Java class. |
ToNativeConverter |
getToNativeConverter(java.lang.Class<?> javaType)
Return the
ToNativeConverter appropriate for the given Java class. |
public void addToNativeConverter(java.lang.Class<?> cls, ToNativeConverter converter)
ToNativeConverter
to define the conversion into a native
type from arguments of the given Java type. Converters are
checked for in the order added.cls
- Java class requiring conversionconverter
- ToNativeConverter
to transform an object of
the given Java class into its native-compatible form.public void addFromNativeConverter(java.lang.Class<?> cls, FromNativeConverter converter)
FromNativeConverter
to convert a native result type into the
given Java type. Converters are checked for in the order added.cls
- Java class for the Java representation of a native type.converter
- FromNativeConverter
to transform a
native-compatible type into its Java equivalent.public void addTypeConverter(java.lang.Class<?> cls, TypeConverter converter)
TypeConverter
to provide bidirectional mapping between
a native and Java type.cls
- Java class representation for a native typeconverter
- TypeConverter
to translate between native and
Java types.public FromNativeConverter getFromNativeConverter(java.lang.Class<?> javaType)
TypeMapper
FromNativeConverter
appropriate for the given Java class.getFromNativeConverter
in interface TypeMapper
javaType
- Java class representation of the native type.public ToNativeConverter getToNativeConverter(java.lang.Class<?> javaType)
TypeMapper
ToNativeConverter
appropriate for the given Java class.getToNativeConverter
in interface TypeMapper
javaType
- Java class representation of the native type.