Bug 2857: Tied pre-existing implementation to BindingCodecTree.
[yangtools.git] / code-generator / binding-data-codec / src / main / java / org / opendaylight / yangtools / binding / data / codec / impl / BindingToNormalizedStreamWriter.java
index a110ff8347bb2e5d7ba82fbb2c75b8e14a7c40fe..a608520a6315668cc71b613ef47ddf869301b66f 100644 (file)
@@ -30,21 +30,21 @@ import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStre
 class BindingToNormalizedStreamWriter implements BindingStreamEventWriter, Delegator<NormalizedNodeStreamWriter> {
 
     private final NormalizedNodeStreamWriter delegate;
-    private final Deque<NodeCodecContext> schema = new ArrayDeque<>();
-    private final NodeCodecContext rootNodeSchema;
+    private final Deque<NodeCodecContext<?>> schema = new ArrayDeque<>();
+    private final NodeCodecContext<?> rootNodeSchema;
 
-    public BindingToNormalizedStreamWriter(final NodeCodecContext schema, final NormalizedNodeStreamWriter delegate) {
+    public BindingToNormalizedStreamWriter(final NodeCodecContext<?> schema, final NormalizedNodeStreamWriter delegate) {
         this.delegate = Preconditions.checkNotNull(delegate, "Delegate must not be null");
         this.rootNodeSchema = Preconditions.checkNotNull(schema);
 
     }
 
-    private NodeCodecContext current() {
+    private NodeCodecContext<?> current() {
         return schema.peek();
     }
 
     private NodeIdentifier duplicateSchemaEnter() {
-        final NodeCodecContext next;
+        final NodeCodecContext<?> next;
         if (current() == null) {
             // Entry of first node
             next = rootNodeSchema;
@@ -55,25 +55,25 @@ class BindingToNormalizedStreamWriter implements BindingStreamEventWriter, Deleg
         return (NodeIdentifier) current().getDomPathArgument();
     }
 
+    @SuppressWarnings({"unchecked", "rawtypes"})
     private <T extends YangInstanceIdentifier.PathArgument> T enter(final Class<?> name, final Class<T> identifier) {
-        final NodeCodecContext next;
+        final NodeCodecContext<?> next;
         if (current() == null) {
             // Entry of first node
             next = rootNodeSchema;
         } else {
             Preconditions.checkArgument((current() instanceof DataContainerCodecContext), "Could not start node %s",
                     name);
-            next = ((DataContainerCodecContext<?>) current()).getStreamChild(name);
+            next = ((DataContainerCodecContext<?,?>) current()).streamChild((Class) name);
         }
         this.schema.push(next);
-        @SuppressWarnings("unchecked")
         T arg = (T) next.getDomPathArgument();
         return arg;
     }
 
     private <T extends YangInstanceIdentifier.PathArgument> T enter(final String localName, final Class<T> identifier) {
-        NodeCodecContext current = current();
-        NodeCodecContext next = ((DataObjectCodecContext<?>) current).getLeafChild(localName);
+        NodeCodecContext<?> current = current();
+        NodeCodecContext<?> next = ((DataObjectCodecContext<?,?>) current).getLeafChild(localName);
         this.schema.push(next);
         @SuppressWarnings("unchecked")
         T arg = (T) next.getDomPathArgument();
@@ -82,7 +82,7 @@ class BindingToNormalizedStreamWriter implements BindingStreamEventWriter, Deleg
 
     @Override
     public void endNode() throws IOException {
-        NodeCodecContext left = schema.pop();
+        NodeCodecContext<?> left = schema.pop();
         // NormalizedNode writer does not have entry into case, but into choice
         // so for leaving case, we do not emit endNode.
         if (!(left instanceof CaseNodeCodecContext)) {
@@ -96,10 +96,10 @@ class BindingToNormalizedStreamWriter implements BindingStreamEventWriter, Deleg
     }
 
     private Map.Entry<NodeIdentifier, Object> serializeLeaf(final String localName, final Object value) {
-        Preconditions.checkArgument(current() instanceof DataObjectCodecContext<?>);
+        Preconditions.checkArgument(current() instanceof DataObjectCodecContext);
 
-        DataObjectCodecContext<?> currentCasted = (DataObjectCodecContext<?>) current();
-        LeafNodeCodecContext leafContext = currentCasted.getLeafChild(localName);
+        DataObjectCodecContext<?,?> currentCasted = (DataObjectCodecContext<?,?>) current();
+        LeafNodeCodecContext<?> leafContext = currentCasted.getLeafChild(localName);
 
         NodeIdentifier domArg = (NodeIdentifier) leafContext.getDomPathArgument();
         Object domValue = leafContext.getValueCodec().serialize(value);
@@ -120,7 +120,7 @@ class BindingToNormalizedStreamWriter implements BindingStreamEventWriter, Deleg
 
     @Override
     public void leafSetEntryNode(final Object value) throws IOException, IllegalArgumentException {
-        LeafNodeCodecContext ctx = (LeafNodeCodecContext) current();
+        LeafNodeCodecContext<?> ctx = (LeafNodeCodecContext<?>) current();
         getDelegate().leafSetEntryNode(ctx.getValueCodec().serialize(value));
     }
 
@@ -156,7 +156,7 @@ class BindingToNormalizedStreamWriter implements BindingStreamEventWriter, Deleg
     @Override
     public void startMapEntryNode(final Identifier<?> key, final int childSizeHint) throws IOException, IllegalArgumentException {
         duplicateSchemaEnter();
-        NodeIdentifierWithPredicates identifier = ((KeyedListNodeCodecContext) current()).serialize(key);
+        NodeIdentifierWithPredicates identifier = ((KeyedListNodeCodecContext<?>) current()).serialize(key);
         getDelegate().startMapEntryNode(identifier, childSizeHint);
     };