.method("protected String %s(final %s %s)", element.conversionMethodName, element.javaType.name, element.shortName)
.add("return %s(%s);", element.javaType.methodName(), element.shortName);
}
private void createReaderForComplexElement(final Element element, final ClassBody clas) {
final Block reader = clas.method("public void %s(final XMLStreamReader xmlr) throws XMLStreamException", element.readTagMethodName);
reader.add("%s();", element.openTagMethodName);
if (element.attributes.isEmpty()) {
reader.open("if(xmlr.getAttributeCount()>0)");
reader.add(fail("Unexpected attribute: %s", "xmlr.getAttributeName(0)"));
reader.close();
} else {
reader
.open("for (int i = 0; i < xmlr.getAttributeCount(); i++)")
.add("final QName name = xmlr.getAttributeName(i);");
for (Element attribute : element.attributes) {
reader.add("if (name.equals(%s)) {", attribute.qNameField).in();
createSimpleTypeHandlerCall(attribute, "xmlr.getAttributeValue(i)", reader);
reader.close("else {");
}
reader.in(fail("Unexpected attribute: %s", "xmlr.getAttributeName(i)"));
reader.close().close();
}
reader
.open("do")
.add("final int eventType = xmlr.next();")
.add("switch (eventType) {")
.in("case START_ELEMENT:")
.in();
if (element.children.isEmpty()) {
reader.add(fail("Unexpected child: %s", "xmlr.getName()"));
} else {
for (Element child : element.children) {
if (child.complex) {
reader
.open("if (xmlr.getName().equals(%s))", child.qNameField)
.add("%s(xmlr);", child.readTagMethodName)
.close("else");
} else {
reader
.open("if (xmlr.getName().equals(%s))", child.qNameField)
.add("%s(xmlr);", child.readTagMethodName)
.close("else");
}
}
reader.in(fail("Unexpected child: %s", "xmlr.getName()"));
reader.out("break;");
}
reader
.out("case END_ELEMENT:")
.in("%s();", element.closeTagMethodName)
.add("return;")
.out("case END_DOCUMENT:")
.in(fail("Unexpected end of document"))