Search in sources :

Example 36 with DataNodeContainer

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

the class TestXmlBodyReader method moduleSubContainerDataPutTest.

@Test
public void moduleSubContainerDataPutTest() throws Exception {
    final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
    final QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
    final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
    final DataSchemaNode dataSchemaNodeOnPath = ((DataNodeContainer) dataSchemaNode).getDataChildByName(cont1QName);
    final String uri = "instance-identifier-module:cont/cont1";
    mockBodyReader(uri, this.xmlBodyReader, false);
    final InputStream inputStream = TestXmlBodyReader.class.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
    final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream);
    checkNormalizedNodeContext(returnValue);
    checkExpectValueNormalizeNodeContext(dataSchemaNodeOnPath, returnValue, dataII);
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) InputStream(java.io.InputStream) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Test(org.junit.Test)

Example 37 with DataNodeContainer

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

the class TestRestconfUtils method parse.

private static NormalizedNode parse(final InstanceIdentifierContext<?> iiContext, final Document doc) throws XMLStreamException, IOException, ParserConfigurationException, SAXException, URISyntaxException {
    final SchemaNode schemaNodeContext = iiContext.getSchemaNode();
    DataSchemaNode schemaNode = null;
    if (schemaNodeContext instanceof RpcDefinition) {
        if ("input".equalsIgnoreCase(doc.getDocumentElement().getLocalName())) {
            schemaNode = ((RpcDefinition) schemaNodeContext).getInput();
        } else if ("output".equalsIgnoreCase(doc.getDocumentElement().getLocalName())) {
            schemaNode = ((RpcDefinition) schemaNodeContext).getOutput();
        } else {
            throw new IllegalStateException("Unknown Rpc input node");
        }
    } else if (schemaNodeContext instanceof DataSchemaNode) {
        schemaNode = (DataSchemaNode) schemaNodeContext;
    } else {
        throw new IllegalStateException("Unknow SchemaNode");
    }
    final String docRootElm = doc.getDocumentElement().getLocalName();
    final String schemaNodeName = iiContext.getSchemaNode().getQName().getLocalName();
    if (!schemaNodeName.equalsIgnoreCase(docRootElm)) {
        for (final DataSchemaNode child : ((DataNodeContainer) schemaNode).getChildNodes()) {
            if (child.getQName().getLocalName().equalsIgnoreCase(docRootElm)) {
                schemaNode = child;
                break;
            }
        }
    }
    final NormalizedNodeResult resultHolder = new NormalizedNodeResult();
    final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
    final XmlParserStream xmlParser = XmlParserStream.create(writer, SchemaInferenceStack.ofInstantiatedPath(iiContext.getSchemaContext(), schemaNode.getPath()).toInference());
    if (schemaNode instanceof ContainerLike || schemaNode instanceof ListSchemaNode) {
        xmlParser.traverse(new DOMSource(doc.getDocumentElement()));
        return resultHolder.getResult();
    }
    // FIXME : add another DataSchemaNode extensions e.g. LeafSchemaNode
    return null;
}
Also used : ContainerLike(org.opendaylight.yangtools.yang.model.api.ContainerLike) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) XmlParserStream(org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream) DOMSource(javax.xml.transform.dom.DOMSource) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) NormalizedNodeResult(org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult) ImmutableNormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter) NormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer)

Example 38 with DataNodeContainer

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

the class TestJsonBodyReaderMountPoint method checkExpectValueNormalizeNodeContext.

protected void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode, final NormalizedNodeContext nnContext, final QName qualifiedName) {
    YangInstanceIdentifier dataNodeIdent = YangInstanceIdentifier.of(dataSchemaNode.getQName());
    final DOMMountPoint mountPoint = nnContext.getInstanceIdentifierContext().getMountPoint();
    final DataSchemaNode mountDataSchemaNode = modelContext(mountPoint).getDataChildByName(dataSchemaNode.getQName());
    assertNotNull(mountDataSchemaNode);
    if (qualifiedName != null && dataSchemaNode instanceof DataNodeContainer) {
        final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode).getDataChildByName(qualifiedName);
        dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent).node(child.getQName()).build();
        assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode().equals(child));
    } else {
        assertTrue(mountDataSchemaNode.equals(dataSchemaNode));
    }
    assertNotNull(NormalizedNodes.findNode(nnContext.getData(), dataNodeIdent));
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 39 with DataNodeContainer

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

the class QueryBuilderState method bindMethod.

@NonNull
BoundMethod bindMethod(@NonNull final InstanceIdentifier<?> bindingPath, @NonNull final LeafReference<?, ?> ref) {
    // Verify bindingPath, which will give us something to fish in
    final BindingDataObjectCodecTreeNode<?> targetCodec = codec.getSubtreeCodec(bindingPath);
    checkState(targetCodec != null, "Failed to find codec for %s", bindingPath);
    final WithStatus targetSchema = targetCodec.getSchema();
    verify(targetSchema instanceof DataNodeContainer, "Unexpected target schema %s", targetSchema);
    final LambdaTarget targetLeaf = LambdaDecoder.resolveLambda(ref);
    verify(targetLeaf.targetClass.equals(bindingPath.getTargetType().getName()), "Mismatched target %s and path %s", targetLeaf, bindingPath);
    final NodeIdentifier childId = factory.findChild((DataNodeContainer) targetSchema, targetLeaf.targetMethod);
    final YangInstanceIdentifier absTarget = fromBinding(bindingPath);
    final YangInstanceIdentifier relTarget = absTarget.relativeTo(absoluteSelect).orElseThrow(() -> new IllegalStateException(absoluteSelect + " is not an ancestor of " + absTarget));
    return new BoundMethod(relTarget, targetCodec.yangPathArgumentChild(childId));
}
Also used : WithStatus(org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) LambdaTarget(org.opendaylight.mdsal.binding.dom.adapter.query.LambdaDecoder.LambdaTarget) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Objects.requireNonNull(java.util.Objects.requireNonNull) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 40 with DataNodeContainer

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

the class DataContainerCodecPrototype method computeChildAddressabilitySummary.

private static ChildAddressabilitySummary computeChildAddressabilitySummary(final Object nodeSchema) {
    // FIXME: rework this to work on EffectiveStatements
    if (nodeSchema instanceof DataNodeContainer) {
        boolean haveAddressable = false;
        boolean haveUnaddressable = false;
        for (DataSchemaNode child : ((DataNodeContainer) nodeSchema).getChildNodes()) {
            if (child instanceof ContainerSchemaNode || child instanceof AugmentationSchemaNode) {
                haveAddressable = true;
            } else if (child instanceof ListSchemaNode) {
                if (((ListSchemaNode) child).getKeyDefinition().isEmpty()) {
                    haveUnaddressable = true;
                } else {
                    haveAddressable = true;
                }
            } else if (child instanceof AnydataSchemaNode || child instanceof AnyxmlSchemaNode || child instanceof TypedDataSchemaNode) {
                haveUnaddressable = true;
            } else if (child instanceof ChoiceSchemaNode) {
                switch(computeChildAddressabilitySummary(child)) {
                    case ADDRESSABLE:
                        haveAddressable = true;
                        break;
                    case MIXED:
                        haveAddressable = true;
                        haveUnaddressable = true;
                        break;
                    case UNADDRESSABLE:
                        haveUnaddressable = true;
                        break;
                    default:
                        throw new IllegalStateException("Unhandled accessibility summary for " + child);
                }
            } else {
                LOG.warn("Unhandled child node {}", child);
            }
        }
        if (!haveAddressable) {
            // Empty or all are unaddressable
            return ChildAddressabilitySummary.UNADDRESSABLE;
        }
        return haveUnaddressable ? ChildAddressabilitySummary.MIXED : ChildAddressabilitySummary.ADDRESSABLE;
    } else if (nodeSchema instanceof ChoiceSchemaNode) {
        boolean haveAddressable = false;
        boolean haveUnaddressable = false;
        for (CaseSchemaNode child : ((ChoiceSchemaNode) nodeSchema).getCases()) {
            switch(computeChildAddressabilitySummary(child)) {
                case ADDRESSABLE:
                    haveAddressable = true;
                    break;
                case UNADDRESSABLE:
                    haveUnaddressable = true;
                    break;
                case MIXED:
                    // A child is mixed, which means we are mixed, too
                    return ChildAddressabilitySummary.MIXED;
                default:
                    throw new IllegalStateException("Unhandled accessibility summary for " + child);
            }
        }
        if (!haveAddressable) {
            // Empty or all are unaddressable
            return ChildAddressabilitySummary.UNADDRESSABLE;
        }
        return haveUnaddressable ? ChildAddressabilitySummary.MIXED : ChildAddressabilitySummary.ADDRESSABLE;
    }
    // No child nodes possible: return unaddressable
    return ChildAddressabilitySummary.UNADDRESSABLE;
}
Also used : AugmentationSchemaNode(org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode) TypedDataSchemaNode(org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) TypedDataSchemaNode(org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) 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) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode)

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