JClass bim = inMemoryType.boxify();
adapter._extends(getCodeModel().ref(XmlAdapter.class).narrow(String.class).narrow(bim));
JMethod unmarshal = adapter.method(JMod.PUBLIC, bim, "unmarshal");
JVar $value = unmarshal.param(String.class, "value");
JExpression inv;
if( parseMethod.equals("new") ) {
// "new" indicates that the constructor of the target type
// will do the unmarshalling.
// RESULT: new <type>()
inv = JExpr._new(bim).arg($value);
} else {
int idx = parseMethod.lastIndexOf('.');
if(idx<0) {
// parseMethod specifies the static method of the target type
// which will do the unmarshalling.
// because of an error check at the constructor,
// we can safely assume that this cast works.
inv = bim.staticInvoke(parseMethod).arg($value);
} else {
inv = JExpr.direct(parseMethod+"(value)");
}
}
unmarshal.body()._return(inv);
JMethod marshal = adapter.method(JMod.PUBLIC, String.class, "marshal");
$value = marshal.param(bim,"value");
if(printMethod.startsWith("javax.xml.bind.DatatypeConverter.")) {
// UGLY: if this conversion is the system-driven conversion,
// check for null
marshal.body()._if($value.eq(JExpr._null()))._then()._return(JExpr._null());
}
int idx = printMethod.lastIndexOf('.');
if(idx<0) {
// printMethod specifies a method in the target type
// which performs the serialization.
// RESULT: <value>.<method>()
inv = $value.invoke(printMethod);
// check value is not null ... if(value == null) return null;
JConditional jcon = marshal.body()._if($value.eq(JExpr._null()));
jcon._then()._return(JExpr._null());
} else {
// RESULT: <className>.<method>(<value>)
if(this.printMethod==null) {
// HACK HACK HACK