public List<ValidationResult> init(MappingNode rootNode) {
    List<ValidationResult> validationResults = new ArrayList<ValidationResult>();

    if (rootNode == null) {
      validationResults.add(createErrorResult("Invalid Root Node"));
      return validationResults;
    }

    for (int i = 0; i < rootNode.getValue().size(); i++) {
      NodeTuple rootTuple = rootNode.getValue().get(i);

      Node keyNode = rootTuple.getKeyNode();
      if (keyNode.getNodeId() != scalar) {
        continue; // invalid key
      }
      String key = ((ScalarNode) keyNode).getValue();

      if (key.equals("resourceTypes") || key.equals("traits")) {
        Node templateSequence = rootTuple.getValueNode();

        if (templateSequence.getNodeId() == scalar) {
          if (!templateSequence.getTag().equals(INCLUDE_TAG)) {
            validationResults.add(
                createErrorResult("Sequence or !include expected", templateSequence));
            break;
          }
          templateSequence = includeResolver.resolve(templateSequence, resourceLoader, nodeNandler);
          rootNode.getValue().remove(i);
          rootNode.getValue().add(i, new NodeTuple(keyNode, templateSequence));
        }
        if (templateSequence.getNodeId() != sequence) {
          validationResults.add(createErrorResult("Sequence expected", templateSequence));
          rootNode.getValue().remove(i);
          rootNode
              .getValue()
              .add(
                  i,
                  new NodeTuple(keyNode, new SequenceNode(Tag.SEQ, new ArrayList<Node>(), false)));
          break;
        }
        loopTemplateSequence((SequenceNode) templateSequence, key, validationResults);
      }
    }
    return validationResults;
  }
  private void loopTemplateSequence(
      SequenceNode templateSequence,
      String templateType,
      List<ValidationResult> validationResults) {
    List<Node> prunedTemplates = new ArrayList<Node>();
    for (int j = 0; j < templateSequence.getValue().size(); j++) {
      Node template = templateSequence.getValue().get(j);

      if (template.getNodeId() == scalar) {
        if (!template.getTag().equals(INCLUDE_TAG)) {
          validationResults.add(
              createErrorResult(
                  "Mapping or !include expected",
                  templateSequence.getStartMark(),
                  templateSequence.getEndMark()));
        }
        template = includeResolver.resolve(template, resourceLoader, nodeNandler);
      }
      for (NodeTuple tuple : ((MappingNode) template).getValue()) {
        if (tuple.getKeyNode().getNodeId() != scalar) {
          validationResults.add(createErrorResult(NON_SCALAR_KEY_MESSAGE, tuple.getKeyNode()));
          continue;
        }
        String templateKey = ((ScalarNode) tuple.getKeyNode()).getValue();
        Node templateValue = tuple.getValueNode();
        if (templateValue.getNodeId() != mapping) {
          validationResults.add(
              createErrorResult(
                  "Mapping expected", templateValue.getStartMark(), templateValue.getEndMark()));
          continue;
        }
        if (templateType.equals("resourceTypes")) {

          resourceTypesMap.put(templateKey, (MappingNode) templateValue);
        }
        if (templateType.equals("traits")) {
          traitsMap.put(templateKey, (MappingNode) templateValue);
        }
        prunedTemplates.add(getFakeTemplateNode(tuple.getKeyNode()));
      }
    }
    templateSequence.getValue().clear();
    templateSequence.getValue().addAll(prunedTemplates);
  }