/**
   * Adds the platform to the folder on the given level. This method is recursive. If agent name is
   * not fitting the level, it will be added to the given composite. If it fitting for the level,
   * proper search will be done for sub-composite to insert the platform.
   *
   * @param folder Top composite.
   * @param level Wanted level.
   * @param platformIdent {@link PlatformIdent}.
   * @param agentStatusData {@link AgentStatusData}.
   * @param cmrRepositoryDefinition Repository agent is belonging to.
   */
  private static void addToFolder(
      Composite folder,
      int level,
      PlatformIdent platformIdent,
      AgentStatusData agentStatusData,
      CmrRepositoryDefinition cmrRepositoryDefinition) {
    if (!accessibleForLevel(platformIdent.getAgentName(), level)) {
      // if name is not matching the level just add th leaf
      AgentLeaf agentLeaf =
          new AgentLeaf(platformIdent, agentStatusData, cmrRepositoryDefinition, level != 0);
      folder.addChild(agentLeaf);
    } else {
      // search for proper folder
      boolean folderExisting = false;
      String agentLevelName = getFolderNameFromAgent(platformIdent.getAgentName(), level);
      for (Component child : folder.getChildren()) {
        if (child instanceof Composite && ObjectUtils.equals(child.getName(), agentLevelName)) {
          addToFolder(
              (Composite) child,
              level + 1,
              platformIdent,
              agentStatusData,
              cmrRepositoryDefinition);
          folderExisting = true;
        }
      }

      // if not found create new one
      if (!folderExisting) {
        Composite newFolder = createFolder(agentLevelName);
        addToFolder(newFolder, level + 1, platformIdent, agentStatusData, cmrRepositoryDefinition);
        folder.addChild(newFolder);
      }
    }
  }
Exemple #2
0
  public static void main(String[] args) {

    Composite root = new Composite("Root");

    Component a = new Leaf("A");

    Composite b = new Composite("B");
    Component b1 = new Leaf("B-1");
    Component b2 = new Leaf("B-2");
    Component b3 = new Leaf("B-3");
    b.addChild(b1);
    b.addChild(b2);
    b.addChild(b3);

    Component c = new Leaf("C");

    root.addChild(a);
    root.addChild(b);
    root.addChild(c);

    root.operation();
  }