JExpression propertyVar = getValue(builder, property, block);
if (!property.isXmlAny()) {
if (!toClass(property.getType()).isPrimitive()) {
JConditional nullCond = block._if(propertyVar.ne(JExpr._null()));
block = nullCond._then();
}
writeSimpleTypeAttribute(builder, block, property, propertyVar);
} else {
// if (value != null)
JConditional nullCond = block._if(propertyVar.ne(JExpr._null()));
String entryName = builder.getWriteVariableManager().createId(property.getName() + "Entry");
boolean needsCast = true;
if (property.getType() instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) property.getType();
Type[] arguments = parameterizedType.getActualTypeArguments();
if (arguments.length == 2 &&
QName.class.equals(arguments[0]) &&
property.getComponentType().equals(arguments[1])) {
needsCast = false;
}
}
if (needsCast) {
propertyVar = JExpr.cast(context.toJClass(Map.class).narrow(context.toJClass(QName.class), context.getGenericType(property.getComponentType())), propertyVar);
}
JForEach each = nullCond._then().forEach(context.toJClass(Map.Entry.class).narrow(context.toJClass(QName.class), context.getGenericType(property.getComponentType())), entryName, propertyVar.invoke("entrySet"));
writeSimpleTypeAttribute(builder, each.body(), each.var().invoke("getKey"), toClass(property.getComponentType()), each.var().invoke("getValue"));
}
}
}
}