/** Fills in the list of declared prefixes. */
 private void fillDeclaredPrefixes(XMLStreamReader reader) {
   fDeclaredPrefixes.clear();
   final int len = reader.getNamespaceCount();
   for (int i = 0; i < len; ++i) {
     String prefix = reader.getNamespacePrefix(i);
     fDeclaredPrefixes.add(prefix != null ? prefix : "");
   }
 }
 /** Fills in the XMLAttributes object. */
 private void fillXMLAttributes(XMLStreamReader reader) {
   fAttributes.removeAllAttributes();
   final int len = reader.getAttributeCount();
   for (int i = 0; i < len; ++i) {
     fillQName(
         fAttributeQName,
         reader.getAttributeNamespace(i),
         reader.getAttributeLocalName(i),
         reader.getAttributePrefix(i));
     String type = reader.getAttributeType(i);
     fAttributes.addAttributeNS(
         fAttributeQName,
         (type != null) ? type : XMLSymbols.fCDATASymbol,
         reader.getAttributeValue(i));
     fAttributes.setSpecified(i, reader.isAttributeSpecified(i));
   }
 }
 private Location getLocation() {
   return reader != null ? reader.getLocation() : null;
 }
 final void validate(XMLStreamReader reader, StAXResult result)
     throws SAXException, XMLStreamException {
   if (reader.hasNext()) {
     int eventType = reader.getEventType();
     if (eventType != XMLStreamConstants.START_DOCUMENT
         && eventType != XMLStreamConstants.START_ELEMENT) {
       throw new SAXException(
           JAXPValidationMessageFormatter.formatMessage(
               fComponentManager.getLocale(), "StAXIllegalInitialState", null));
     }
     fXMLStreamReaderLocation.setXMLStreamReader(reader);
     setup(
         fXMLStreamReaderLocation,
         result,
         Boolean.TRUE.equals(reader.getProperty(STRING_INTERNING)));
     fSchemaValidator.startDocument(fStAXLocationWrapper, null, fNamespaceContext, null);
     do {
       switch (eventType) {
         case XMLStreamConstants.START_ELEMENT:
           ++fDepth;
           fillQName(
               fElementQName,
               reader.getNamespaceURI(),
               reader.getLocalName(),
               reader.getPrefix());
           fillXMLAttributes(reader);
           fillDeclaredPrefixes(reader);
           fNamespaceContext.setNamespaceContext(reader.getNamespaceContext());
           fSchemaValidator.startElement(fElementQName, fAttributes, null);
           break;
         case XMLStreamConstants.END_ELEMENT:
           fillQName(
               fElementQName,
               reader.getNamespaceURI(),
               reader.getLocalName(),
               reader.getPrefix());
           fillDeclaredPrefixes(reader);
           fNamespaceContext.setNamespaceContext(reader.getNamespaceContext());
           fSchemaValidator.endElement(fElementQName, null);
           --fDepth;
           break;
         case XMLStreamConstants.CHARACTERS:
         case XMLStreamConstants.SPACE:
           fTempString.setValues(
               reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength());
           fSchemaValidator.characters(fTempString, null);
           break;
         case XMLStreamConstants.CDATA:
           fSchemaValidator.startCDATA(null);
           fTempString.setValues(
               reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength());
           fSchemaValidator.characters(fTempString, null);
           fSchemaValidator.endCDATA(null);
           break;
         case XMLStreamConstants.START_DOCUMENT:
           ++fDepth;
           if (fStAXValidatorHandler != null) {
             fStAXValidatorHandler.startDocument(reader);
           }
           break;
         case XMLStreamConstants.PROCESSING_INSTRUCTION:
           if (fStAXValidatorHandler != null) {
             fStAXValidatorHandler.processingInstruction(reader);
           }
           break;
         case XMLStreamConstants.COMMENT:
           if (fStAXValidatorHandler != null) {
             fStAXValidatorHandler.comment(reader);
           }
           break;
         case XMLStreamConstants.ENTITY_REFERENCE:
           if (fStAXValidatorHandler != null) {
             fStAXValidatorHandler.entityReference(reader);
           }
           break;
         case XMLStreamConstants.DTD:
           processEntityDeclarations((List) reader.getProperty("javax.xml.stream.entities"));
           break;
       }
       eventType = reader.next();
     } while (reader.hasNext() && fDepth > 0);
     fSchemaValidator.endDocument(null);
     if (eventType == XMLStreamConstants.END_DOCUMENT && fStAXValidatorHandler != null) {
       fStAXValidatorHandler.endDocument(reader);
     }
   }
 }