+ public AbstractNodeDataWithSchema addChild(final Deque<DataSchemaNode> schemas) {
+ Preconditions.checkArgument(!schemas.isEmpty(), "Expecting at least one schema");
+
+ // Pop the first node...
+ final DataSchemaNode schema = schemas.pop();
+ if (schemas.isEmpty()) {
+ // Simple, direct node
+ return addChild(schema);
+ }
+
+ // The choice/case mess, reuse what we already popped
+ final DataSchemaNode choiceCandidate = schema;
+ Preconditions.checkArgument(choiceCandidate instanceof ChoiceNode,
+ "Expected node of type ChoiceNode but was %s", choiceCandidate.getClass().getSimpleName());
+ final ChoiceNode choiceNode = (ChoiceNode) choiceCandidate;
+
+ final DataSchemaNode caseCandidate = schemas.pop();
+ Preconditions.checkArgument(caseCandidate instanceof ChoiceCaseNode,
+ "Expected node of type ChoiceCaseNode but was %s", caseCandidate.getClass().getSimpleName());
+ final ChoiceCaseNode caseNode = (ChoiceCaseNode) caseCandidate;
+
+ AugmentationSchema augSchema = null;
+ if (choiceCandidate.isAugmenting()) {
+ augSchema = findCorrespondingAugment(getSchema(), choiceCandidate);
+ }
+
+ // looking for existing choice
+ final List<AbstractNodeDataWithSchema> childNodes;
+ if (augSchema != null) {
+ childNodes = augmentationsToChild.get(augSchema);
+ } else {
+ childNodes = children;
+ }
+
+ CompositeNodeDataWithSchema caseNodeDataWithSchema = findChoice(childNodes, choiceCandidate, caseCandidate);
+ if (caseNodeDataWithSchema == null) {
+ ChoiceNodeDataWithSchema choiceNodeDataWithSchema = new ChoiceNodeDataWithSchema(choiceNode);
+ addChild(choiceNodeDataWithSchema);
+ caseNodeDataWithSchema = choiceNodeDataWithSchema.addCompositeChild(caseNode);
+ }
+
+ return caseNodeDataWithSchema.addChild(schemas);
+ }
+
+ private AbstractNodeDataWithSchema addSimpleChild(final DataSchemaNode schema) {