/**
   * Build an XML element with the task profile information
   *
   * @param taskProfile the task profile
   * @param doc the XML document
   * @param name the name of the element
   * @return the XML element
   */
  private Element buildTaskProfileElement(MRTaskProfile taskProfile, Document doc, String name) {

    // Add the task attributes
    Element task = doc.createElement(name);
    task.setAttribute(ID, taskProfile.getTaskId());
    task.setAttribute(NUM_TASKS, Integer.toString(taskProfile.getNumTasks()));

    // Add the task enum maps
    task.appendChild(buildEnumMapElement(taskProfile.getCounters(), doc, COUNTERS, COUNTER));
    task.appendChild(buildEnumMapElement(taskProfile.getStatistics(), doc, STATS, STAT));
    task.appendChild(buildEnumMapElement(taskProfile.getCostFactors(), doc, FACTORS, FACTOR));
    task.appendChild(buildEnumMapElement(taskProfile.getTimings(), doc, TIMINGS, TIMING));

    // Add the task auxiliary counters map
    if (taskProfile.containsAuxCounters()) {
      Element counters = doc.createElement(AUX_COUNTERS);
      for (Entry<String, Long> e : taskProfile.getAuxCounters().entrySet()) {
        Element counter = doc.createElement(AUX_COUNTER);
        counters.appendChild(counter);
        counter.setAttribute(KEY, e.getKey());
        counter.setAttribute(VALUE, e.getValue().toString());
      }
      task.appendChild(counters);
    }

    return task;
  }
  /**
   * Load the execution profile
   *
   * @param profile the task profile to load
   * @return true if the loading was successful
   */
  public boolean loadExecutionProfile(MRTaskProfile profile) {

    if (!this.profile.getTaskId().equalsIgnoreCase(profile.getTaskId())) {
      return false;
    } else if (loaded && this.profile == profile) {
      return true;
    }

    // Load the profile
    this.profile = profile;
    loaded = true;

    try {
      if (parseProfileFile()) {
        return loadExecutionProfile();
      } else {
        return false;
      }
    } catch (ProfileFormatException e) {
      System.err.println(e.getMessage());
      e.printStackTrace();
      return false;
    }
  }