use of org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement in project yangtools by opendaylight.
the class SchemaInferenceStack method resolveChoiceSteps.
private void resolveChoiceSteps(@NonNull final ChoiceEffectiveStatement parent, @NonNull final QName nodeIdentifier) {
for (EffectiveStatement<?, ?> stmt : parent.effectiveSubstatements()) {
if (stmt instanceof CaseEffectiveStatement) {
final CaseEffectiveStatement caze = (CaseEffectiveStatement) stmt;
final SchemaTreeEffectiveStatement<?> found = caze.findSchemaTreeNode(nodeIdentifier).orElse(null);
if (found instanceof ChoiceEffectiveStatement) {
deque.push(caze);
deque.push(found);
return;
}
}
}
throw new VerifyException("Failed to resolve " + nodeIdentifier + " in " + parent);
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement in project yangtools by opendaylight.
the class SchemaInferenceStack method enterChoice.
/**
* Lookup a {@code choice} by its node identifier and push it to the stack. This step is very similar to
* {@link #enterSchemaTree(QName)}, except it handles the use case where traversal ignores actual {@code case}
* intermediate schema tree children.
*
* @param nodeIdentifier Node identifier of the choice to enter
* @return Resolved choice
* @throws NullPointerException if {@code nodeIdentifier} is null
* @throws IllegalArgumentException if the corresponding choice cannot be found
*/
@NonNull
public ChoiceEffectiveStatement enterChoice(final QName nodeIdentifier) {
final QName nodeId = requireNonNull(nodeIdentifier);
final EffectiveStatement<?, ?> parent = deque.peek();
if (parent instanceof ChoiceEffectiveStatement) {
return enterChoice((ChoiceEffectiveStatement) parent, nodeId);
}
// Fall back to schema tree lookup. Note if it results in non-choice, we rewind before reporting an error
final SchemaTreeEffectiveStatement<?> result = enterSchemaTree(nodeId);
if (result instanceof ChoiceEffectiveStatement) {
return (ChoiceEffectiveStatement) result;
}
exit();
if (parent != null) {
throw notPresent(parent, "Choice", nodeId);
}
throw new IllegalArgumentException("Choice " + nodeId + " not present");
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement in project yangtools by opendaylight.
the class NormalizedNodeStreamWriterStack method startChoiceNode.
public ChoiceSchemaNode startChoiceNode(final NodeIdentifier name) {
LOG.debug("Enter choice {}", name);
final ChoiceEffectiveStatement stmt = dataTree.enterChoice(name.getNodeType());
verify(stmt instanceof ChoiceSchemaNode, "Node %s is not a choice", stmt);
final ChoiceSchemaNode ret = (ChoiceSchemaNode) stmt;
schemaStack.push(ret);
return ret;
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement in project yangtools by opendaylight.
the class YT1208Test method testChoiceStatementReuse.
@Test
public void testChoiceStatementReuse() throws Exception {
final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/choice.yang").getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final NotificationEffectiveStatement notif = module.findFirstEffectiveSubstatement(NotificationEffectiveStatement.class).orElseThrow();
final ChoiceEffectiveStatement grpBar = notif.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(ChoiceEffectiveStatement.class).orElseThrow();
final ChoiceEffectiveStatement contBar = notif.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(ChoiceEffectiveStatement.class).orElseThrow();
assertSame(contBar, grpBar);
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement in project yangtools by opendaylight.
the class DeclaredStatementsTest method testDeclaredChoice.
@Test
public void testDeclaredChoice() throws ReactorException {
final StatementStreamSource choiceStmtModule = sourceForResource("/declared-statements-test/choice-declared-test.yang");
final SchemaContext schemaContext = StmtTestUtils.parseYangSources(choiceStmtModule);
assertNotNull(schemaContext);
final Module testModule = schemaContext.findModules("choice-declared-test").iterator().next();
assertNotNull(testModule);
final ChoiceSchemaNode choiceSchemaNode = (ChoiceSchemaNode) testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "test-choice"));
assertNotNull(choiceSchemaNode);
final ChoiceStatement choiceStatement = ((ChoiceEffectiveStatement) choiceSchemaNode).getDeclared();
final QName name = choiceStatement.argument();
assertNotNull(name);
final DefaultStatement defaultStatement = choiceStatement.getDefault().get();
assertEquals("case-two", defaultStatement.argument());
assertTrue(choiceStatement.getConfig().isPresent());
assertTrue(choiceStatement.getMandatory().isPresent());
final Collection<? extends CaseStatement> caseStatements = choiceStatement.getCases();
assertNotNull(caseStatements);
assertEquals(3, caseStatements.size());
final CaseStatement caseStatement = caseStatements.iterator().next();
final QName caseStatementName = caseStatement.argument();
assertNotNull(caseStatementName);
final WhenStatement caseStatementWhen = caseStatement.getWhenStatement().get();
final Collection<? extends IfFeatureStatement> caseStatementIfFeatures = caseStatement.getIfFeatures();
assertNotNull(caseStatementIfFeatures);
assertEquals(1, caseStatementIfFeatures.size());
final Collection<? extends DataDefinitionStatement> caseStatementDataDefinitions = caseStatement.getDataDefinitions();
assertNotNull(caseStatementDataDefinitions);
assertEquals(1, caseStatementDataDefinitions.size());
assertTrue(caseStatement.getStatus().isPresent());
assertTrue(caseStatement.getDescription().isPresent());
assertTrue(caseStatement.getReference().isPresent());
final WhenStatement whenStatement = choiceStatement.getWhenStatement().get();
final Collection<? extends IfFeatureStatement> ifFeatureStatements = choiceStatement.getIfFeatures();
assertNotNull(ifFeatureStatements);
assertEquals(1, ifFeatureStatements.size());
assertTrue(choiceStatement.getStatus().isPresent());
assertTrue(choiceStatement.getDescription().isPresent());
assertTrue(choiceStatement.getReference().isPresent());
}
Aggregations