BUG-865: remove reference to SchemaAwareNormalizedNodeStreamWriter 92/40092/5
authorRobert Varga <rovarga@cisco.com>
Thu, 9 Jun 2016 08:49:19 +0000 (10:49 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 14 Jun 2016 12:47:20 +0000 (12:47 +0000)
All functionality has been integrated ito NormalizedNodeStreamWriter, hence
the two subclasses are no longer needed. Remove reference to the old type
so it can be removed.

Change-Id: I0e0ef84279b5504bb18bcf164ae3a5091fa04582
Signed-off-by: Robert Varga <rovarga@cisco.com>
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingToNormalizedStreamWriter.java

index 1aeaeb56f3181858a8c54737d87bbb36b6b17f10..794cec8a9c058f9105a27f49ffbcc5494f943bdf 100644 (file)
@@ -26,66 +26,27 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.Augmentat
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
-import org.opendaylight.yangtools.yang.data.api.schema.stream.SchemaAwareNormalizedNodeStreamWriter;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 
-abstract class BindingToNormalizedStreamWriter implements BindingStreamEventWriter, Delegator<NormalizedNodeStreamWriter> {
-    private static final class Schemaless extends BindingToNormalizedStreamWriter {
-        private final NormalizedNodeStreamWriter delegate;
-
-        Schemaless(final NodeCodecContext<?> schema, final NormalizedNodeStreamWriter delegate) {
-            super(schema);
-            this.delegate = Preconditions.checkNotNull(delegate, "Delegate must not be null");
-        }
-
-        @Override
-        public NormalizedNodeStreamWriter getDelegate() {
-            return delegate;
-        }
-
-        @Override
-        protected void emitSchema(final Object schema) {
-            // No-op
-        }
-    }
-
-    private static final class SchemaAware extends BindingToNormalizedStreamWriter {
-        private final SchemaAwareNormalizedNodeStreamWriter delegate;
-
-        SchemaAware(final NodeCodecContext<?> schema, final SchemaAwareNormalizedNodeStreamWriter delegate) {
-            super(schema);
-            this.delegate = Preconditions.checkNotNull(delegate, "Delegate must not be null");
-        }
-
-        @Override
-        public SchemaAwareNormalizedNodeStreamWriter getDelegate() {
-            return delegate;
-        }
-
-        @Override
-        protected void emitSchema(final Object schema) {
-            delegate.nextDataSchemaNode((DataSchemaNode) schema);
-        }
-    }
-
+final class BindingToNormalizedStreamWriter implements BindingStreamEventWriter, Delegator<NormalizedNodeStreamWriter> {
     private final Deque<NodeCodecContext<?>> schema = new ArrayDeque<>();
+    private final NormalizedNodeStreamWriter delegate;
     private final NodeCodecContext<?> rootNodeSchema;
 
-    BindingToNormalizedStreamWriter(final NodeCodecContext<?> schema) {
-        this.rootNodeSchema = Preconditions.checkNotNull(schema);
+    BindingToNormalizedStreamWriter(final NodeCodecContext<?> rootNodeSchema, final NormalizedNodeStreamWriter delegate) {
+        this.rootNodeSchema = Preconditions.checkNotNull(rootNodeSchema);
+        this.delegate = Preconditions.checkNotNull(delegate);
     }
 
     static BindingToNormalizedStreamWriter create(final NodeCodecContext<?> schema, final NormalizedNodeStreamWriter delegate) {
-        if (delegate instanceof SchemaAwareNormalizedNodeStreamWriter) {
-            return new SchemaAware(schema, (SchemaAwareNormalizedNodeStreamWriter) delegate);
-        } else {
-            return new Schemaless(schema, delegate);
-        }
+            return new BindingToNormalizedStreamWriter(schema, delegate);
     }
 
-    protected abstract void emitSchema(Object schema);
+    private void emitSchema(final Object schema) {
+        delegate.nextDataSchemaNode((DataSchemaNode) schema);
+    }
 
-    protected final NodeCodecContext<?> current() {
+    NodeCodecContext<?> current() {
         return schema.peek();
     }
 
@@ -127,7 +88,12 @@ abstract class BindingToNormalizedStreamWriter implements BindingStreamEventWrit
     }
 
     @Override
-    public final void endNode() throws IOException {
+    public NormalizedNodeStreamWriter getDelegate() {
+        return delegate;
+    }
+
+    @Override
+    public void endNode() throws IOException {
         NodeCodecContext<?> left = schema.pop();
         // NormalizedNode writer does not have entry into case, but into choice
         // so for leaving case, we do not emit endNode.
@@ -149,95 +115,95 @@ abstract class BindingToNormalizedStreamWriter implements BindingStreamEventWrit
     }
 
     @Override
-    public final void leafNode(final String localName, final Object value) throws IOException {
+    public void leafNode(final String localName, final Object value) throws IOException {
         Entry<NodeIdentifier, Object> dom = serializeLeaf(localName, value);
         getDelegate().leafNode(dom.getKey(), dom.getValue());
     }
 
     @Override
-    public final void anyxmlNode(final String name, final Object value) throws IOException {
+    public void anyxmlNode(final String name, final Object value) throws IOException {
         Entry<NodeIdentifier, Object> dom = serializeLeaf(name, value);
         getDelegate().anyxmlNode(dom.getKey(), dom.getValue());
     }
 
     @Override
-    public final void leafSetEntryNode(final Object value) throws IOException {
+    public void leafSetEntryNode(final Object value) throws IOException {
         LeafNodeCodecContext<?> ctx = (LeafNodeCodecContext<?>) current();
         getDelegate().leafSetEntryNode(((DataSchemaNode) ctx.getSchema()).getQName(),
             ctx.getValueCodec().serialize(value));
     }
 
     @Override
-    public final void startAugmentationNode(final Class<? extends Augmentation<?>> augmentationType)
+    public void startAugmentationNode(final Class<? extends Augmentation<?>> augmentationType)
             throws IOException {
         getDelegate().startAugmentationNode(enter(augmentationType, AugmentationIdentifier.class));
     }
 
     @Override
-    public final void startCase(final Class<? extends DataObject> caze, final int childSizeHint) {
+    public void startCase(final Class<? extends DataObject> caze, final int childSizeHint) {
         enter(caze, NodeIdentifier.class);
     }
 
     @Override
-    public final void startChoiceNode(final Class<? extends DataContainer> type, final int childSizeHint)
+    public void startChoiceNode(final Class<? extends DataContainer> type, final int childSizeHint)
             throws IOException {
         getDelegate().startChoiceNode(enter(type, NodeIdentifier.class), childSizeHint);
     }
 
     @Override
-    public final void startContainerNode(final Class<? extends DataObject> object, final int childSizeHint)
+    public void startContainerNode(final Class<? extends DataObject> object, final int childSizeHint)
             throws IOException {
         getDelegate().startContainerNode(enter(object, NodeIdentifier.class), childSizeHint);
     }
 
     @Override
-    public final void startLeafSet(final String localName, final int childSizeHint) throws IOException {
+    public void startLeafSet(final String localName, final int childSizeHint) throws IOException {
         final NodeIdentifier id = enter(localName, NodeIdentifier.class);
         emitSchema(current().getSchema());
         getDelegate().startLeafSet(id, childSizeHint);
     }
 
     @Override
-    public final void startOrderedLeafSet(final String localName, final int childSizeHint) throws IOException {
+    public void startOrderedLeafSet(final String localName, final int childSizeHint) throws IOException {
         getDelegate().startOrderedLeafSet(enter(localName, NodeIdentifier.class), childSizeHint);
     }
 
     @Override
-    public final void startMapEntryNode(final Identifier<?> key, final int childSizeHint) throws IOException {
+    public void startMapEntryNode(final Identifier<?> key, final int childSizeHint) throws IOException {
         duplicateSchemaEnter();
         NodeIdentifierWithPredicates identifier = ((KeyedListNodeCodecContext<?>) current()).serialize(key);
         getDelegate().startMapEntryNode(identifier, childSizeHint);
     }
 
     @Override
-    public final <T extends DataObject & Identifiable<?>> void startMapNode(final Class<T> mapEntryType,
+    public <T extends DataObject & Identifiable<?>> void startMapNode(final Class<T> mapEntryType,
             final int childSizeHint) throws IOException {
         getDelegate().startMapNode(enter(mapEntryType, NodeIdentifier.class), childSizeHint);
     }
 
     @Override
-    public final <T extends DataObject & Identifiable<?>> void startOrderedMapNode(final Class<T> mapEntryType,
+    public <T extends DataObject & Identifiable<?>> void startOrderedMapNode(final Class<T> mapEntryType,
             final int childSizeHint) throws IOException {
         getDelegate().startOrderedMapNode(enter(mapEntryType, NodeIdentifier.class), childSizeHint);
     }
 
     @Override
-    public final void startUnkeyedList(final Class<? extends DataObject> obj, final int childSizeHint) throws IOException {
+    public void startUnkeyedList(final Class<? extends DataObject> obj, final int childSizeHint) throws IOException {
         getDelegate().startUnkeyedList(enter(obj, NodeIdentifier.class), childSizeHint);
     }
 
     @Override
-    public final void startUnkeyedListItem(final int childSizeHint) throws IOException {
+    public void startUnkeyedListItem(final int childSizeHint) throws IOException {
         getDelegate().startUnkeyedListItem(duplicateSchemaEnter(), childSizeHint);
     }
 
     @Override
-    public final void flush() throws IOException {
+    public void flush() throws IOException {
         getDelegate().flush();
     }
 
     @Override
-    public final void close() throws IOException {
+    public void close() throws IOException {
         getDelegate().close();
     }
 }