public static final TypeMapper UNICODE = new W32APITypeMapper(true);
public static final TypeMapper ASCII = new W32APITypeMapper(false);
protected W32APITypeMapper(boolean unicode) {
if (unicode) {
TypeConverter stringConverter = new TypeConverter() {
public Object toNative(Object value, ToNativeContext context) {
if (value == null)
return null;
if (value instanceof String[]) {
return new StringArray((String[])value, true);
}
return new WString(value.toString());
}
public Object fromNative(Object value, FromNativeContext context) {
if (value == null)
return null;
return ((Pointer)value).getString(0, true);
}
public Class nativeType() {
return Pointer.class;
}
};
addTypeConverter(String.class, stringConverter);
addToNativeConverter(String[].class, stringConverter);
}
TypeConverter booleanConverter = new TypeConverter() {
public Object toNative(Object value, ToNativeContext context) {
return new Integer(Boolean.TRUE.equals(value) ? 1 : 0);
}
public Object fromNative(Object value, FromNativeContext context) {
return Boolean.valueOf(((Integer)value).intValue() != 0);