code: public static XMLEventReader getXMLEventReader(Source source) throws XMLStreamException
      {
          XMLEventReader xmlEventReader;
  
          if (source instanceof StAXSource) {
              // StAXSource is not supported by standard XMLInputFactory
              StAXSource staxSource = (StAXSource) source;
              if (staxSource.getXMLEventReader() != null) {
                  xmlEventReader = staxSource.getXMLEventReader();
              } else {
                  xmlEventReader = new XMLStreamEventReader(staxSource.getXMLStreamReader());
              }
          } else {
              xmlEventReader = XML_INPUT_FACTORY.createXMLEventReader(source);
          }
  
          return xmlEventReader;
      }
docs: Extract or create an instance of {@link XMLEventReader} from the provided {@link Source}.
  
  @param source the source
  @return the {@link XMLEventReader}
  @throws XMLStreamException when failing to extract xml event reader