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);
}
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;
}
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));
}
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));
}
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;
}
Aggregations