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();
}
}
@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.
}
@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();
}
}