Java Code Examples for javax.xml.stream.XMLStreamReader#getAttributeNamespace()

The following examples show how to use javax.xml.stream.XMLStreamReader#getAttributeNamespace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OutboundStreamHeader.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * We don't really expect this to be used, but just to satisfy
 * the {@link Header} contract.
 *
 * So this is rather slow.
 */
private void parseAttributes() {
    try {
        XMLStreamReader reader = readHeader();

        attributes = new FinalArrayList<Attribute>();

        for (int i = 0; i < reader.getAttributeCount(); i++) {
            final String localName = reader.getAttributeLocalName(i);
            final String namespaceURI = reader.getAttributeNamespace(i);
            final String value = reader.getAttributeValue(i);

            attributes.add(new Attribute(namespaceURI,localName,value));
        }
    } catch (XMLStreamException e) {
        throw new WebServiceException("Unable to read the attributes for {"+nsUri+"}"+localName+" header",e);
    }
}
 
Example 2
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private List<AnnotationAttribute> readAnnotationAttribute(final XMLStreamReader reader) {
  List<AnnotationAttribute> annotationAttributes = new ArrayList<AnnotationAttribute>();
  for (int i = 0; i < reader.getAttributeCount(); i++) {
    String attributeNamespace = reader.getAttributeNamespace(i);
    if (attributeNamespace != null && !isDefaultNamespace(attributeNamespace)
        && !mandatoryNamespaces.containsValue(attributeNamespace)
        && !edmNamespaces.contains(attributeNamespace)) {
      annotationAttributes.add(new AnnotationAttribute().setName(reader.getAttributeLocalName(i)).
          setPrefix(reader.getAttributePrefix(i)).setNamespace(attributeNamespace).setText(
              reader.getAttributeValue(i)));
    }
  }
  if (annotationAttributes.isEmpty()) {
    return null;
  }
  return annotationAttributes;
}
 
Example 3
Source File: OutboundStreamHeader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * We don't really expect this to be used, but just to satisfy
 * the {@link Header} contract.
 *
 * So this is rather slow.
 */
private void parseAttributes() {
    try {
        XMLStreamReader reader = readHeader();

        attributes = new FinalArrayList<Attribute>();

        for (int i = 0; i < reader.getAttributeCount(); i++) {
            final String localName = reader.getAttributeLocalName(i);
            final String namespaceURI = reader.getAttributeNamespace(i);
            final String value = reader.getAttributeValue(i);

            attributes.add(new Attribute(namespaceURI,localName,value));
        }
    } catch (XMLStreamException e) {
        throw new WebServiceException("Unable to read the attributes for {"+nsUri+"}"+localName+" header",e);
    }
}
 
Example 4
Source File: OutboundStreamHeader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * We don't really expect this to be used, but just to satisfy
 * the {@link Header} contract.
 *
 * So this is rather slow.
 */
private void parseAttributes() {
    try {
        XMLStreamReader reader = readHeader();

        attributes = new FinalArrayList<Attribute>();

        for (int i = 0; i < reader.getAttributeCount(); i++) {
            final String localName = reader.getAttributeLocalName(i);
            final String namespaceURI = reader.getAttributeNamespace(i);
            final String value = reader.getAttributeValue(i);

            attributes.add(new Attribute(namespaceURI,localName,value));
        }
    } catch (XMLStreamException e) {
        throw new WebServiceException("Unable to read the attributes for {"+nsUri+"}"+localName+" header",e);
    }
}
 
Example 5
Source File: XMLSupport.java    From FHIR with Apache License 2.0 6 votes vote down vote up
private static void writeAttributes(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String prefix = reader.getAttributePrefix(i);
        String namespaceURI = reader.getAttributeNamespace(i);
        String localName = reader.getAttributeLocalName(i);
        String value = reader.getAttributeValue(i);
        if (namespaceURI != null) {
            if (prefix != null) {
                writer.writeAttribute(prefix, namespaceURI, localName, value);
            } else {
                writer.writeAttribute(namespaceURI, localName, value);
            }
        } else {
            writer.writeAttribute(localName, value);
        }
    }
}
 
Example 6
Source File: OutboundStreamHeader.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * We don't really expect this to be used, but just to satisfy
 * the {@link Header} contract.
 *
 * So this is rather slow.
 */
private void parseAttributes() {
    try {
        XMLStreamReader reader = readHeader();

        attributes = new FinalArrayList<Attribute>();

        for (int i = 0; i < reader.getAttributeCount(); i++) {
            final String localName = reader.getAttributeLocalName(i);
            final String namespaceURI = reader.getAttributeNamespace(i);
            final String value = reader.getAttributeValue(i);

            attributes.add(new Attribute(namespaceURI,localName,value));
        }
    } catch (XMLStreamException e) {
        throw new WebServiceException("Unable to read the attributes for {"+nsUri+"}"+localName+" header",e);
    }
}
 
Example 7
Source File: OutboundReferenceParameterHeader.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * We don't really expect this to be used, but just to satisfy
 * the {@link Header} contract.
 *
 * So this is rather slow.
 */
private void parseAttributes() {
    try {
        XMLStreamReader reader = readHeader();
        reader.nextTag();   // move to the first element, which is the header element

        attributes = new FinalArrayList<Attribute>();
        boolean refParamAttrWritten = false;
        for (int i = 0; i < reader.getAttributeCount(); i++) {
            final String attrLocalName = reader.getAttributeLocalName(i);
            final String namespaceURI = reader.getAttributeNamespace(i);
            final String value = reader.getAttributeValue(i);
            if (namespaceURI.equals(AddressingVersion.W3C.nsUri)&& attrLocalName.equals("IS_REFERENCE_PARAMETER")) {
                refParamAttrWritten = true;
            }
            attributes.add(new Attribute(namespaceURI,attrLocalName,value));
        }
        // we are adding one more attribute "wsa:IsReferenceParameter", if its not alrady there
        if (!refParamAttrWritten) {
            attributes.add(new Attribute(AddressingVersion.W3C.nsUri,IS_REFERENCE_PARAMETER,TRUE_VALUE));
        }
    } catch (XMLStreamException e) {
        throw new WebServiceException("Unable to read the attributes for {"+nsUri+"}"+localName+" header",e);
    }
}
 
Example 8
Source File: OutboundReferenceParameterHeader.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * We don't really expect this to be used, but just to satisfy
 * the {@link Header} contract.
 *
 * So this is rather slow.
 */
private void parseAttributes() {
    try {
        XMLStreamReader reader = readHeader();
        reader.nextTag();   // move to the first element, which is the header element

        attributes = new FinalArrayList<Attribute>();
        boolean refParamAttrWritten = false;
        for (int i = 0; i < reader.getAttributeCount(); i++) {
            final String attrLocalName = reader.getAttributeLocalName(i);
            final String namespaceURI = reader.getAttributeNamespace(i);
            final String value = reader.getAttributeValue(i);
            if (namespaceURI.equals(AddressingVersion.W3C.nsUri)&& attrLocalName.equals("IS_REFERENCE_PARAMETER")) {
                refParamAttrWritten = true;
            }
            attributes.add(new Attribute(namespaceURI,attrLocalName,value));
        }
        // we are adding one more attribute "wsa:IsReferenceParameter", if its not alrady there
        if (!refParamAttrWritten) {
            attributes.add(new Attribute(AddressingVersion.W3C.nsUri,IS_REFERENCE_PARAMETER,TRUE_VALUE));
        }
    } catch (XMLStreamException e) {
        throw new WebServiceException("Unable to read the attributes for {"+nsUri+"}"+localName+" header",e);
    }
}
 
Example 9
Source File: OutboundReferenceParameterHeader.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * We don't really expect this to be used, but just to satisfy
 * the {@link Header} contract.
 *
 * So this is rather slow.
 */
private void parseAttributes() {
    try {
        XMLStreamReader reader = readHeader();
        reader.nextTag();   // move to the first element, which is the header element

        attributes = new FinalArrayList<Attribute>();
        boolean refParamAttrWritten = false;
        for (int i = 0; i < reader.getAttributeCount(); i++) {
            final String attrLocalName = reader.getAttributeLocalName(i);
            final String namespaceURI = reader.getAttributeNamespace(i);
            final String value = reader.getAttributeValue(i);
            if (namespaceURI.equals(AddressingVersion.W3C.nsUri)&& attrLocalName.equals("IS_REFERENCE_PARAMETER")) {
                refParamAttrWritten = true;
            }
            attributes.add(new Attribute(namespaceURI,attrLocalName,value));
        }
        // we are adding one more attribute "wsa:IsReferenceParameter", if its not alrady there
        if (!refParamAttrWritten) {
            attributes.add(new Attribute(AddressingVersion.W3C.nsUri,IS_REFERENCE_PARAMETER,TRUE_VALUE));
        }
    } catch (XMLStreamException e) {
        throw new WebServiceException("Unable to read the attributes for {"+nsUri+"}"+localName+" header",e);
    }
}
 
Example 10
Source File: StreamHeader12.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected final FinalArrayList<Attribute> processHeaderAttributes(XMLStreamReader reader) {
    FinalArrayList<Attribute> atts = null;

    _role = SOAPConstants.URI_SOAP_1_2_ROLE_ULTIMATE_RECEIVER;

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        final String localName = reader.getAttributeLocalName(i);
        final String namespaceURI = reader.getAttributeNamespace(i);
        final String value = reader.getAttributeValue(i);

        if (SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(namespaceURI)) {
            if (SOAP_1_2_MUST_UNDERSTAND.equals(localName)) {
                _isMustUnderstand = Util.parseBool(value);
            } else if (SOAP_1_2_ROLE.equals(localName)) {
                if (value != null && value.length() > 0) {
                    _role = value;
                }
            } else if (SOAP_1_2_RELAY.equals(localName)) {
                _isRelay = Util.parseBool(value);
            }
        }

        if(atts==null) {
            atts = new FinalArrayList<Attribute>();
        }
        atts.add(new Attribute(namespaceURI,localName,value));
    }

    return atts;
}
 
Example 11
Source File: StreamHeader12.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected final FinalArrayList<Attribute> processHeaderAttributes(XMLStreamReader reader) {
    FinalArrayList<Attribute> atts = null;

    _role = SOAPConstants.URI_SOAP_1_2_ROLE_ULTIMATE_RECEIVER;

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        final String localName = reader.getAttributeLocalName(i);
        final String namespaceURI = reader.getAttributeNamespace(i);
        final String value = reader.getAttributeValue(i);

        if (SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(namespaceURI)) {
            if (SOAP_1_2_MUST_UNDERSTAND.equals(localName)) {
                _isMustUnderstand = Util.parseBool(value);
            } else if (SOAP_1_2_ROLE.equals(localName)) {
                if (value != null && value.length() > 0) {
                    _role = value;
                }
            } else if (SOAP_1_2_RELAY.equals(localName)) {
                _isRelay = Util.parseBool(value);
            }
        }

        if(atts==null) {
            atts = new FinalArrayList<Attribute>();
        }
        atts.add(new Attribute(namespaceURI,localName,value));
    }

    return atts;
}
 
Example 12
Source File: StreamHeader12.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
protected final FinalArrayList<Attribute> processHeaderAttributes(XMLStreamReader reader) {
    FinalArrayList<Attribute> atts = null;

    _role = SOAPConstants.URI_SOAP_1_2_ROLE_ULTIMATE_RECEIVER;

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        final String localName = reader.getAttributeLocalName(i);
        final String namespaceURI = reader.getAttributeNamespace(i);
        final String value = reader.getAttributeValue(i);

        if (SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(namespaceURI)) {
            if (SOAP_1_2_MUST_UNDERSTAND.equals(localName)) {
                _isMustUnderstand = Util.parseBool(value);
            } else if (SOAP_1_2_ROLE.equals(localName)) {
                if (value != null && value.length() > 0) {
                    _role = value;
                }
            } else if (SOAP_1_2_RELAY.equals(localName)) {
                _isRelay = Util.parseBool(value);
            }
        }

        if(atts==null) {
            atts = new FinalArrayList<Attribute>();
        }
        atts.add(new Attribute(namespaceURI,localName,value));
    }

    return atts;
}
 
Example 13
Source File: StreamHeader12.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected final FinalArrayList<Attribute> processHeaderAttributes(XMLStreamReader reader) {
    FinalArrayList<Attribute> atts = null;

    _role = SOAPConstants.URI_SOAP_1_2_ROLE_ULTIMATE_RECEIVER;

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        final String localName = reader.getAttributeLocalName(i);
        final String namespaceURI = reader.getAttributeNamespace(i);
        final String value = reader.getAttributeValue(i);

        if (SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(namespaceURI)) {
            if (SOAP_1_2_MUST_UNDERSTAND.equals(localName)) {
                _isMustUnderstand = Util.parseBool(value);
            } else if (SOAP_1_2_ROLE.equals(localName)) {
                if (value != null && value.length() > 0) {
                    _role = value;
                }
            } else if (SOAP_1_2_RELAY.equals(localName)) {
                _isRelay = Util.parseBool(value);
            }
        }

        if(atts==null) {
            atts = new FinalArrayList<Attribute>();
        }
        atts.add(new Attribute(namespaceURI,localName,value));
    }

    return atts;
}
 
Example 14
Source File: StreamHeader11.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
protected final FinalArrayList<Attribute> processHeaderAttributes(XMLStreamReader reader) {
    FinalArrayList<Attribute> atts = null;

    _role = SOAPConstants.URI_SOAP_ACTOR_NEXT;

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        final String localName = reader.getAttributeLocalName(i);
        final String namespaceURI = reader.getAttributeNamespace(i);
        final String value = reader.getAttributeValue(i);

        if (SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(namespaceURI)) {
            if (SOAP_1_1_MUST_UNDERSTAND.equals(localName)) {
                _isMustUnderstand = Util.parseBool(value);
            } else if (SOAP_1_1_ROLE.equals(localName)) {
                if (value != null && value.length() > 0) {
                    _role = value;
                }
            }
        }

        if(atts==null) {
            atts = new FinalArrayList<Attribute>();
        }
        atts.add(new Attribute(namespaceURI,localName,value));
    }

    return atts;
}
 
Example 15
Source File: StreamHeader12.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected final FinalArrayList<Attribute> processHeaderAttributes(XMLStreamReader reader) {
    FinalArrayList<Attribute> atts = null;

    _role = SOAPConstants.URI_SOAP_1_2_ROLE_ULTIMATE_RECEIVER;

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        final String localName = reader.getAttributeLocalName(i);
        final String namespaceURI = reader.getAttributeNamespace(i);
        final String value = reader.getAttributeValue(i);

        if (SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(namespaceURI)) {
            if (SOAP_1_2_MUST_UNDERSTAND.equals(localName)) {
                _isMustUnderstand = Util.parseBool(value);
            } else if (SOAP_1_2_ROLE.equals(localName)) {
                if (value != null && value.length() > 0) {
                    _role = value;
                }
            } else if (SOAP_1_2_RELAY.equals(localName)) {
                _isRelay = Util.parseBool(value);
            }
        }

        if(atts==null) {
            atts = new FinalArrayList<Attribute>();
        }
        atts.add(new Attribute(namespaceURI,localName,value));
    }

    return atts;
}
 
Example 16
Source File: StreamHeader11.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected final FinalArrayList<Attribute> processHeaderAttributes(XMLStreamReader reader) {
    FinalArrayList<Attribute> atts = null;

    _role = SOAPConstants.URI_SOAP_ACTOR_NEXT;

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        final String localName = reader.getAttributeLocalName(i);
        final String namespaceURI = reader.getAttributeNamespace(i);
        final String value = reader.getAttributeValue(i);

        if (SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(namespaceURI)) {
            if (SOAP_1_1_MUST_UNDERSTAND.equals(localName)) {
                _isMustUnderstand = Util.parseBool(value);
            } else if (SOAP_1_1_ROLE.equals(localName)) {
                if (value != null && value.length() > 0) {
                    _role = value;
                }
            }
        }

        if(atts==null) {
            atts = new FinalArrayList<Attribute>();
        }
        atts.add(new Attribute(namespaceURI,localName,value));
    }

    return atts;
}
 
Example 17
Source File: StreamHeader12.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected final FinalArrayList<Attribute> processHeaderAttributes(XMLStreamReader reader) {
    FinalArrayList<Attribute> atts = null;

    _role = SOAPConstants.URI_SOAP_1_2_ROLE_ULTIMATE_RECEIVER;

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        final String localName = reader.getAttributeLocalName(i);
        final String namespaceURI = reader.getAttributeNamespace(i);
        final String value = reader.getAttributeValue(i);

        if (SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(namespaceURI)) {
            if (SOAP_1_2_MUST_UNDERSTAND.equals(localName)) {
                _isMustUnderstand = Util.parseBool(value);
            } else if (SOAP_1_2_ROLE.equals(localName)) {
                if (value != null && value.length() > 0) {
                    _role = value;
                }
            } else if (SOAP_1_2_RELAY.equals(localName)) {
                _isRelay = Util.parseBool(value);
            }
        }

        if(atts==null) {
            atts = new FinalArrayList<Attribute>();
        }
        atts.add(new Attribute(namespaceURI,localName,value));
    }

    return atts;
}
 
Example 18
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private AnnotationElement readAnnotationElement(final XMLStreamReader reader) throws XMLStreamException {
  AnnotationElement aElement = new AnnotationElement();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  List<AnnotationAttribute> annotationAttributes = new ArrayList<AnnotationAttribute>();
  aElement.setName(reader.getLocalName());
  String elementNamespace = reader.getNamespaceURI();
  if (!edmNamespaces.contains(elementNamespace)) {
    aElement.setPrefix(reader.getPrefix());
    aElement.setNamespace(elementNamespace);
  }
  for (int i = 0; i < reader.getAttributeCount(); i++) {
    AnnotationAttribute annotationAttribute = new AnnotationAttribute();
    annotationAttribute.setText(reader.getAttributeValue(i));
    annotationAttribute.setName(reader.getAttributeLocalName(i));
    annotationAttribute.setPrefix(reader.getAttributePrefix(i));
    String namespace = reader.getAttributeNamespace(i);
    if (namespace != null && !isDefaultNamespace(namespace)) {
      annotationAttribute.setNamespace(namespace);
    }
    annotationAttributes.add(annotationAttribute);
  }
  if (!annotationAttributes.isEmpty()) {
    aElement.setAttributes(annotationAttributes);
  }

  boolean justRead = false;
  if (reader.hasNext()) {
    reader.next();
    justRead = true;
  }

  while (justRead && !(reader.isEndElement() && aElement.getName() != null
      && aElement.getName().equals(reader.getLocalName()))) {
    justRead = false;
    if (reader.isStartElement()) {
      annotationElements.add(readAnnotationElement(reader));
      if (reader.hasNext()) {
        reader.next();
        justRead = true;
      }
    } else if (reader.isCharacters()) {
      String elementText = "";
      do {
        justRead = false;
        elementText = elementText + reader.getText();
        if (reader.hasNext()) {
          reader.next();
          justRead = true;
        }
      } while (justRead && reader.isCharacters());
      aElement.setText(elementText);
    }
  }
  if (!annotationElements.isEmpty()) {
    aElement.setChildElements(annotationElements);
  }
  return aElement;
}
 
Example 19
Source File: XmlMetadataDeserializer.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private EdmAnnotationElement readAnnotationElement(final XMLStreamReader reader) throws XMLStreamException {
  EdmAnnotationElementImpl elementImpl = new EdmAnnotationElementImpl();
  List<EdmAnnotationElement> annotationElements = new ArrayList<EdmAnnotationElement>();
  List<EdmAnnotationAttribute> annotationAttributes = new ArrayList<EdmAnnotationAttribute>();
  elementImpl.setName(reader.getLocalName());
  String elementNamespace = reader.getNamespaceURI();
  if (!edmNamespaces.contains(elementNamespace)) {
    elementImpl.setPrefix(reader.getPrefix());
    elementImpl.setNamespace(elementNamespace);
  }
  for (int i = 0; i < reader.getAttributeCount(); i++) {
    EdmAnnotationAttributeImpl annotationAttribute = new EdmAnnotationAttributeImpl();
    annotationAttribute.setText(reader.getAttributeValue(i));
    annotationAttribute.setName(reader.getAttributeLocalName(i));
    annotationAttribute.setPrefix(reader.getAttributePrefix(i));
    String namespace = reader.getAttributeNamespace(i);
    if (namespace != null && !isDefaultNamespace(namespace)) {
      annotationAttribute.setNamespace(namespace);
    }
    annotationAttributes.add(annotationAttribute);
  }
  if (!annotationAttributes.isEmpty()) {
    elementImpl.setAttributes(annotationAttributes);
  }

  boolean justRead = false;
  if (reader.hasNext()) {
    reader.next();
    justRead = true;
  }

  while (justRead && !(reader.isEndElement() && elementImpl.getName() != null
      && elementImpl.getName().equals(reader.getLocalName()))) {
    justRead = false;
    if (reader.isStartElement()) {
      annotationElements.add(readAnnotationElement(reader));
      if (reader.hasNext()) {
        reader.next();
        justRead = true;
      }
    } else if (reader.isCharacters()) {
      String elementText = "";
      do {
        justRead = false;
        elementText = elementText + reader.getText();
        if (reader.hasNext()) {
          reader.next();
          justRead = true;
        }
      } while (justRead && reader.isCharacters());
      elementImpl.setText(elementText);
    }
  }
  if (!annotationElements.isEmpty()) {
    elementImpl.setChildElements(annotationElements);
  }
  return elementImpl;
}
 
Example 20
Source File: XmlParserStream.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
private ImmutableMap<QName, Object> getElementAttributes(final XMLStreamReader in) {
    checkState(in.isStartElement(), "Attributes can be extracted only from START_ELEMENT.");
    final Map<QName, Object> attributes = new LinkedHashMap<>();

    for (int attrIndex = 0; attrIndex < in.getAttributeCount(); attrIndex++) {
        final String attributeNS = in.getAttributeNamespace(attrIndex);

        // Skip namespace definitions
        if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attributeNS)) {
            continue;
        }

        final String localName = in.getAttributeLocalName(attrIndex);
        final String attrValue = in.getAttributeValue(attrIndex);
        if (Strings.isNullOrEmpty(attributeNS)) {
            StreamWriterFacade.warnLegacyAttribute(localName);
            attributes.put(QName.create(LEGACY_ATTRIBUTE_NAMESPACE, localName), attrValue);
            continue;
        }

        // Cross-relate attribute namespace to the module
        final Optional<QNameModule> optModule = resolveXmlNamespace(attributeNS);
        if (optModule.isPresent()) {
            final QName qname = QName.create(optModule.get(), localName);
            final Optional<AnnotationSchemaNode> optAnnotation = AnnotationSchemaNode.find(
                codecs.getSchemaContext(), qname);
            if (optAnnotation.isPresent()) {
                final AnnotationSchemaNode schema = optAnnotation.get();
                final Object value = codecs.codecFor(schema).parseValue(in.getNamespaceContext(), attrValue);
                attributes.put(schema.getQName(), value);
                continue;
            }

            LOG.debug("Annotation for {} not found, using legacy QName", qname);
        }

        attributes.put(QName.create(rawXmlNamespace(attributeNS), localName), attrValue);
    }

    return ImmutableMap.copyOf(attributes);
}