From: Robert Varga Date: Thu, 9 Jun 2016 08:49:19 +0000 (+0200) Subject: BUG-865: remove reference to SchemaAwareNormalizedNodeStreamWriter X-Git-Tag: release/boron~108 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=c911f1eff999d460ea3056ff15808d5883853067;p=mdsal.git BUG-865: remove reference to SchemaAwareNormalizedNodeStreamWriter 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 --- diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingToNormalizedStreamWriter.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingToNormalizedStreamWriter.java index 1aeaeb56f3..794cec8a9c 100644 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingToNormalizedStreamWriter.java +++ b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingToNormalizedStreamWriter.java @@ -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 { - 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 { private final Deque> 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 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 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> augmentationType) + public void startAugmentationNode(final Class> augmentationType) throws IOException { getDelegate().startAugmentationNode(enter(augmentationType, AugmentationIdentifier.class)); } @Override - public final void startCase(final Class caze, final int childSizeHint) { + public void startCase(final Class caze, final int childSizeHint) { enter(caze, NodeIdentifier.class); } @Override - public final void startChoiceNode(final Class type, final int childSizeHint) + public void startChoiceNode(final Class type, final int childSizeHint) throws IOException { getDelegate().startChoiceNode(enter(type, NodeIdentifier.class), childSizeHint); } @Override - public final void startContainerNode(final Class object, final int childSizeHint) + public void startContainerNode(final Class 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 > void startMapNode(final Class mapEntryType, + public > void startMapNode(final Class mapEntryType, final int childSizeHint) throws IOException { getDelegate().startMapNode(enter(mapEntryType, NodeIdentifier.class), childSizeHint); } @Override - public final > void startOrderedMapNode(final Class mapEntryType, + public > void startOrderedMapNode(final Class mapEntryType, final int childSizeHint) throws IOException { getDelegate().startOrderedMapNode(enter(mapEntryType, NodeIdentifier.class), childSizeHint); } @Override - public final void startUnkeyedList(final Class obj, final int childSizeHint) throws IOException { + public void startUnkeyedList(final Class 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(); } }