X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-data-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fdata%2Fimpl%2Fschema%2FImmutableNormalizedNodeStreamWriter.java;h=d8b9dc438e17282277b1941dff256d14ac82fb87;hb=refs%2Fchanges%2F13%2F93913%2F1;hp=3ac6f32b0871a27a5982e77c25af8c83eb8ae642;hpb=e250f536389b2104171dd6c10a0a27783d602e0b;p=yangtools.git diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNormalizedNodeStreamWriter.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNormalizedNodeStreamWriter.java index 3ac6f32b08..d8b9dc438e 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNormalizedNodeStreamWriter.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNormalizedNodeStreamWriter.java @@ -7,288 +7,362 @@ */ package org.opendaylight.yangtools.yang.data.impl.schema; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; +import static java.util.Objects.requireNonNull; + import java.io.IOException; import java.util.ArrayDeque; import java.util.Deque; -import java.util.List; +import javax.xml.transform.dom.DOMSource; +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.yangtools.odlext.model.api.YangModeledAnyxmlSchemaNode; 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; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; -import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode; -import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode; -import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAnyXmlNodeBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAnydataNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAugmentationNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedLeafSetNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedMapNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableYangModeledAnyXmlNodeBuilder; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; /** + * Implementation of {@link NormalizedNodeStreamWriter}, which constructs immutable instances of + * {@link NormalizedNode}s. * - * Implementation of {@link NormalizedNodeStreamWriter}, which constructs - * immutable instances of {@link NormalizedNode}s. *

- * This writer supports two modes of behaviour one is using {@link #from(NormalizedNodeResult)} - * where resulting NormalizedNode will be stored in supplied result object. - * - * Other mode of operation is using {@link #from(NormalizedNodeContainerBuilder)}, - * where all created nodes will be written to this builder. + * This writer supports two modes of behaviour one is using {@link #from(NormalizedNodeResult)} where resulting + * NormalizedNode will be stored in supplied result object. * + *

+ * Other mode of operation is using {@link #from(NormalizedNodeContainerBuilder)}, where all created nodes will be + * written to this builder. * + *

+ * This class is not final for purposes of customization, normal users should not need to subclass it. */ public class ImmutableNormalizedNodeStreamWriter implements NormalizedNodeStreamWriter { - @SuppressWarnings("rawtypes") - private final Deque builders = new ArrayDeque<>(); + private final Deque builders = new ArrayDeque<>(); + + private DataSchemaNode nextSchema; @SuppressWarnings("rawtypes") - private ImmutableNormalizedNodeStreamWriter( final NormalizedNodeContainerBuilder topLevelBuilder) { + protected ImmutableNormalizedNodeStreamWriter(final NormalizedNodeBuilder topLevelBuilder) { builders.push(topLevelBuilder); } + protected ImmutableNormalizedNodeStreamWriter(final NormalizedNodeResult result) { + this(new NormalizedNodeResultBuilder(result)); + } + /** - * Creates a {@link NormalizedNodeStreamWriter} which creates instances of supplied - * {@link NormalizedNode}s and writes them to supplied builder as child nodes. + * Creates a {@link NormalizedNodeStreamWriter} which creates instances of supplied {@link NormalizedNode}s + * and writes them to supplied builder as child nodes. + * *

- * Type of supplied {@link NormalizedNodeContainerBuilder} affects, - * which events could be emitted in order to ensure proper construction of - * data. + * Type of supplied {@link NormalizedNodeContainerBuilder} affects, which events could be emitted in order + * to ensure proper construction of data. * * @param builder Builder to which data will be written. * @return {@link NormalizedNodeStreamWriter} which writes data */ - public static final NormalizedNodeStreamWriter from(final NormalizedNodeContainerBuilder builder) { + public static @NonNull NormalizedNodeStreamWriter from(final NormalizedNodeContainerBuilder builder) { return new ImmutableNormalizedNodeStreamWriter(builder); } /** + * Creates a {@link NormalizedNodeStreamWriter} which creates one instance of top-level {@link NormalizedNode} + * (type of NormalizedNode) is determined by first start event. * - * Creates a {@link NormalizedNodeStreamWriter} which creates one instance of top - * level {@link NormalizedNode} (type of NormalizedNode) is determined by first - * start event. *

- * Result is built when {@link #endNode()} associated with that start event - * is emitted. + * Result is built when {@link #endNode()} associated with that start event is emitted. + * *

- * Writer properly creates also nested {@link NormalizedNode} instances, - * if their are supported inside the scope of first event. + * Writer properly creates also nested {@link NormalizedNode} instances, if their are supported inside the scope + * of the first event. + * *

- * This method is useful for clients, which knows there will be one - * top level node written, but does not know which type of {@link NormalizedNode} - * will be written. + * This method is useful for clients, which knows there will be one top-level node written, but does not know which + * type of {@link NormalizedNode} will be written. * * @param result {@link NormalizedNodeResult} object which will hold result value. * @return {@link NormalizedNodeStreamWriter} which will write item to supplied result holder. */ - public static final NormalizedNodeStreamWriter from(final NormalizedNodeResult result) { - return new ImmutableNormalizedNodeStreamWriter(new NormalizedNodeResultBuilder(result)); + public static @NonNull NormalizedNodeStreamWriter from(final NormalizedNodeResult result) { + return result instanceof NormalizedNodeMetadataResult ? from((NormalizedNodeMetadataResult) result) + : new ImmutableNormalizedNodeStreamWriter(result); } - - @SuppressWarnings("rawtypes") - private NormalizedNodeContainerBuilder getCurrent() { - return builders.peek(); + /** + * Creates a {@link NormalizedNodeStreamWriter} which creates one instance of top-level {@link NormalizedNode} + * (type of NormalizedNode) is determined by first start event. + * + *

+ * Result is built when {@link #endNode()} associated with that start event is emitted. + * + *

+ * Writer properly creates also nested {@link NormalizedNode} instances, if their are supported inside the scope + * of the first event. + * + *

+ * This method is useful for clients, which knows there will be one top-level node written, but does not know which + * type of {@link NormalizedNode} will be written. + * + * @param result {@link NormalizedNodeResult} object which will hold result value. + * @return {@link NormalizedNodeStreamWriter} which will write item to supplied result holder. + */ + public static @NonNull NormalizedNodeStreamWriter from(final NormalizedNodeMetadataResult result) { + return new ImmutableMetadataNormalizedNodeStreamWriter(result); } - @SuppressWarnings("rawtypes") - private void enter(final NormalizedNodeContainerBuilder next) { - builders.push(next); + @Override + public void startLeafNode(final NodeIdentifier name) { + checkDataNodeContainer(); + enter(name, leafNodeBuilder(nextSchema)); + nextSchema = null; } - @SuppressWarnings("unchecked") - private void writeChild(final NormalizedNode child) { - getCurrent().addChild(child); + @Override + public void startLeafSet(final NodeIdentifier name, final int childSizeHint) { + checkDataNodeContainer(); + enter(name, UNKNOWN_SIZE == childSizeHint ? InterningLeafSetNodeBuilder.create(nextSchema) + : InterningLeafSetNodeBuilder.create(nextSchema, childSizeHint)); } @Override - @SuppressWarnings({"rawtypes","unchecked"}) - public void endNode() { - final NormalizedNodeContainerBuilder finishedBuilder = builders.poll(); - Preconditions.checkState(finishedBuilder != null, "Node which should be closed does not exists."); - NormalizedNodeContainerBuilder current = getCurrent(); - Preconditions.checkState(current != null, "Reached top level node, which could not be closed in this writer."); - NormalizedNode product = finishedBuilder.build(); - current.addChild(product); + public void startLeafSetEntryNode(final NodeWithValue name) { + final NormalizedNodeBuilder current = current(); + checkArgument(current instanceof ImmutableLeafSetNodeBuilder + || current instanceof ImmutableOrderedLeafSetNodeBuilder || current instanceof NormalizedNodeResultBuilder, + "LeafSetEntryNode is not valid for parent %s", current); + enter(name, leafsetEntryNodeBuilder()); + nextSchema = null; } @Override - public void leafNode(final NodeIdentifier name, final Object value) throws IllegalArgumentException { + public void startOrderedLeafSet(final NodeIdentifier name, final int childSizeHint) { checkDataNodeContainer(); - writeChild(ImmutableNodes.leafNode(name, value)); + enter(name, Builders.orderedLeafSetBuilder()); } @Override - public void startLeafSet(final NodeIdentifier name, final int childSizeHint) throws IllegalArgumentException { + public boolean startAnyxmlNode(final NodeIdentifier name, final Class objectModel) { checkDataNodeContainer(); - ListNodeBuilder> builder = UNKNOWN_SIZE == childSizeHint ? - ImmutableLeafSetNodeBuilder.create() : ImmutableLeafSetNodeBuilder.create(childSizeHint); - builder.withNodeIdentifier(name); - enter(builder); + if (DOMSource.class.isAssignableFrom(objectModel)) { + enter(name, ImmutableAnyXmlNodeBuilder.create()); + nextSchema = null; + return true; + } + return false; } @Override - public void leafSetEntryNode(final Object value) throws IllegalArgumentException { - Preconditions.checkArgument(getCurrent() instanceof ImmutableLeafSetNodeBuilder); - @SuppressWarnings("unchecked") - ListNodeBuilder> builder = ((ImmutableLeafSetNodeBuilder) getCurrent()); - builder.withChildValue(value); + public void startContainerNode(final NodeIdentifier name, final int childSizeHint) { + checkDataNodeContainer(); + enter(name, UNKNOWN_SIZE == childSizeHint ? ImmutableContainerNodeBuilder.create() + : ImmutableContainerNodeBuilder.create(childSizeHint)); } @Override - public void anyxmlNode(final NodeIdentifier name, final Object value) throws IllegalArgumentException { + public void startYangModeledAnyXmlNode(final NodeIdentifier name, final int childSizeHint) { checkDataNodeContainer(); + + checkArgument(nextSchema instanceof YangModeledAnyxmlSchemaNode, + "Schema of this node should be instance of YangModeledAnyxmlSchemaNode"); + final YangModeledAnyxmlSchemaNode anyxmlSchema = (YangModeledAnyxmlSchemaNode) nextSchema; + enter(name, UNKNOWN_SIZE == childSizeHint ? ImmutableYangModeledAnyXmlNodeBuilder.create(anyxmlSchema) + : ImmutableYangModeledAnyXmlNodeBuilder.create(anyxmlSchema, childSizeHint)); } @Override - public void startContainerNode(final NodeIdentifier name, final int childSizeHint) throws IllegalArgumentException { + public void startUnkeyedList(final NodeIdentifier name, final int childSizeHint) { checkDataNodeContainer(); + enter(name, UNKNOWN_SIZE == childSizeHint ? ImmutableUnkeyedListNodeBuilder.create() + : ImmutableUnkeyedListNodeBuilder.create(childSizeHint)); + } - final DataContainerNodeAttrBuilder builder = UNKNOWN_SIZE == childSizeHint ? - ImmutableContainerNodeBuilder.create() : ImmutableContainerNodeBuilder.create(childSizeHint); - enter(builder.withNodeIdentifier(name)); + @Override + public void startUnkeyedListItem(final NodeIdentifier name, final int childSizeHint) { + final NormalizedNodeBuilder current = current(); + checkArgument(current instanceof ImmutableUnkeyedListNodeBuilder + || current instanceof NormalizedNodeResultBuilder); + enter(name, UNKNOWN_SIZE == childSizeHint ? ImmutableUnkeyedListEntryNodeBuilder.create() + : ImmutableUnkeyedListEntryNodeBuilder.create(childSizeHint)); } @Override - public void startUnkeyedList(final NodeIdentifier name, final int childSizeHint) throws IllegalArgumentException { + public void startMapNode(final NodeIdentifier name, final int childSizeHint) { checkDataNodeContainer(); + enter(name, UNKNOWN_SIZE == childSizeHint ? ImmutableMapNodeBuilder.create() + : ImmutableMapNodeBuilder.create(childSizeHint)); + } - final CollectionNodeBuilder builder = UNKNOWN_SIZE == childSizeHint ? - ImmutableUnkeyedListNodeBuilder.create() : ImmutableUnkeyedListNodeBuilder.create(childSizeHint); - enter(builder.withNodeIdentifier(name)); + @Override + public void startMapEntryNode(final NodeIdentifierWithPredicates identifier, final int childSizeHint) { + final NormalizedNodeBuilder current = current(); + checkArgument(current instanceof ImmutableMapNodeBuilder || current instanceof ImmutableOrderedMapNodeBuilder + || current instanceof NormalizedNodeResultBuilder); + + enter(identifier, UNKNOWN_SIZE == childSizeHint ? ImmutableMapEntryNodeBuilder.create() + : ImmutableMapEntryNodeBuilder.create(childSizeHint)); } @Override - public void startUnkeyedListItem(final NodeIdentifier name, final int childSizeHint) throws IllegalStateException { - Preconditions.checkArgument(getCurrent() instanceof ImmutableUnkeyedListNodeBuilder); + public void startOrderedMapNode(final NodeIdentifier name, final int childSizeHint) { + checkDataNodeContainer(); + enter(name, UNKNOWN_SIZE == childSizeHint ? ImmutableOrderedMapNodeBuilder.create() + : ImmutableOrderedMapNodeBuilder.create(childSizeHint)); + } - final DataContainerNodeAttrBuilder builder = UNKNOWN_SIZE == childSizeHint ? - ImmutableUnkeyedListEntryNodeBuilder.create() : ImmutableUnkeyedListEntryNodeBuilder.create(childSizeHint); - enter(builder.withNodeIdentifier(name)); + @Override + public void startChoiceNode(final NodeIdentifier name, final int childSizeHint) { + checkDataNodeContainer(); + enter(name, UNKNOWN_SIZE == childSizeHint ? ImmutableChoiceNodeBuilder.create() + : ImmutableChoiceNodeBuilder.create(childSizeHint)); } @Override - public void startMapNode(final NodeIdentifier name, final int childSizeHint) throws IllegalArgumentException { + public void startAugmentationNode(final AugmentationIdentifier identifier) { checkDataNodeContainer(); + checkArgument(!(current() instanceof ImmutableAugmentationNodeBuilder)); + enter(identifier, Builders.augmentationBuilder()); + } - final CollectionNodeBuilder builder = UNKNOWN_SIZE == childSizeHint ? - ImmutableMapNodeBuilder.create() : ImmutableMapNodeBuilder.create(childSizeHint); - enter(builder.withNodeIdentifier(name)); + @Override + public void flush() { + // no-op } @Override - public void startMapEntryNode(final NodeIdentifierWithPredicates identifier, final int childSizeHint) throws IllegalArgumentException { - if(!(getCurrent() instanceof NormalizedNodeResultBuilder)) { - Preconditions.checkArgument(getCurrent() instanceof ImmutableMapNodeBuilder || getCurrent() instanceof ImmutableOrderedMapNodeBuilder); - } + public void close() { + // no-op + } - final DataContainerNodeAttrBuilder builder = UNKNOWN_SIZE == childSizeHint ? - ImmutableMapEntryNodeBuilder.create() : ImmutableMapEntryNodeBuilder.create(childSizeHint); - enter(builder.withNodeIdentifier(identifier)); + @Override + public void nextDataSchemaNode(final DataSchemaNode schema) { + nextSchema = requireNonNull(schema); } @Override - public void startOrderedMapNode(final NodeIdentifier name, final int childSizeHint) throws IllegalArgumentException { - checkDataNodeContainer(); + public void scalarValue(final Object value) { + currentScalar().withValue(value); + } - final CollectionNodeBuilder builder = UNKNOWN_SIZE == childSizeHint ? - ImmutableOrderedMapNodeBuilder.create() : ImmutableOrderedMapNodeBuilder.create(childSizeHint); - enter(builder.withNodeIdentifier(name)); + @Override + public void domSourceValue(final DOMSource value) { + currentScalar().withValue(value); } @Override - public void startChoiceNode(final NodeIdentifier name, final int childSizeHint) throws IllegalArgumentException { - checkDataNodeContainer(); + @SuppressWarnings({ "rawtypes", "unchecked" }) + public void endNode() { + final NormalizedNodeBuilder finishedBuilder = builders.poll(); + checkState(finishedBuilder != null, "Node which should be closed does not exists."); + final NormalizedNode product = finishedBuilder.build(); + nextSchema = null; - final DataContainerNodeBuilder builder = UNKNOWN_SIZE == childSizeHint ? - ImmutableChoiceNodeBuilder.create() : ImmutableChoiceNodeBuilder.create(childSizeHint); - enter(builder.withNodeIdentifier(name)); + writeChild(product); } @Override - public void startAugmentationNode(final AugmentationIdentifier identifier) throws IllegalArgumentException { + public boolean startAnydataNode(final NodeIdentifier name, final Class objectModel) throws IOException { checkDataNodeContainer(); - Preconditions.checkArgument(!(getCurrent() instanceof ImmutableAugmentationNodeBuilder)); - enter(Builders.augmentationBuilder().withNodeIdentifier(identifier)); + enter(name, ImmutableAnydataNodeBuilder.create(objectModel)); + // We support all object models + return true; } - private void checkDataNodeContainer() { - @SuppressWarnings("rawtypes") - NormalizedNodeContainerBuilder current = getCurrent(); - if(!(current instanceof NormalizedNodeResultBuilder)) { - Preconditions.checkArgument(current instanceof DataContainerNodeBuilder, "Invalid nesting of data."); - } + /** + * Add a child not to the currently-open builder. + * + * @param child A new child + * @throws NullPointerException if {@code child} is null + * @throws IllegalStateException if there is no open builder + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + protected final void writeChild(final NormalizedNode child) { + final NormalizedNodeContainerBuilder current = currentContainer(); + checkState(current != null, "Reached top level node, which could not be closed in this writer."); + current.addChild(requireNonNull(child)); } + // Exposed for ImmutableMetadataNormalizedNodeStreamWriter @SuppressWarnings("rawtypes") - private static final class NormalizedNodeResultBuilder implements NormalizedNodeContainerBuilder { - - private final NormalizedNodeResult result; - - public NormalizedNodeResultBuilder(final NormalizedNodeResult result) { - this.result = result; - } + void enter(final PathArgument identifier, final NormalizedNodeBuilder next) { + builders.push(next.withNodeIdentifier(identifier)); + nextSchema = null; + } - @Override - public NormalizedNodeBuilder withValue(final Object value) { - throw new UnsupportedOperationException(); - } + // Exposed for ImmutableMetadataNormalizedNodeStreamWriter + protected final NormalizedNodeBuilder popBuilder() { + return builders.pop(); + } - @Override - public NormalizedNode build() { - throw new IllegalStateException("Can not close NormalizedNodeResult"); - } + final void reset(final NormalizedNodeResultBuilder builder) { + nextSchema = null; + builders.clear(); + builders.push(builder); + } - @Override - public NormalizedNodeContainerBuilder withNodeIdentifier(final PathArgument nodeIdentifier) { - throw new UnsupportedOperationException(); - } + private ImmutableLeafNodeBuilder leafNodeBuilder(final DataSchemaNode schema) { + final InterningLeafNodeBuilder interning = InterningLeafNodeBuilder.forSchema(schema); + return interning != null ? interning : leafNodeBuilder(); + } - @Override - public NormalizedNodeContainerBuilder withValue(final List value) { - throw new UnsupportedOperationException(); - } + ImmutableLeafNodeBuilder leafNodeBuilder() { + return new ImmutableLeafNodeBuilder<>(); + } - @Override - public NormalizedNodeContainerBuilder addChild(final NormalizedNode child) { - result.setResult(child); - return this; - } + ImmutableLeafSetEntryNodeBuilder leafsetEntryNodeBuilder() { + return ImmutableLeafSetEntryNodeBuilder.create(); + } - @Override - public NormalizedNodeContainerBuilder removeChild(final PathArgument key) { - throw new UnsupportedOperationException(); + private void checkDataNodeContainer() { + @SuppressWarnings("rawtypes") + final NormalizedNodeContainerBuilder current = currentContainer(); + if (!(current instanceof NormalizedNodeResultBuilder)) { + checkArgument(current instanceof DataContainerNodeBuilder, "Invalid nesting of data."); } - } - @Override - public void flush() { - // no-op + @SuppressWarnings("rawtypes") + private NormalizedNodeBuilder current() { + return builders.peek(); } - @Override - public void close() throws IOException { - // TODO Auto-generated method stub - + @SuppressWarnings("rawtypes") + private NormalizedNodeContainerBuilder currentContainer() { + final NormalizedNodeBuilder current = current(); + if (current == null) { + return null; + } + checkState(current instanceof NormalizedNodeContainerBuilder, "%s is not a node container", current); + return (NormalizedNodeContainerBuilder) current; } + @SuppressWarnings("rawtypes") + private NormalizedNodeBuilder currentScalar() { + final NormalizedNodeBuilder current = current(); + checkState(!(current instanceof NormalizedNodeContainerBuilder), "Unexpected node container %s", current); + return current; + } }