Search in sources :

Example 1 with DataNodeContainer

use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project controller by opendaylight.

the class RuntimeRegistratorTest method prepareRootRB.

// TODO add more tests
protected RuntimeBeanEntry prepareRootRB(final List<RuntimeBeanEntry> children) {
    final DataNodeContainer nodeContainer = mock(DataNodeContainer.class);
    doReturn("DataSchemaNode").when(nodeContainer).toString();
    return new RuntimeBeanEntry("pa.cka.ge", nodeContainer, "module-name", "ModuleName", true, Optional.absent(), Collections.emptyList(), children, Collections.emptySet());
}
Also used : DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer)

Example 2 with DataNodeContainer

use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project yangtools by opendaylight.

the class InMemoryDataTree method internalSetSchemaContext.

/*
     * This method is synchronized to guard against user attempting to install
     * multiple contexts. Otherwise it runs in a lock-free manner.
     */
private synchronized void internalSetSchemaContext(final EffectiveModelContext newSchemaContext) {
    requireNonNull(newSchemaContext);
    LOG.debug("Following schema contexts will be attempted {}", newSchemaContext);
    final DataSchemaContextTree contextTree = DataSchemaContextTree.from(newSchemaContext);
    final Optional<DataSchemaContextNode<?>> rootContextNode = contextTree.findChild(getRootPath());
    if (!rootContextNode.isPresent()) {
        LOG.warn("Could not find root {} in new schema context, not upgrading", getRootPath());
        return;
    }
    final DataSchemaNode rootSchemaNode = rootContextNode.get().getDataSchemaNode();
    if (!(rootSchemaNode instanceof DataNodeContainer)) {
        LOG.warn("Root {} resolves to non-container type {}, not upgrading", getRootPath(), rootSchemaNode);
        return;
    }
    final ModificationApplyOperation rootNode = getOperation(rootSchemaNode);
    DataTreeState currentState;
    DataTreeState newState;
    do {
        currentState = currentState();
        newState = currentState.withSchemaContext(newSchemaContext, rootNode);
    // TODO: can we lower this to compareAndSwapRelease?
    } while (!STATE.compareAndSet(this, currentState, newState));
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) DataSchemaContextNode(org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) DataSchemaContextTree(org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree)

Example 3 with DataNodeContainer

use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project yangtools by opendaylight.

the class UniqueValidation method toDescendantPath.

private static ImmutableList<NodeIdentifier> toDescendantPath(final ListSchemaNode parent, final Descendant descendant) {
    final List<QName> qnames = descendant.getNodeIdentifiers();
    final ImmutableList.Builder<NodeIdentifier> builder = ImmutableList.builderWithExpectedSize(qnames.size());
    final Iterator<QName> it = descendant.getNodeIdentifiers().iterator();
    DataNodeContainer current = parent;
    while (true) {
        final QName qname = it.next();
        final DataSchemaNode next = current.findDataChildByName(qname).orElseThrow(() -> new IllegalStateException("Cannot find component " + qname + " of " + descendant));
        builder.add(NodeIdentifier.create(qname));
        if (!it.hasNext()) {
            checkState(next instanceof TypedDataSchemaNode, "Unexpected schema %s for %s", next, descendant);
            final ImmutableList<NodeIdentifier> ret = builder.build();
            LOG.trace("Resolved {} to {}", descendant, ret);
            return ret;
        }
        checkState(next instanceof DataNodeContainer, "Unexpected non-container %s for %s", next, descendant);
        current = (DataNodeContainer) next;
    }
}
Also used : TypedDataSchemaNode(org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode) TypedDataSchemaNode(org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) ImmutableList(com.google.common.collect.ImmutableList) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer)

Example 4 with DataNodeContainer

use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project yangtools by opendaylight.

the class LeafRefContextTreeBuilder method buildLeafRefContextReferencingTree.

private LeafRefContext buildLeafRefContextReferencingTree(final DataSchemaNode node, final SchemaInferenceStack stack) {
    final LeafRefContextBuilder currentLeafRefContextBuilder = new LeafRefContextBuilder(node.getQName(), stack.toSchemaPath(), schemaContext);
    if (node instanceof DataNodeContainer) {
        for (final DataSchemaNode childNode : ((DataNodeContainer) node).getChildNodes()) {
            stack.enterSchemaTree(childNode.getQName());
            final LeafRefContext childLeafRefContext = buildLeafRefContextReferencingTree(childNode, stack);
            stack.exit();
            if (childLeafRefContext.hasReferencingChild() || childLeafRefContext.isReferencing()) {
                currentLeafRefContextBuilder.addReferencingChild(childLeafRefContext, childLeafRefContext.getNodeName());
            }
        }
    } else if (node instanceof ChoiceSchemaNode) {
        // :FIXME choice without case
        for (final CaseSchemaNode caseNode : ((ChoiceSchemaNode) node).getCases()) {
            stack.enterSchemaTree(caseNode.getQName());
            final LeafRefContext childLeafRefContext = buildLeafRefContextReferencingTree(caseNode, stack);
            stack.exit();
            if (childLeafRefContext.hasReferencingChild() || childLeafRefContext.isReferencing()) {
                currentLeafRefContextBuilder.addReferencingChild(childLeafRefContext, childLeafRefContext.getNodeName());
            }
        }
    } else if (node instanceof TypedDataSchemaNode) {
        final TypedDataSchemaNode typedNode = (TypedDataSchemaNode) node;
        final TypeDefinition<?> type = typedNode.getType();
        // FIXME: fix case when type is e.g. typedef -> typedef -> leafref
        if (type instanceof LeafrefTypeDefinition) {
            final LeafrefTypeDefinition leafrefType = (LeafrefTypeDefinition) type;
            final PathExpression path = leafrefType.getPathStatement();
            final LeafRefPathParserImpl leafRefPathParser = new LeafRefPathParserImpl(leafrefType, typedNode);
            final LeafRefPath leafRefPath = leafRefPathParser.parseLeafRefPath(path);
            currentLeafRefContextBuilder.setLeafRefTargetPathString(path.getOriginalString());
            currentLeafRefContextBuilder.setReferencing(true);
            currentLeafRefContextBuilder.setLeafRefTargetPath(leafRefPath);
            final LeafRefContext currentLeafRefContext = currentLeafRefContextBuilder.build();
            leafRefs.add(currentLeafRefContext);
            return currentLeafRefContext;
        }
    }
    return currentLeafRefContextBuilder.build();
}
Also used : TypedDataSchemaNode(org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode) LeafrefTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition) PathExpression(org.opendaylight.yangtools.yang.model.api.PathExpression) TypedDataSchemaNode(org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) 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 5 with DataNodeContainer

use of org.opendaylight.yangtools.yang.model.api.DataNodeContainer in project yangtools by opendaylight.

the class LeafRefContextTreeBuilder method buildLeafRefContextReferencedByTree.

private LeafRefContext buildLeafRefContextReferencedByTree(final DataSchemaNode node, final Module currentModule, final SchemaInferenceStack stack) {
    final LeafRefContextBuilder currentLeafRefContextBuilder = new LeafRefContextBuilder(node.getQName(), stack.toSchemaPath(), schemaContext);
    if (node instanceof DataNodeContainer) {
        for (final DataSchemaNode childNode : ((DataNodeContainer) node).getChildNodes()) {
            stack.enterSchemaTree(childNode.getQName());
            final LeafRefContext childLeafRefContext = buildLeafRefContextReferencedByTree(childNode, currentModule, stack);
            stack.exit();
            if (childLeafRefContext.hasReferencedChild() || childLeafRefContext.isReferenced()) {
                currentLeafRefContextBuilder.addReferencedByChild(childLeafRefContext, childLeafRefContext.getNodeName());
            }
        }
    } else if (node instanceof ChoiceSchemaNode) {
        for (final CaseSchemaNode caseNode : ((ChoiceSchemaNode) node).getCases()) {
            stack.enterSchemaTree(caseNode.getQName());
            final LeafRefContext childLeafRefContext = buildLeafRefContextReferencedByTree(caseNode, currentModule, stack);
            stack.exit();
            if (childLeafRefContext.hasReferencedChild() || childLeafRefContext.isReferenced()) {
                currentLeafRefContextBuilder.addReferencedByChild(childLeafRefContext, childLeafRefContext.getNodeName());
            }
        }
    } else if (node instanceof LeafSchemaNode || node instanceof LeafListSchemaNode) {
        final List<LeafRefContext> foundLeafRefs = getLeafRefsFor(currentModule, stack);
        if (!foundLeafRefs.isEmpty()) {
            currentLeafRefContextBuilder.setReferencedBy(true);
            for (final LeafRefContext leafRef : foundLeafRefs) {
                currentLeafRefContextBuilder.addReferencedByLeafRefCtx(leafRef.getNodeName(), leafRef);
            }
        }
    }
    return currentLeafRefContextBuilder.build();
}
Also used : LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) TypedDataSchemaNode(org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) CaseSchemaNode(org.opendaylight.yangtools.yang.model.api.CaseSchemaNode) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)

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