final List<Element> elements = Collections.singletonList(doc.getDocumentElement());
final SchemaNode schemaNodeContext = pathContext.getSchemaNode();
DataSchemaNode schemaNode;
+ boolean isRpc = false;
if (schemaNodeContext instanceof RpcDefinition) {
schemaNode = ((RpcDefinition) schemaNodeContext).getInput();
+ isRpc = true;
} else if (schemaNodeContext instanceof DataSchemaNode) {
schemaNode = (DataSchemaNode) schemaNodeContext;
} else {
}
final String docRootElm = doc.getDocumentElement().getLocalName();
- List<YangInstanceIdentifier.PathArgument> iiToDataList = new ArrayList<>();
- InstanceIdentifierContext<SchemaNode> outIIContext;
+ final List<YangInstanceIdentifier.PathArgument> iiToDataList = new ArrayList<>();
+ InstanceIdentifierContext<? extends SchemaNode> outIIContext;
// FIXME the factory instance should be cached if the schema context is the same
final DomToNormalizedNodeParserFactory parserFactory =
DomToNormalizedNodeParserFactory.getInstance(XmlUtils.DEFAULT_XML_CODEC_PROVIDER, pathContext.getSchemaContext());
- if (isPost()) {
+ if (isPost() && !isRpc) {
final Deque<Object> foundSchemaNodes = findPathToSchemaNodeByName(schemaNode, docRootElm);
+ if (foundSchemaNodes.isEmpty()) {
+ throw new IllegalStateException(String.format("Child \"%s\" was not found in parent schema node \"%s\"",
+ docRootElm, schemaNode.getQName()));
+ }
while (!foundSchemaNodes.isEmpty()) {
- Object child = foundSchemaNodes.pop();
+ final Object child = foundSchemaNodes.pop();
if (child instanceof AugmentationSchema) {
final AugmentationSchema augmentSchemaNode = (AugmentationSchema) child;
iiToDataList.add(SchemaUtils.getNodeIdentifierForAugmentation(augmentSchemaNode));
} else if(schemaNode instanceof ListSchemaNode) {
final ListSchemaNode casted = (ListSchemaNode) schemaNode;
parsed = parserFactory.getMapEntryNodeParser().parse(elements, casted);
- iiToDataList.add(parsed.getIdentifier());
+ if (isPost()) {
+ iiToDataList.add(parsed.getIdentifier());
+ }
}
// FIXME : add another DataSchemaNode extensions e.g. LeafSchemaNode
- YangInstanceIdentifier fullIIToData = YangInstanceIdentifier.create(Iterables.concat(
+ final YangInstanceIdentifier fullIIToData = YangInstanceIdentifier.create(Iterables.concat(
pathContext.getInstanceIdentifier().getPathArguments(), iiToDataList));
outIIContext = new InstanceIdentifierContext<>(fullIIToData, pathContext.getSchemaNode(), pathContext.getMountPoint(),
return new NormalizedNodeContext(outIIContext, parsed);
}
- private static Deque<Object> findPathToSchemaNodeByName(DataSchemaNode schemaNode, String elementName) {
+ private static Deque<Object> findPathToSchemaNodeByName(final DataSchemaNode schemaNode, final String elementName) {
final Deque<Object> result = new ArrayDeque<>();
final ArrayList<ChoiceSchemaNode> choiceSchemaNodes = new ArrayList<>();
final Collection<DataSchemaNode> children = ((DataNodeContainer) schemaNode).getChildNodes();
private static AugmentationSchema findCorrespondingAugment(final DataSchemaNode parent, final DataSchemaNode child) {
if (parent instanceof AugmentationTarget && !(parent instanceof ChoiceSchemaNode)) {
- for (AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) {
- DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName());
+ for (final AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) {
+ final DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName());
if (childInAugmentation != null) {
return augmentation;
}