Validate parsed QName to identity 76/69076/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 5 Mar 2018 14:11:45 +0000 (15:11 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 5 Mar 2018 14:12:21 +0000 (15:12 +0100)
We need to validate if parsed QName refers to an existing identity,
this fixes up unused AbstractModuleStringIdentityrefCodec to check
Module references.

Change-Id: Iebbb43681e9b384c43bd81607d169294373bdd72
JIRA: YANGTOOLS-846
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/AbstractModuleStringIdentityrefCodec.java

index 29c0d173ed81805245f75cd421f9b00bfd33973b..d2c373eea1f4e57be03f166eb1c5236486fa3773 100644 (file)
@@ -12,6 +12,7 @@ import static com.google.common.base.Preconditions.checkArgument;
 import com.google.common.annotations.Beta;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 
 @Beta
@@ -28,6 +29,14 @@ public abstract class AbstractModuleStringIdentityrefCodec extends AbstractStrin
     protected final QName createQName(@Nonnull final String prefix, @Nonnull final String localName) {
         final Module module = moduleForPrefix(prefix);
         checkArgument(module != null, "Failed to lookup prefix %s", prefix);
-        return QName.create(module.getQNameModule(), localName);
+
+        final QName qname = QName.create(module.getQNameModule(), localName);
+        for (IdentitySchemaNode identity : module.getIdentities()) {
+            if (qname.equals(identity.getQName())) {
+                return identity.getQName();
+            }
+        }
+
+        throw new IllegalArgumentException("Failed to find identity matching " + qname);
     }
 }