Ejemplo n.º 1
0
  /**
   * Get the node whose id matches this node's idref attribute value.
   *
   * @return the MenuNode whose id matches this node's idref attribute value.
   */
  @Override
  public MenuNode getRefNode() {
    MenuNode refNode = null;

    // create one if it does not exist
    // should not happen, but can't hurt
    if (_idrefList == null) {
      String idref = getIdRef();
      _makeIdRefList(idref);
    }

    // Get idrefList
    String[] idrefList = _getIdRefList();

    // get group node's children
    List<MenuNode> children = getChildren();

    // Traverse the list. Do the following:
    //    o get Node from Model's hashMap of nodes and ids
    //    o check attributes (rendered, disabled, readOnly)
    //    o if they are ok, return the node
    for (int i = 0; i < Array.getLength(idrefList); i++) {
      Iterator<MenuNode> childIter = children.iterator();

      // All node "id" attribute values had the node's
      // system hashcode id appended to the id when
      // placed in the model's idNodeMap.
      //
      // Each id in the idreflist of a group node does
      // NOT have this node sys id appended it to it
      // and needs to or we won't find the group's
      // ref node.
      //
      // Since group nodes can only point to one of
      // its children, we iterate through them, get
      // their sys id and append it to idref until
      // we find a match (or not).
      while (childIter.hasNext()) {
        MenuNode childNode = childIter.next();
        String nodeSysId = childNode.getNodeSysId();

        // Need to append mode's sys id here to create a
        // unique id.
        String refNodeId = idrefList[i] + nodeSysId;

        refNode = (MenuNode) getRootModel().getNode(refNodeId);

        // if nothing found, move on to the next child
        if (refNode != null) break;
      }

      if (refNode == null) continue;

      // Check the attributes of the found node
      if (!refNode.getRendered()
          || refNode.getDisabled()
          || refNode.getReadOnly()
          || !refNode.getVisible()) {
        refNode = null;
        continue;
      }

      // Ok, we have a valid RefNode
      break;
    }

    // If no valid node is found,
    // log an error
    if (refNode == null) {
      _LOG.severe("GroupNode " + getLabel() + " refers to no valid node.\n");
      return null;
    }

    return refNode;
  }