use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project netconf by opendaylight.
the class DefinitionGenerator method processChildren.
/**
* Processes the nodes.
*/
private ObjectNode processChildren(final ObjectNode parentNode, final Collection<? extends DataSchemaNode> nodes, final String parentName, final ObjectNode definitions, final DefinitionNames definitionNames, final boolean isConfig, final SchemaInferenceStack stack, final OAversion oaversion) throws IOException {
final ObjectNode properties = JsonNodeFactory.instance.objectNode();
final ArrayNode required = JsonNodeFactory.instance.arrayNode();
for (final DataSchemaNode node : nodes) {
stack.enterSchemaTree(node.getQName());
if (!isConfig || node.isConfiguration()) {
/*
Add module name prefix to property name, when needed, when ServiceNow can process colons,
use RestDocGenUtil#resolveNodesName for creating property name
*/
final String propertyName = node.getQName().getLocalName();
final ObjectNode property;
if (node instanceof LeafSchemaNode) {
processLeafNode((LeafSchemaNode) node, propertyName, properties, required, stack, definitions, definitionNames, oaversion);
} else if (node instanceof AnyxmlSchemaNode) {
processAnyXMLNode((AnyxmlSchemaNode) node, propertyName, properties, required);
} else if (node instanceof AnydataSchemaNode) {
processAnydataNode((AnydataSchemaNode) node, propertyName, properties, required);
} else {
if (node instanceof ListSchemaNode || node instanceof ContainerSchemaNode) {
property = processDataNodeContainer((DataNodeContainer) node, parentName, definitions, definitionNames, isConfig, stack, oaversion);
if (!isConfig) {
processActionNodeContainer(node, parentName, definitions, definitionNames, stack, oaversion);
}
} else if (node instanceof LeafListSchemaNode) {
property = processLeafListNode((LeafListSchemaNode) node, stack, definitions, definitionNames, oaversion);
} else if (node instanceof ChoiceSchemaNode) {
for (final CaseSchemaNode variant : ((ChoiceSchemaNode) node).getCases()) {
stack.enterSchemaTree(variant.getQName());
processChoiceNode(variant.getChildNodes(), parentName, definitions, definitionNames, isConfig, stack, properties, oaversion);
stack.exit();
}
stack.exit();
// FIXME dangerous statement here! Try to rework without continue.
continue;
} else {
throw new IllegalArgumentException("Unknown DataSchemaNode type: " + node.getClass());
}
properties.set(propertyName, property);
}
}
stack.exit();
}
parentNode.set(PROPERTIES_KEY, properties);
setRequiredIfNotEmpty(parentNode, required);
return properties;
}
use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project netconf by opendaylight.
the class DefinitionGenerator method processChoiceNode.
private void processChoiceNode(final Iterable<? extends DataSchemaNode> nodes, final String parentName, final ObjectNode definitions, final DefinitionNames definitionNames, final boolean isConfig, final SchemaInferenceStack stack, final ObjectNode properties, final OAversion oaversion) throws IOException {
for (final DataSchemaNode node : nodes) {
stack.enterSchemaTree(node.getQName());
/*
Add module name prefix to property name, when needed, when ServiceNow can process colons,
use RestDocGenUtil#resolveNodesName for creating property name
*/
final String name = node.getQName().getLocalName();
final ObjectNode property;
/*
Ignore mandatoriness(passing unreferenced arrayNode to process...Node), because choice produces multiple
properties
*/
if (node instanceof LeafSchemaNode) {
processLeafNode((LeafSchemaNode) node, name, properties, JsonNodeFactory.instance.arrayNode(), stack, definitions, definitionNames, oaversion);
} else if (node instanceof AnyxmlSchemaNode) {
processAnyXMLNode((AnyxmlSchemaNode) node, name, properties, JsonNodeFactory.instance.arrayNode());
} else if (node instanceof AnydataSchemaNode) {
processAnydataNode((AnydataSchemaNode) node, name, properties, JsonNodeFactory.instance.arrayNode());
} else {
if (node instanceof ListSchemaNode || node instanceof ContainerSchemaNode) {
property = processDataNodeContainer((DataNodeContainer) node, parentName, definitions, definitionNames, isConfig, stack, oaversion);
if (!isConfig) {
processActionNodeContainer(node, parentName, definitions, definitionNames, stack, oaversion);
}
} else if (node instanceof LeafListSchemaNode) {
property = processLeafListNode((LeafListSchemaNode) node, stack, definitions, definitionNames, oaversion);
} else if (node instanceof ChoiceSchemaNode) {
for (final CaseSchemaNode variant : ((ChoiceSchemaNode) node).getCases()) {
processChoiceNode(variant.getChildNodes(), parentName, definitions, definitionNames, isConfig, stack, properties, oaversion);
}
continue;
} else {
throw new IllegalArgumentException("Unknown DataSchemaNode type: " + node.getClass());
}
properties.set(name, property);
}
stack.exit();
}
}
use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project controller by opendaylight.
the class RuntimeRegistratorTest method prepareChildRB.
protected RuntimeBeanEntry prepareChildRB(final List<RuntimeBeanEntry> children, final String prefix) {
final DataNodeContainer nodeContainer = mock(DataNodeContainer.class);
doReturn("DataSchemaNode").when(nodeContainer).toString();
return new RuntimeBeanEntry("pa.cka.ge", nodeContainer, prefix + "child-name", capitalize(prefix) + "ChildName", false, Optional.absent(), Collections.emptyList(), children, Collections.emptySet());
}
use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project yangtools by opendaylight.
the class LeafRefUtils method schemaPathToXPathQNames.
private static Deque<QNameWithPredicate> schemaPathToXPathQNames(final SchemaPath nodePath, final Module module) {
final Deque<QNameWithPredicate> xpath = new LinkedList<>();
final Iterator<QName> nodePathIterator = nodePath.getPathFromRoot().iterator();
DataNodeContainer currenDataNodeContainer = module;
while (nodePathIterator.hasNext()) {
final QName qname = nodePathIterator.next();
final DataSchemaNode child = currenDataNodeContainer.dataChildByName(qname);
if (child instanceof DataNodeContainer) {
if (!(child instanceof CaseSchemaNode)) {
xpath.add(new SimpleQNameWithPredicate(qname));
}
currenDataNodeContainer = (DataNodeContainer) child;
} else if (child instanceof ChoiceSchemaNode) {
if (nodePathIterator.hasNext()) {
currenDataNodeContainer = ((ChoiceSchemaNode) child).findCase(nodePathIterator.next()).orElse(null);
} else {
break;
}
} else if (child instanceof LeafSchemaNode || child instanceof LeafListSchemaNode) {
xpath.add(new SimpleQNameWithPredicate(qname));
break;
} else if (child == null) {
throw new IllegalArgumentException("No child " + qname + " found in node container " + currenDataNodeContainer + " in module " + module.getName());
} else {
throw new IllegalStateException("Illegal schema node type in the path: " + child.getClass());
}
}
return xpath;
}
use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project yangtools by opendaylight.
the class AugmentTest method testAugmentInUsesResolving.
@Test
public void testAugmentInUsesResolving() throws Exception {
final EffectiveModelContext context = assertEffectiveModelDir("/augment-test/augment-in-uses");
assertEquals(1, context.getModules().size());
final Module test = context.getModules().iterator().next();
final DataNodeContainer links = (DataNodeContainer) test.getDataChildByName(QName.create(test.getQNameModule(), "links"));
final DataNodeContainer link = (DataNodeContainer) links.getDataChildByName(QName.create(test.getQNameModule(), "link"));
final DataNodeContainer nodes = (DataNodeContainer) link.getDataChildByName(QName.create(test.getQNameModule(), "nodes"));
final ContainerSchemaNode node = (ContainerSchemaNode) nodes.getDataChildByName(QName.create(test.getQNameModule(), "node"));
final Collection<? extends AugmentationSchemaNode> augments = node.getAvailableAugmentations();
assertEquals(1, augments.size());
assertEquals(1, node.getChildNodes().size());
final LeafSchemaNode id = (LeafSchemaNode) node.getDataChildByName(QName.create(test.getQNameModule(), "id"));
assertTrue(id.isAugmenting());
}
Aggregations