- final QName qName = QName.create(URI.create(attributeNS), in.getAttributeLocalName(attrIndex));
- attributes.put(qName, in.getAttributeValue(attrIndex));
+ 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 URI uri = URI.create(attributeNS);
+ final SchemaContext schemaContext = codecs.getSchemaContext();
+ final Set<Module> modules = schemaContext.findModules(uri);
+ if (!modules.isEmpty()) {
+ final QName qname = QName.create(modules.iterator().next().getQNameModule(), localName);
+ final Optional<AnnotationSchemaNode> optAnnotation = AnnotationSchemaNode.find(schemaContext, 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(uri, localName), attrValue);