Search in sources :

Example 1 with TypedDataSchemaNode

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

the class UintAdaptingPruner method adaptEntry.

private void adaptEntry(final ReusableImmutableNormalizedNodeStreamWriter writer, final NodeWithValue<?> name) {
    final NodeWithValue<?> adapted;
    final DataSchemaNode schema = currentSchema().getDataSchemaNode();
    if (schema instanceof TypedDataSchemaNode) {
        final Object oldValue = name.getValue();
        final Object newValue = adaptValue(((TypedDataSchemaNode) schema).getType(), oldValue);
        adapted = newValue == oldValue ? name : new NodeWithValue<>(name.getNodeType(), newValue);
    } else {
        adapted = name;
    }
    writer.startLeafSetEntryNode(adapted);
}
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) NodeWithValue(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue)

Example 2 with TypedDataSchemaNode

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

the class XmlStreamUtilsTest method getTargetNodeForLeafRef.

private static TypeDefinition<?> getTargetNodeForLeafRef(final Class<?> clas, final String... names) {
    final SchemaInferenceStack stack = SchemaInferenceStack.of(schemaContext);
    stack.enterDataTree(QName.create(leafRefModule.getQNameModule(), "cont2"));
    for (String name : names) {
        stack.enterDataTree(QName.create(leafRefModule.getQNameModule(), name));
    }
    final EffectiveStatement<?, ?> leaf = stack.currentStatement();
    assertThat(leaf, instanceOf(LeafSchemaNode.class));
    final TypeDefinition<? extends TypeDefinition<?>> type = ((TypedDataSchemaNode) leaf).getType();
    assertThat(type, instanceOf(LeafrefTypeDefinition.class));
    final TypeDefinition<?> resolved = stack.resolveLeafref((LeafrefTypeDefinition) type);
    assertThat(resolved, instanceOf(clas));
    return resolved;
}
Also used : SchemaInferenceStack(org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack) TypedDataSchemaNode(org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode) LeafrefTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)

Example 3 with TypedDataSchemaNode

use of org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode 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 TypedDataSchemaNode

use of org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode 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 TypedDataSchemaNode

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

the class SchemaInferenceStack method resolveLeafref.

@Override
public TypeDefinition<?> resolveLeafref(final LeafrefTypeDefinition type) {
    final SchemaInferenceStack tmp = copy();
    LeafrefTypeDefinition current = type;
    while (true) {
        final EffectiveStatement<?, ?> resolved = tmp.resolvePathExpression(current.getPathStatement());
        checkState(resolved instanceof TypeAware, "Unexpected result %s resultion of %s", resolved, type);
        final TypeDefinition<?> result = ((TypedDataSchemaNode) resolved).getType();
        if (result instanceof LeafrefTypeDefinition) {
            checkArgument(result != type, "Resolution of %s loops back onto itself via %s", type, current);
            current = (LeafrefTypeDefinition) result;
        } else {
            return result;
        }
    }
}
Also used : TypedDataSchemaNode(org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode) LeafrefTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition) TypeAware(org.opendaylight.yangtools.yang.model.api.TypeAware)

Aggregations

TypedDataSchemaNode (org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode)9 LeafrefTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition)5 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)4 DataNodeContainer (org.opendaylight.yangtools.yang.model.api.DataNodeContainer)3 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)3 QName (org.opendaylight.yangtools.yang.common.QName)2 AnydataSchemaNode (org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode)2 AnyxmlSchemaNode (org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode)2 CaseSchemaNode (org.opendaylight.yangtools.yang.model.api.CaseSchemaNode)2 ChoiceSchemaNode (org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)2 PathExpression (org.opendaylight.yangtools.yang.model.api.PathExpression)2 ImmutableList (com.google.common.collect.ImmutableList)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 DOMSource (javax.xml.transform.dom.DOMSource)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)1 NodeWithValue (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue)1 AugmentationSchemaNode (org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode)1