// Use XML schema object model to determine if field is mapped
// from an element (attributes default values are handled
// natively) and get its default value.
XmlString xmlDefaultValue = null;
XSType xsType = null;
boolean isElement = false;
boolean isRequiredAttr = true;
if (f.getPropertyInfo().getSchemaComponent() instanceof XSParticle) {
XSParticle particle = (XSParticle)f.getPropertyInfo().getSchemaComponent();
XSTerm term = particle.getTerm();
XSElementDecl element = null;
if (term.isElementDecl()) {
element = particle.getTerm().asElementDecl();
xmlDefaultValue = element.getDefaultValue();
xsType = element.getType();
isElement = true;
}
} else if (f.getPropertyInfo().getSchemaComponent() instanceof XSAttributeUse) {
XSAttributeUse attributeUse = (XSAttributeUse)f.getPropertyInfo().getSchemaComponent();
XSAttributeDecl decl = attributeUse.getDecl();
xmlDefaultValue = decl.getDefaultValue();
xsType = decl.getType();
isRequiredAttr = attributeUse.isRequired();
}
if (xsType != null && xsType.isComplexType() && containsDefaultValue(outline, f)) {
String varName = f.getPropertyInfo().getName(false);
JFieldVar var = co.implClass.fields().get(varName);
if (var != null) {
co.implClass.removeField(var);
JFieldVar newVar = co.implClass.field(var.mods().getValue(),
var.type(),
var.name(),
JExpr._new(f.getRawType()));
newVar.javadoc().append(var.javadoc());
}
}
JExpression dvExpr = null;
if (null != xmlDefaultValue && null != xmlDefaultValue.value) {
dvExpr = getDefaultValueExpression(f, co, outline, xsType, isElement,
xmlDefaultValue, false);
}
if (null == dvExpr
&& !isElement && !isRequiredAttr
&& xsType != null && xsType.getOwnerSchema() != null
&& !"http://www.w3.org/2001/XMLSchema"
.equals(xsType.getOwnerSchema().getTargetNamespace())) {
//non-primitive attribute, may still be able to convert it, but need to do
//a bunch more checks and changes to setters and isSet and such
dvExpr =
getDefaultValueExpression(f, co, outline, xsType, isElement, xmlDefaultValue, true);