protected BufferedXMLEventReader createSourceXmlEventReader(final Source source) {
    // If it is a StAXSource see if we can do better handling of it
    if (source instanceof StAXSource) {
      final StAXSource staxSource = (StAXSource) source;
      XMLEventReader xmlEventReader = staxSource.getXMLEventReader();
      if (xmlEventReader != null) {
        if (xmlEventReader instanceof BufferedXMLEventReader) {
          final BufferedXMLEventReader bufferedXMLEventReader =
              (BufferedXMLEventReader) xmlEventReader;
          bufferedXMLEventReader.reset();
          bufferedXMLEventReader.mark(-1);
          return bufferedXMLEventReader;
        }

        return new BufferedXMLEventReader(xmlEventReader, -1);
      }
    }

    final XMLInputFactory xmlInputFactory = this.xmlUtilities.getXmlInputFactory();
    final XMLEventReader xmlEventReader;
    try {
      xmlEventReader = xmlInputFactory.createXMLEventReader(source);
    } catch (XMLStreamException e) {
      throw new RuntimeException("Failed to create XML Event Reader for data Source", e);
    }
    return new BufferedXMLEventReader(xmlEventReader, -1);
  }
  @Override
  public final void importData(final Source source, PortalDataKey portalDataKey) {
    // Get a StAX reader for the source to determine info about the data to import
    final BufferedXMLEventReader bufferedXmlEventReader = createSourceXmlEventReader(source);

    // If no PortalDataKey was passed build it from the source
    if (portalDataKey == null) {
      final StartElement rootElement = StaxUtils.getRootElement(bufferedXmlEventReader);
      portalDataKey = new PortalDataKey(rootElement);
      bufferedXmlEventReader.reset();
    }

    final String systemId = source.getSystemId();

    // Post Process the PortalDataKey to see if more complex import operations are needed
    final IPortalDataType portalDataType = this.dataKeyTypes.get(portalDataKey);
    if (portalDataType == null) {
      throw new RuntimeException(
          "No IPortalDataType configured for "
              + portalDataKey
              + ", the resource will be ignored: "
              + getPartialSystemId(systemId));
    }
    final Set<PortalDataKey> postProcessedPortalDataKeys =
        portalDataType.postProcessPortalDataKey(systemId, portalDataKey, bufferedXmlEventReader);
    bufferedXmlEventReader.reset();

    // If only a single result from post processing import
    if (postProcessedPortalDataKeys.size() == 1) {
      this.importOrUpgradeData(
          systemId,
          DataAccessUtils.singleResult(postProcessedPortalDataKeys),
          bufferedXmlEventReader);
    }
    // If multiple results from post processing ordering is needed
    else {
      // Iterate over the data key order list to run the imports in the correct order
      for (final PortalDataKey orderedPortalDataKey : this.dataKeyImportOrder) {
        if (postProcessedPortalDataKeys.contains(orderedPortalDataKey)) {
          // Reset the to start of the XML document for each import/upgrade call
          bufferedXmlEventReader.reset();
          this.importOrUpgradeData(systemId, orderedPortalDataKey, bufferedXmlEventReader);
        }
      }
    }
  }