public boolean run(Outline outline,
Options opt,
ErrorHandler errorHandler) {
LOG.fine("Running default value plugin.");
for (ClassOutline co : outline.getClasses()) {
for (FieldOutline f : co.getDeclaredFields()) {
// 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;
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();
}
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());
}
}
if (null == xmlDefaultValue || null == xmlDefaultValue.value) {
continue;
}
JExpression dvExpr =
getDefaultValueExpression(f, co, outline, xsType, isElement, xmlDefaultValue);
if (null == dvExpr) {
continue;
}
updateGetter(co, f, co.implClass, dvExpr);
}
}
return true;
}
|