// Now go through the element and dispatch its attributes, remembering
// that constructor arguments get first dibs
for (int i = elem.getAttributeCount() - 1; i >= 0; i--) {
// Backward traversal b/c we're deleting attributes from the xml element
XMLAttribute attribute = elem.getAttribute(i);
// Ignore xmlns attributes
if (attribute.getName().startsWith("xmlns:")) {
continue;
}
String propertyName = attribute.getLocalName();
if (setterValues.keySet().contains(propertyName)
|| requiredValues.containsKey(propertyName)) {
// TODO(rjrjr) A fine example of why res: namespace hack must die
writer.die("Duplicate attribute name: %s", propertyName);
}
if (unfilledRequiredParams.keySet().contains(propertyName)) {
JParameter parameter = unfilledRequiredParams.get(propertyName);
AttributeParser parser =
writer.getAttributeParser(attribute, parameter);
if (parser == null) {
writer.die("In %s, unable to parse %s as constructor argument "
+ "of type %s", elem, attribute,
parameter.getType().getSimpleSourceName());
}
requiredValues.put(propertyName, parser.parse(attribute.consumeValue(),
writer));
unfilledRequiredParams.remove(propertyName);
} else {
JMethod setter = ownerFieldClass.getSetter(propertyName);
if (setter == null) {
writer.die("In %s, class %s has no appropriate set%s() method", elem,
elem.getLocalName(), initialCap(propertyName));
}
JParameter[] params = setter.getParameters();
AttributeParser parser = writer.getAttributeParser(attribute, params);
if (parser == null) {
writer.die("In %s, unable to parse %s.", elem, attribute);
}
setterValues.put(propertyName, parser.parse(attribute.consumeValue(),
writer));
}
}
if (!unfilledRequiredParams.isEmpty()) {