package org.opendaylight.controller.cluster.datastore.node.utils.transformer;
import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Verify.verify;
import static java.util.Objects.requireNonNull;
import java.io.IOException;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
@FunctionalInterface
- private interface WriterMethod<T extends PathArgument> {
+ interface WriterMethod<T extends PathArgument> {
void apply(ReusableImmutableNormalizedNodeStreamWriter writer, T name) throws IOException;
}
@FunctionalInterface
- private interface SizedWriterMethod<T extends PathArgument> {
+ interface SizedWriterMethod<T extends PathArgument> {
void apply(ReusableImmutableNormalizedNodeStreamWriter writer, T name, int childSizeHint) throws IOException;
}
private final DataSchemaContextTree tree;
private DataSchemaContextNode<?> nodePathSchemaNode;
+ private NormalizedNode normalizedNode;
private State state = State.UNITIALIZED;
private int unknown;
- // FIXME: package-private to support unguarded NormalizedNodePruner access
- NormalizedNode<?, ?> normalizedNode;
-
AbstractNormalizedNodePruner(final DataSchemaContextTree tree) {
this.tree = requireNonNull(tree);
}
- AbstractNormalizedNodePruner(final SchemaContext schemaContext) {
+ AbstractNormalizedNodePruner(final EffectiveModelContext schemaContext) {
this(DataSchemaContextTree.from(schemaContext));
}
}
@Override
- public void startLeafNode(final NodeIdentifier name) throws IOException {
+ public final void startLeafNode(final NodeIdentifier name) throws IOException {
enter(ReusableImmutableNormalizedNodeStreamWriter::startLeafNode, name);
}
@Override
- public void startLeafSet(final NodeIdentifier name, final int childSizeHint) throws IOException {
+ public final void startLeafSet(final NodeIdentifier name, final int childSizeHint) throws IOException {
enter(ReusableImmutableNormalizedNodeStreamWriter::startLeafSet, name, childSizeHint);
}
@Override
- public void startOrderedLeafSet(final NodeIdentifier name, final int childSizeHint) throws IOException {
+ public final void startOrderedLeafSet(final NodeIdentifier name, final int childSizeHint) throws IOException {
enter(ReusableImmutableNormalizedNodeStreamWriter::startOrderedLeafSet, name, childSizeHint);
}
}
@Override
- public void startContainerNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
+ public final void startContainerNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
enter(ReusableImmutableNormalizedNodeStreamWriter::startContainerNode, name, childSizeHint);
}
@Override
- public void startYangModeledAnyXmlNode(final NodeIdentifier nodeIdentifier, final int count) {
- // FIXME: implement this
- throw new UnsupportedOperationException("Not implemented yet");
- }
-
- @Override
- public void startUnkeyedList(final NodeIdentifier name, final int childSizeHint) throws IOException {
+ public final void startUnkeyedList(final NodeIdentifier name, final int childSizeHint) throws IOException {
enter(ReusableImmutableNormalizedNodeStreamWriter::startUnkeyedList, name, childSizeHint);
}
@Override
- public void startUnkeyedListItem(final NodeIdentifier name, final int childSizeHint) throws IOException {
+ public final void startUnkeyedListItem(final NodeIdentifier name, final int childSizeHint) throws IOException {
enter(ReusableImmutableNormalizedNodeStreamWriter::startUnkeyedListItem, name, childSizeHint);
}
@Override
- public void startMapNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
+ public final void startMapNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
enter(ReusableImmutableNormalizedNodeStreamWriter::startMapNode, name, childSizeHint);
}
}
@Override
- public void startOrderedMapNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
+ public final void startOrderedMapNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
enter(ReusableImmutableNormalizedNodeStreamWriter::startOrderedMapNode, name, childSizeHint);
}
@Override
- public void startChoiceNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
+ public final void startChoiceNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
enter(ReusableImmutableNormalizedNodeStreamWriter::startChoiceNode, name, childSizeHint);
}
@Override
- public void startAugmentationNode(final AugmentationIdentifier identifier) throws IOException {
+ public final void startAugmentationNode(final AugmentationIdentifier identifier) throws IOException {
enter(ReusableImmutableNormalizedNodeStreamWriter::startAugmentationNode, identifier);
}
@Override
- public void startAnyxmlNode(final NodeIdentifier name) throws IOException {
- enter(ReusableImmutableNormalizedNodeStreamWriter::startAnyxmlNode, name);
+ public final boolean startAnyxmlNode(final NodeIdentifier name, final Class<?> objectModel) throws IOException {
+ if (enter(name)) {
+ verify(delegate.startAnyxmlNode(name, objectModel),
+ "Unexpected failure to stream DOMSource node %s model %s", name, objectModel);
+ }
+ return true;
+ }
+
+ @Override
+ public final boolean startAnydataNode(final NodeIdentifier name, final Class<?> objectModel) throws IOException {
+ // FIXME: we do not support anydata nodes yet
+ return false;
}
@Override
- public void domSourceValue(final DOMSource value) throws IOException {
+ public final void domSourceValue(final DOMSource value) throws IOException {
checkNotSealed();
if (unknown == 0) {
delegate.domSourceValue(value);
}
@Override
- public void scalarValue(final Object value) throws IOException {
+ public final void scalarValue(final Object value) throws IOException {
checkNotSealed();
if (unknown == 0) {
- delegate.scalarValue(translateScalar(stack.peek(), value));
+ delegate.scalarValue(translateScalar(currentSchema(), value));
}
}
}
@Override
- public void endNode() throws IOException {
+ public final void endNode() throws IOException {
checkNotSealed();
if (unknown == 0) {
}
@Override
- public void close() throws IOException {
+ public final void close() throws IOException {
state = State.CLOSED;
stack.clear();
delegate.close();
}
@Override
- public void flush() throws IOException {
+ public final void flush() throws IOException {
delegate.flush();
}
* @return Resulting node for the path, if it was not pruned
* @throws IllegalStateException if this pruner has not been closed
*/
- public final Optional<NormalizedNode<?, ?>> getResult() {
+ public final Optional<NormalizedNode> getResult() {
checkState(state == State.CLOSED, "Cannot get result in state %s", state);
return Optional.ofNullable(normalizedNode);
}
}
final DataSchemaContextNode<?> schema;
- final DataSchemaContextNode<?> parent = stack.peek();
+ final DataSchemaContextNode<?> parent = currentSchema();
if (parent != null) {
schema = parent.getChild(name);
} else {
return true;
}
- private <A extends PathArgument> void enter(final WriterMethod<A> method, final A name) throws IOException {
+ final <A extends PathArgument> void enter(final WriterMethod<A> method, final A name) throws IOException {
if (enter(name)) {
method.apply(delegate, name);
}
}
- private <A extends PathArgument> void enter(final SizedWriterMethod<A> method, final A name, final int size)
+ final <A extends PathArgument> void enter(final SizedWriterMethod<A> method, final A name, final int size)
throws IOException {
if (enter(name)) {
method.apply(delegate, name, size);
}
}
+
+ final DataSchemaContextNode<?> currentSchema() {
+ return stack.peek();
+ }
}