public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer) throws UnableToCompleteException { // Generate instantiation (Vertical MenuBars require a ctor param). if (elem.hasAttribute("vertical")) { String vertical = elem.consumeBooleanAttribute("vertical"); writer.setFieldInitializerAsConstructor( fieldName, writer.getOracle().findType(MenuBar.class.getName()), vertical); } // Parse children. for (XMLElement child : elem.consumeChildElements()) { // MenuBar can only contain MenuItem elements. { String ns = child.getNamespaceUri(); String tagName = child.getLocalName(); if (!elem.getNamespaceUri().equals(ns) || !tagName.equals(TAG_MENUITEM)) { writer.die( "In %s, only <%s:%s> are valid children", elem, elem.getPrefix(), TAG_MENUITEM); } } String itemFieldName = writer.parseElementToField(child); writer.addStatement("%1$s.addItem(%2$s);", fieldName, itemFieldName); } }
private static String getLegalPlaceholderTag(XMLElement elem) { XMLElement parent = elem.getParent(); String tag = null; if (parent != null) { tag = LEGAL_CHILD_ELEMENTS.get(parent.getLocalName()); } if (tag == null) { tag = DEFAULT_CHILD_ELEMENT; } return tag; }