import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.SchemaUtils;
-import org.opendaylight.yangtools.yang.data.impl.schema.transform.base.AugmentationSchemaProxy;
import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.util.EffectiveAugmentationSchema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
child = tryFindNotification((SchemaContext) current, qname)
.or(tryFindRpc(((SchemaContext) current), qname)).orNull();
}
- } else if (current instanceof ChoiceNode) {
- child = ((ChoiceNode) current).getCaseNodeByName(qname);
+ } else if (current instanceof ChoiceSchemaNode) {
+ child = ((ChoiceSchemaNode) current).getCaseNodeByName(qname);
} else if (current instanceof RpcDefinition) {
switch (qname.getLocalName()) {
case "input":
if(schema == null && parent instanceof NotificationDefinition) {
schema = ((NotificationDefinition) parent);
}
- } else if(parent instanceof ChoiceNode) {
- for(final ChoiceCaseNode caze : ((ChoiceNode) parent).getCases()) {
- final DataSchemaNode potential = caze.getDataChildByName(qname);
- if(potential != null) {
- schema = potential;
- break;
- }
- }
+ } else if(parent instanceof ChoiceSchemaNode) {
+ schema = findChildInCases((ChoiceSchemaNode) parent, qname);
} else {
throw new IllegalStateException("Unsupported schema type "+ parent.getClass() +" on stack.");
}
return schema;
}
+ private SchemaNode findChildInCases(final ChoiceSchemaNode parent, final QName qname) {
+ DataSchemaNode schema = null;
+ for(final ChoiceCaseNode caze : parent.getCases()) {
+ final DataSchemaNode potential = caze.getDataChildByName(qname);
+ if(potential != null) {
+ schema = potential;
+ break;
+ }
+ }
+ return schema;
+ }
+
+ private SchemaNode findCaseByChild(final ChoiceSchemaNode parent, final QName qname) {
+ DataSchemaNode schema = null;
+ for(final ChoiceCaseNode caze : parent.getCases()) {
+ final DataSchemaNode potential = caze.getDataChildByName(qname);
+ if(potential != null) {
+ schema = caze;
+ break;
+ }
+ }
+ return schema;
+ }
+
public void startList(final PathArgument name) {
final SchemaNode schema = getSchema(name);
Preconditions.checkArgument(schema instanceof ListSchemaNode, "Node %s is not a list", schema.getPath());
return (LeafListSchemaNode) parent;
}
- public ChoiceNode startChoiceNode(final NodeIdentifier name) {
+ public ChoiceSchemaNode 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());
+ Preconditions.checkArgument(schema instanceof ChoiceSchemaNode, "Node %s is not a choice", schema.getPath());
schemaStack.push(schema);
- return (ChoiceNode)schema;
+ return (ChoiceSchemaNode)schema;
}
public SchemaNode startContainerNode(final NodeIdentifier name) {
public AugmentationSchema startAugmentationNode(final AugmentationIdentifier identifier) {
LOG.debug("Enter augmentation {}", identifier);
- final Object parent = getParent();
+ Object parent = getParent();
Preconditions.checkArgument(parent instanceof AugmentationTarget, "Augmentation not allowed under %s", parent);
+ if(parent instanceof ChoiceSchemaNode) {
+ final QName name = Iterables.get(identifier.getPossibleChildNames(), 0);
+ parent = findCaseByChild((ChoiceSchemaNode) parent, name);
+ }
Preconditions.checkArgument(parent instanceof DataNodeContainer, "Augmentation allowed only in DataNodeContainer",parent);
final AugmentationSchema schema = SchemaUtils.findSchemaForAugment((AugmentationTarget) parent, identifier.getPossibleChildNames());
final HashSet<DataSchemaNode> realChildSchemas = new HashSet<>();
for(final DataSchemaNode child : schema.getChildNodes()) {
realChildSchemas.add(((DataNodeContainer) parent).getDataChildByName(child.getQName()));
}
- final AugmentationSchema resolvedSchema = new AugmentationSchemaProxy(schema, realChildSchemas);
+ final AugmentationSchema resolvedSchema = new EffectiveAugmentationSchema(schema, realChildSchemas);
schemaStack.push(resolvedSchema);
return resolvedSchema;
}