Parent schema node input parameter in JsonParserStream 69/12669/4
authorJozef Gloncak <jgloncak@cisco.com>
Fri, 24 Oct 2014 08:43:48 +0000 (10:43 +0200)
committerJozef Gloncak <jgloncak@cisco.com>
Wed, 17 Dec 2014 12:23:46 +0000 (12:23 +0000)
For stable helium

- JsonParserStream - added input parameter to create() factory method which
  specify parent schema node of schema node which is at top level of JSON
  input. Usually it is schema context.

Change-Id: I15ca2bdd0f8ace617d834040cd9a6745b40ee78a
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
(cherry picked from commit 2bba449d5246784298943ccd1359d06f0e8d840f)

yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonParserStream.java

index cea3fa683c02cee5c120370d5c680a325d1b5479..1721f428d5c276edd109dd1cec93b29bb6d2ae15 100644 (file)
@@ -40,6 +40,7 @@ import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 
 /**
@@ -52,15 +53,22 @@ public final class JsonParserStream implements Closeable, Flushable {
     private final NormalizedNodeStreamWriter writer;
     private final JSONCodecFactory codecs;
     private final SchemaContext schema;
+    private final DataSchemaNode parentNode;
 
-    private JsonParserStream(final NormalizedNodeStreamWriter writer, final SchemaContext schemaContext) {
+    private JsonParserStream(final NormalizedNodeStreamWriter writer, final SchemaContext schemaContext, final DataSchemaNode parentNode) {
         this.schema = Preconditions.checkNotNull(schemaContext);
         this.writer = Preconditions.checkNotNull(writer);
         this.codecs = JSONCodecFactory.create(schemaContext);
+        this.parentNode = parentNode;
+    }
+
+    public static JsonParserStream create(final NormalizedNodeStreamWriter writer, final SchemaContext schemaContext, final SchemaNode parentNode ) {
+        Preconditions.checkArgument(parentNode instanceof DataSchemaNode, "Instance of DataSchemaNode class awaited.");
+        return new JsonParserStream(writer, schemaContext, (DataSchemaNode) parentNode);
     }
 
     public static JsonParserStream create(final NormalizedNodeStreamWriter writer, final SchemaContext schemaContext) {
-        return new JsonParserStream(writer, schemaContext);
+        return new JsonParserStream(writer, schemaContext, schemaContext);
     }
 
     public JsonParserStream parse(final JsonReader reader) throws JsonIOException, JsonSyntaxException {
@@ -72,7 +80,7 @@ public final class JsonParserStream implements Closeable, Flushable {
         try {
             reader.peek();
             isEmpty = false;
-            CompositeNodeDataWithSchema compositeNodeDataWithSchema = new CompositeNodeDataWithSchema(schema);
+            CompositeNodeDataWithSchema compositeNodeDataWithSchema = new CompositeNodeDataWithSchema(parentNode);
             read(reader, compositeNodeDataWithSchema);
             compositeNodeDataWithSchema.write(writer);