import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
+
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashSet;
+
import javax.xml.stream.XMLStreamWriter;
+
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
private final DataNodeContainer root;
private SchemaTracker(final SchemaContext context, final SchemaPath path) {
- DataNodeContainer current = Preconditions.checkNotNull(context);
+ DataSchemaNode current = Preconditions.checkNotNull(context);
for (QName qname : path.getPathFromRoot()) {
- final DataSchemaNode child = current.getDataChildByName(qname);
- Preconditions.checkArgument(child instanceof DataNodeContainer);
- current = (DataNodeContainer) child;
+ final DataSchemaNode child;
+ if(current instanceof DataNodeContainer) {
+ child = ((DataNodeContainer) current).getDataChildByName(qname);
+ } else if (current instanceof ChoiceNode) {
+ child = ((ChoiceNode) current).getCaseNodeByName(qname);
+ } else {
+ throw new IllegalArgumentException(String.format("Schema node %s does not allow children.",current));
+ }
+ current = child;
}
-
- this.root = current;
+ Preconditions.checkArgument(current instanceof DataNodeContainer,"Schema path must point to container or list. Supplied path %s pointed to: %s",path,current);
+ this.root = (DataNodeContainer) current;
}
/**
return schema;
}
- public void startList(final NodeIdentifier name) {
+ public void startList(final PathArgument name) {
final SchemaNode schema = getSchema(name);
Preconditions.checkArgument(schema instanceof ListSchemaNode, "Node %s is not a list", schema.getPath());
schemaStack.push(schema);
return (LeafSchemaNode) schema;
}
- public SchemaNode startLeafSet(final NodeIdentifier name) {
+ public LeafListSchemaNode startLeafSet(final NodeIdentifier name) {
final SchemaNode schema = getSchema(name);
Preconditions.checkArgument(schema instanceof LeafListSchemaNode, "Node %s is not a leaf-list", schema.getPath());
schemaStack.push(schema);
- return schema;
+ return (LeafListSchemaNode)schema;
}
public LeafListSchemaNode leafSetEntryNode() {
return (LeafListSchemaNode) parent;
}
- public SchemaNode startChoiceNode(final NodeIdentifier name) {
+ public ChoiceNode startChoiceNode(final NodeIdentifier name) {
LOG.debug("Enter choice {}", name);
final SchemaNode schema = getSchema(name);
Preconditions.checkArgument(schema instanceof ChoiceNode, "Node %s is not a choice", schema.getPath());
schemaStack.push(schema);
- return schema;
+ return (ChoiceNode)schema;
}
- public SchemaNode startContainerNode(final NodeIdentifier name) {
+ public ContainerSchemaNode startContainerNode(final NodeIdentifier name) {
LOG.debug("Enter container {}", name);
final SchemaNode schema = getSchema(name);
Preconditions.checkArgument(schema instanceof ContainerSchemaNode, "Node %s is not a container", schema.getPath());
schemaStack.push(schema);
- return schema;
+ return (ContainerSchemaNode)schema;
}
public AugmentationSchema startAugmentationNode(final AugmentationIdentifier identifier) {