Validate parsed QName to identity 79/69079/3
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:41:33 +0000 (15:41 +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>
(cherry picked from commit 86ed935221b79680e8aca7a5e561fed6d89ed084)

yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/AbstractModuleStringIdentityrefCodec.java

index 886b8438ef7df9251dcacbd337ee497af7237c7d..d87b6c13b0a9046259704ee5b8f6c4286f6c2124 100644 (file)
@@ -13,6 +13,7 @@ import com.google.common.base.Preconditions;
 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
@@ -29,6 +30,14 @@ public abstract class AbstractModuleStringIdentityrefCodec extends AbstractStrin
     protected final QName createQName(@Nonnull final String prefix, @Nonnull final String localName) {
         final Module module = moduleForPrefix(prefix);
         Preconditions.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);
     }
 }