This variant allows passing a DataSchemaNode from the user.
Implementations can take advantage of this information to optimize their
result. Utility no-op adaptors are provided, too.
Change-Id: I990197baf3a80f9826cd35d3bb3155d1b7a10cc3
Signed-off-by: Robert Varga <rovarga@cisco.com>
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.api.schema.stream;
+
+import com.google.common.annotations.Beta;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+
+/**
+ * Mixin interface for {@link NormalizedNodeStreamWriter} allowing callers to inform the writer of the
+ * {@link DataSchemaNode} corresponding to the next node which will either be started or emitted. This interface should
+ * not be implemented directly.
+ */
+@Beta
+public interface DataSchemaNodeAware {
+ /**
+ * Attach the specified {@link DataSchemaNode} to the next node which will get started or emitted.
+ *
+ * @param schema DataSchemaNode
+ * @throws NullPointerException if the argument is null
+ */
+ void nextDataSchemaNode(@Nonnull DataSchemaNode schema);
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.api.schema.stream;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+
+/**
+ * Utility class for adapting {@link NormalizedNodeStreamWriter}s to their {@link DataSchemaNodeAware} counterparts
+ * which ignore the provided schema node.
+ */
+@Beta
+public final class DataSchemaNodeAwareAdaptor {
+ private DataSchemaNodeAwareAdaptor() {
+ throw new UnsupportedOperationException();
+ }
+
+ public static SchemaAwareNormalizedNodeStreamAttributeWriter forAttributeWriter(
+ @Nonnull final NormalizedNodeStreamAttributeWriter writer) {
+ Preconditions.checkNotNull(writer, "Writer must not be null");
+
+ if (writer instanceof SchemaAwareNormalizedNodeStreamAttributeWriter) {
+ return (SchemaAwareNormalizedNodeStreamAttributeWriter) writer;
+ }
+
+ return new AttributeWriter() {
+ @Override
+ protected NormalizedNodeStreamAttributeWriter delegate() {
+ return writer;
+ }
+ };
+ }
+
+ public static SchemaAwareNormalizedNodeStreamWriter forWriter(@Nonnull final NormalizedNodeStreamWriter writer) {
+ Preconditions.checkNotNull(writer, "Writer must not be null");
+
+ if (writer instanceof SchemaAwareNormalizedNodeStreamWriter) {
+ return (SchemaAwareNormalizedNodeStreamWriter) writer;
+ }
+ if (writer instanceof NormalizedNodeStreamAttributeWriter) {
+ return forAttributeWriter((NormalizedNodeStreamAttributeWriter) writer);
+ }
+
+ return new Writer() {
+ @Override
+ protected NormalizedNodeStreamWriter delegate() {
+ return writer;
+ }
+ };
+ }
+
+ private static abstract class AttributeWriter extends ForwardingNormalizedNodeStreamAttributeWriter
+ implements SchemaAwareNormalizedNodeStreamAttributeWriter {
+ @Override
+ public void nextDataSchemaNode(final DataSchemaNode schema) {
+ // Intentional no-op
+ }
+ }
+
+ private static abstract class Writer extends ForwardingNormalizedNodeStreamWriter
+ implements SchemaAwareNormalizedNodeStreamWriter {
+ @Override
+ public void nextDataSchemaNode(final DataSchemaNode schema) {
+ // Intentional no-op
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.api.schema.stream;
+
+import java.io.IOException;
+import java.util.Map;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+
+abstract class ForwardingNormalizedNodeStreamAttributeWriter extends ForwardingNormalizedNodeStreamWriter implements NormalizedNodeStreamAttributeWriter {
+ @Override
+ protected abstract NormalizedNodeStreamAttributeWriter delegate();
+
+ @Override
+ public void leafNode(final NodeIdentifier name, final Object value, final Map<QName, String> attributes)
+ throws IOException {
+ delegate().leafNode(name, value, attributes);
+ }
+
+ @Override
+ public void leafSetEntryNode(final Object value, final Map<QName, String> attributes) throws IOException {
+ delegate().leafSetEntryNode(value, attributes);
+ }
+
+ @Override
+ public void startContainerNode(final NodeIdentifier name, final int childSizeHint,
+ final Map<QName, String> attributes) throws IOException {
+ delegate().startContainerNode(name, childSizeHint, attributes);
+ }
+
+ @Override
+ public void startUnkeyedListItem(final NodeIdentifier name, final int childSizeHint,
+ final Map<QName, String> attributes) throws IOException {
+ delegate().startUnkeyedListItem(name, childSizeHint, attributes);
+ }
+
+ @Override
+ public void startMapEntryNode(final NodeIdentifierWithPredicates identifier, final int childSizeHint,
+ final Map<QName, String> attributes) throws IOException {
+ delegate().startMapEntryNode(identifier, childSizeHint, attributes);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.api.schema.stream;
+
+import com.google.common.collect.ForwardingObject;
+import java.io.IOException;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+
+abstract class ForwardingNormalizedNodeStreamWriter extends ForwardingObject implements NormalizedNodeStreamWriter {
+ @Override
+ protected abstract NormalizedNodeStreamWriter delegate();
+
+ @Override
+ public void leafNode(final NodeIdentifier name, final Object value) throws IOException {
+ delegate().leafNode(name, value);
+ }
+
+ @Override
+ public void startLeafSet(final NodeIdentifier name, final int childSizeHint) throws IOException {
+ delegate().startLeafSet(name, childSizeHint);
+ }
+
+ @Override
+ public void leafSetEntryNode(final Object value) throws IOException {
+ delegate().leafSetEntryNode(value);
+ }
+
+ @Override
+ public void startContainerNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
+ delegate().startContainerNode(name, childSizeHint);
+ }
+
+ @Override
+ public void startUnkeyedList(final NodeIdentifier name, final int childSizeHint) throws IOException {
+ delegate().startUnkeyedList(name, childSizeHint);
+ }
+
+ @Override
+ public void startUnkeyedListItem(final NodeIdentifier name, final int childSizeHint) throws IOException {
+ delegate().startUnkeyedListItem(name, childSizeHint);
+ }
+
+ @Override
+ public final void startMapNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
+ delegate().startMapNode(name, childSizeHint);
+ }
+
+ @Override
+ public void startMapEntryNode(final NodeIdentifierWithPredicates identifier, final int childSizeHint)
+ throws IOException {
+ delegate().startMapEntryNode(identifier, childSizeHint);
+ }
+
+ @Override
+ public void startOrderedMapNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
+ delegate().startOrderedMapNode(name, childSizeHint);
+ }
+
+ @Override
+ public void startChoiceNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
+ delegate().startChoiceNode(name, childSizeHint);
+ }
+
+ @Override
+ public void startAugmentationNode(final AugmentationIdentifier identifier) throws IOException {
+ delegate().startAugmentationNode(identifier);
+ }
+
+ @Override
+ public void anyxmlNode(final NodeIdentifier name, final Object value) throws IOException {
+ delegate().anyxmlNode(name, value);
+ }
+
+ @Override
+ public void endNode() throws IOException {
+ delegate().endNode();
+ }
+
+ @Override
+ public void close() throws IOException {
+ delegate().close();
+ }
+
+ @Override
+ public void flush() throws IOException {
+ delegate().flush();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.api.schema.stream;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+
+/**
+ * Marker interface for {@link SchemaAwareNormalizedNodeStreamAttributeWriter}s which can take advantage of
+ * {@link DataSchemaNode} information when writing the nodes.
+ */
+@Beta
+public interface SchemaAwareNormalizedNodeStreamAttributeWriter
+ extends NormalizedNodeStreamAttributeWriter, SchemaAwareNormalizedNodeStreamWriter {
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.api.schema.stream;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+
+/**
+ * Marker interface for {@link NormalizedNodeStreamWriter}s which can take advantage of {@link DataSchemaNode}
+ * information when writing the nodes.
+ */
+@Beta
+public interface SchemaAwareNormalizedNodeStreamWriter extends NormalizedNodeStreamWriter, DataSchemaNodeAware {
+
+}