Search in sources :

Example 16 with DataNodeContainer

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) CaseSchemaNode(org.opendaylight.yangtools.yang.model.api.CaseSchemaNode) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AnydataSchemaNode(org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)

Example 17 with DataNodeContainer

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();
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) CaseSchemaNode(org.opendaylight.yangtools.yang.model.api.CaseSchemaNode) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) AnydataSchemaNode(org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)

Example 18 with DataNodeContainer

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());
}
Also used : DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer)

Example 19 with DataNodeContainer

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;
}
Also used : LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) LinkedList(java.util.LinkedList) CaseSchemaNode(org.opendaylight.yangtools.yang.model.api.CaseSchemaNode) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)

Example 20 with DataNodeContainer

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());
}
Also used : ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Aggregations

DataNodeContainer (org.opendaylight.yangtools.yang.model.api.DataNodeContainer)41 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)34 QName (org.opendaylight.yangtools.yang.common.QName)15 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)14 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)12 ChoiceSchemaNode (org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)12 CaseSchemaNode (org.opendaylight.yangtools.yang.model.api.CaseSchemaNode)11 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)10 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)9 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)9 ArrayList (java.util.ArrayList)7 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)7 RestConfModule (org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 Test (org.junit.Test)5 AugmentationSchemaNode (org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode)5 Module (org.opendaylight.yangtools.yang.model.api.Module)5 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ArrayDeque (java.util.ArrayDeque)3