BUG-4145: check if entire YangInstanceIdentifier is present in SchemaContext
[yangtools.git] / yang / yang-data-util / src / main / java / org / opendaylight / yangtools / yang / data / util / AbstractStringInstanceIdentifierCodec.java
index ef6ac8eb31860a72325d98d7436f82ba291f8e24..6e1c0a72e5ec73099ac24c78d617ea53ff9259de 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.codec.InstanceIdentifierCodec;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 
 /**
  * Abstract utility class for representations which encode {@link YangInstanceIdentifier} as a
@@ -31,15 +32,16 @@ public abstract class AbstractStringInstanceIdentifierCodec extends AbstractName
         DataSchemaContextNode<?> current = getDataContextTree().getRoot();
         for (PathArgument arg : data.getPathArguments()) {
             current = current.getChild(arg);
+            Preconditions.checkArgument(current != null,
+                    "Invalid input %s: schema for argument %s (after %s) not found", data, arg, sb);
 
-            if(current.isMixin()) {
+            if (current.isMixin()) {
                 /*
                  * XML/YANG instance identifier does not have concept
                  * of augmentation identifier, or list as whole which
-                 * identifies mixin (same as paretn element),
+                 * identifies a mixin (same as the parent element),
                  * so we can safely ignore it if it is part of path
                  * (since child node) is identified in same fashion.
-                 *
                  */
                 continue;
             }
@@ -83,6 +85,10 @@ public abstract class AbstractStringInstanceIdentifierCodec extends AbstractName
      */
     protected abstract @Nonnull DataSchemaContextTree getDataContextTree();
 
+    protected Object deserializeKeyValue(final DataSchemaNode schemaNode, final String value) {
+        return value;
+    }
+
     @Override
     public final YangInstanceIdentifier deserialize(final String data) {
         Preconditions.checkNotNull(data, "Data may not be null");