Ejemplo n.º 1
0
  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);
    }
  }
Ejemplo n.º 2
0
 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;
 }