Bug 8745: Add support for parsing attributes to the new XML parser
[yangtools.git] / yang / yang-data-util / src / main / java / org / opendaylight / yangtools / yang / data / util / AbstractNodeDataWithSchema.java
index b6368c768e4c057e143d9469926f0ef67a8bd776..db7cb770650ad1f438d0387592124a0d2e5eac0a 100644 (file)
@@ -10,7 +10,9 @@ package org.opendaylight.yangtools.yang.data.util;
 import com.google.common.annotations.Beta;
 import com.google.common.base.Preconditions;
 import java.io.IOException;
+import java.util.Map;
 import java.util.Objects;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@@ -22,6 +24,7 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 @Beta
 public abstract class AbstractNodeDataWithSchema {
     private final DataSchemaNode schema;
+    private Map<QName, String> attributes;
 
     public AbstractNodeDataWithSchema(final DataSchemaNode schema) {
         this.schema = Preconditions.checkNotNull(schema);
@@ -36,6 +39,26 @@ public abstract class AbstractNodeDataWithSchema {
         return schema;
     }
 
+    /**
+     * Set the associated attributes.
+     *
+     * @param attributes parsed attributes
+     */
+    public final void setAttributes(final Map<QName, String> attributes) {
+        Preconditions.checkState(this.attributes == null, "Node '%s' has already set its attributes to %s.",
+                getSchema().getQName(), this.attributes);
+        this.attributes = attributes;
+    }
+
+    /**
+     * Return the associated attributes.
+     *
+     * @return associated attributes
+     */
+    public final Map<QName, String> getAttributes() {
+        return attributes;
+    }
+
     /**
      * Emit this node's events into the specified writer.
      *