Package com.sun.jna
Class DefaultTypeMapper
- java.lang.Object
-
- com.sun.jna.DefaultTypeMapper
-
- All Implemented Interfaces:
TypeMapper
- Direct Known Subclasses:
W32APITypeMapper
public class DefaultTypeMapper extends java.lang.Object implements TypeMapper
Provide custom mappings to and from native types. The default lookup checks classes corresponding to converters in the order added; if the class to be converted is an instance of the converter's registered class, the converter will be used.Derived classes should install additional converters using
addToNativeConverter(java.lang.Class<?>, com.sun.jna.ToNativeConverter)and/oraddFromNativeConverter(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 bothint.classandInteger.class). If you want different mapping behavior than the default, simply overridegetToNativeConverter(java.lang.Class<?>)andgetFromNativeConverter(java.lang.Class<?>).- See Also:
Library.OPTION_TYPE_MAPPER
-
-
Constructor Summary
Constructors Constructor Description DefaultTypeMapper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFromNativeConverter(java.lang.Class<?> cls, FromNativeConverter converter)Add aFromNativeConverterto convert a native result type into the given Java type.voidaddToNativeConverter(java.lang.Class<?> cls, ToNativeConverter converter)Add aToNativeConverterto define the conversion into a native type from arguments of the given Java type.voidaddTypeConverter(java.lang.Class<?> cls, TypeConverter converter)Add aTypeConverterto provide bidirectional mapping between a native and Java type.FromNativeConvertergetFromNativeConverter(java.lang.Class<?> javaType)Return theFromNativeConverterappropriate for the given Java class.ToNativeConvertergetToNativeConverter(java.lang.Class<?> javaType)Return theToNativeConverterappropriate for the given Java class.
-
-
-
Method Detail
-
addToNativeConverter
public void addToNativeConverter(java.lang.Class<?> cls, ToNativeConverter converter)Add aToNativeConverterto define the conversion into a native type from arguments of the given Java type. Converters are checked for in the order added.- Parameters:
cls- Java class requiring conversionconverter-ToNativeConverterto transform an object of the given Java class into its native-compatible form.
-
addFromNativeConverter
public void addFromNativeConverter(java.lang.Class<?> cls, FromNativeConverter converter)Add aFromNativeConverterto convert a native result type into the given Java type. Converters are checked for in the order added.- Parameters:
cls- Java class for the Java representation of a native type.converter-FromNativeConverterto transform a native-compatible type into its Java equivalent.
-
addTypeConverter
public void addTypeConverter(java.lang.Class<?> cls, TypeConverter converter)Add aTypeConverterto provide bidirectional mapping between a native and Java type.- Parameters:
cls- Java class representation for a native typeconverter-TypeConverterto translate between native and Java types.
-
getFromNativeConverter
public FromNativeConverter getFromNativeConverter(java.lang.Class<?> javaType)
Description copied from interface:TypeMapperReturn theFromNativeConverterappropriate for the given Java class.- Specified by:
getFromNativeConverterin interfaceTypeMapper- Parameters:
javaType- Java class representation of the native type.- Returns:
- Converter from the native-compatible type.
-
getToNativeConverter
public ToNativeConverter getToNativeConverter(java.lang.Class<?> javaType)
Description copied from interface:TypeMapperReturn theToNativeConverterappropriate for the given Java class.- Specified by:
getToNativeConverterin interfaceTypeMapper- Parameters:
javaType- Java class representation of the native type.- Returns:
- Converter to the native-compatible type.
-
-