/**
  * return the resulting merged menubar
  *
  * @param master the master menubar
  * @param servant the servant menubar
  * @return a Menubar or null if there was nothing to merge
  */
 protected Menubar merge(Menubar master, Menubar servant) {
   if (logger.isDebugEnabled()) {
     logger.debug("entering merge(Menubar, Menubar)");
   }
   Menubar result = null;
   if (master == null) {
     if (servant != null) {
       result = servant;
     }
   } else {
     if (servant != null && servant.getMenus() != null && servant.getMenus().getMenu() != null) {
       /* merge two non null items fill the structure of master with servant elements */
       for (int i = 0; i < servant.getMenus().getMenu().size(); i++) {
           /* if it already contains a menu named like current servant menu, then merge them */
         MenuType currentMenu = (MenuType) servant.getMenus().getMenu().get(i);
         if (currentMenu != null) {
           Object item =
               this.getItem(
                   master, currentMenu.getLabel(), currentMenu.getI18Nref(), MenuType.class);
           if (item != null) {
             this.merge((MenuType) item, currentMenu);
           } else {
               /* add the current servant menu to the list of menu of the master bar */
             master.getMenus().getMenu().add(currentMenu);
           }
         }
       }
     }
     result = master;
   }
   if (logger.isDebugEnabled()) {
     logger.debug("exiting merge(Menubar, Menubar)");
   }
   return result;
 }
  /**
   * merge two menu into master one
   *
   * @param masterMenu the master menu non null
   * @param servantMenu the servant menu non null
   */
  protected void merge(MenuType masterMenu, MenuType servantMenu) {
    if (logger.isDebugEnabled()) {
      logger.debug("entering merge(MenuType, MenuType)");
    }

    boolean seemsSame = this.equalsAbstractElts(masterMenu, servantMenu);

    if (seemsSame) {
      /* loop on all first elements of the servantMenu */

      List subItems = servantMenu.getMenuOrItemOrCheck();
      if (subItems != null) {
        Iterator it = subItems.iterator();
        while (it.hasNext()) {
          Object o = it.next();

          if (o != null) {
            if (o instanceof MenuType) {
                /* search for a menu in the master sub items */
              MenuType servantSubMenu = (MenuType) o;
              MenuType masterSubMenu =
                  (MenuType)
                      this.getItem(
                          masterMenu,
                          servantMenu.getLabel(),
                          servantMenu.getI18Nref(),
                          MenuType.class);
              if (masterSubMenu != null) {
                this.merge(masterSubMenu, servantSubMenu);
              } else {
                masterMenu.getMenuOrItemOrCheck().add(servantSubMenu);
                this.assignShortcuts(servantSubMenu, true);
              }
            } else if (o instanceof SeparatorElement) {
              masterMenu.getMenuOrItemOrCheck().add((OrderedElement) o);
            } else if (o instanceof AbstractElement) {
              AbstractElement subItem = (AbstractElement) o;
              /* search for a sub item in the servant list that is named like subItem
               *
               * if we find a checkItem named 't' and if tmaster already contains a comboItem named 't'
               *  then the checkItem won't be added to the resulting structure
               */
              AbstractElement masterSubItem =
                  (AbstractElement)
                      this.getItem(
                          masterMenu,
                          subItem.getLabel(),
                          subItem.getI18Nref(),
                          AbstractElement.class);
              if (masterSubItem == null) {
                masterMenu.getMenuOrItemOrCheck().add((OrderedElement) o);
                this.assignShortcuts(o, false);
              }
            }
          }
        }
      }
    }
    if (logger.isDebugEnabled()) {
      logger.debug("exiting merge(MenuType, MenuType)");
    }
  }