import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableMap;
+import java.net.URI;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
*/
@Beta
public interface NormalizedMetadata extends Identifiable<PathArgument>, Immutable {
+ /**
+ * {@link QNameModule} for use with legacy XML attributes.
+ * @deprecated The use on this namespace is discouraged and users are strongly encouraged to proper RFC7952 metadata
+ * annotations.
+ */
+ @Deprecated
+ QNameModule LEGACY_ATTRIBUTE_NAMESPACE = QNameModule.create(URI.create("")).intern();
+
/**
* Return the set of annotations defined in this metadata node. Values are expected to be effectively-immutable
* scalar types, like {@link String}s, {@link Number}s and similar. The map must also be effectively-immutable.
*
+ * <p>
+ * Due to backwards compatibility reasons, keys may include QNames with empty URI (as exposed via
+ * {@link #LEGACY_ATTRIBUTE_NAMESPACE}) as their QNameModule. These indicate an unqualified XML attribute and their
+ * value can be assumed to be a String. Furthermore, this extends to qualified attributes, which uses the proper
+ * namespace, but will not bind to a proper module revision -- these need to be reconciled with a particular
+ * SchemaContext and are expected to either be fully decoded, or contain a String value. Handling of such
+ * annotations is at the discretion of the user encountering it: preferred way of handling is to either filter or
+ * normalize them to proper QNames/values when encountered.
+ *
+ * <p>
+ * This caveat will be removed in a future version.
+ *
* @return The set of annotations attached to the corresponding data node.
*/
@NonNull Map<QName, Object> getAnnotations();
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-data-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>rfc7952-data-api</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-data-impl</artifactId>
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.Beta;
+import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import java.io.Closeable;
import java.io.Flushable;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stax.StAXSource;
import org.opendaylight.yangtools.odlext.model.api.YangModeledAnyXmlSchemaNode;
+import org.opendaylight.yangtools.rfc7952.data.api.NormalizedMetadata;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.util.AbstractNodeDataWithSchema;
import org.opendaylight.yangtools.yang.data.util.AnyXmlNodeDataWithSchema;
final Map<QName, String> attributes = new LinkedHashMap<>();
for (int attrIndex = 0; attrIndex < in.getAttributeCount(); attrIndex++) {
- String attributeNS = in.getAttributeNamespace(attrIndex);
-
- if (attributeNS == null) {
- attributeNS = "";
- }
+ final String attributeNS = in.getAttributeNamespace(attrIndex);
// Skip namespace definitions
if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attributeNS)) {
continue;
}
- final QName qName = QName.create(URI.create(attributeNS), in.getAttributeLocalName(attrIndex));
+ final QNameModule namespace;
+ if (!Strings.isNullOrEmpty(attributeNS)) {
+ // FIXME: bind the namespace to a module, if available
+ namespace = QNameModule.create(URI.create(attributeNS));
+ } else {
+ namespace = NormalizedMetadata.LEGACY_ATTRIBUTE_NAMESPACE;
+ }
+
+ final QName qName = QName.create(namespace, in.getAttributeLocalName(attrIndex));
attributes.put(qName, in.getAttributeValue(attrIndex));
}