- private void addChildToAugmentation(final AugmentationSchema augSchema, final AbstractNodeDataWithSchema newChild) {
- List<AbstractNodeDataWithSchema> childsInAugment = augmentationsToChild.get(augSchema);
- if (childsInAugment == null) {
- childsInAugment = new ArrayList<>();
- augmentationsToChild.put(augSchema, childsInAugment);
- }
- childsInAugment.add(newChild);
- }
-
- public AbstractNodeDataWithSchema addChild(final Deque<DataSchemaNode> schemas) {
- if (schemas.size() == 1) {
- final DataSchemaNode childDataSchemaNode = schemas.pop();
- return addChild(childDataSchemaNode);
- } else {
- DataSchemaNode choiceCandidate = schemas.pop();
- DataSchemaNode caseCandidate = schemas.pop();
- ChoiceNode choiceNode = null;
- ChoiceCaseNode caseNode = null;
- if (choiceCandidate instanceof ChoiceNode) {
- choiceNode = (ChoiceNode) choiceCandidate;
- } else {
- throw new IllegalArgumentException("Awaited node of type ChoiceNode but was "
- + choiceCandidate.getClass().getSimpleName());
- }
-
- if (caseCandidate instanceof ChoiceCaseNode) {
- caseNode = (ChoiceCaseNode) caseCandidate;
- } else {
- throw new IllegalArgumentException("Awaited node of type ChoiceCaseNode but was "
- + caseCandidate.getClass().getSimpleName());
- }
-
- AugmentationSchema augSchema = null;
- if (choiceCandidate.isAugmenting()) {
- augSchema = findCorrespondingAugment(getSchema(), choiceCandidate);
- }
-
- // looking for existing choice
- List<AbstractNodeDataWithSchema> childNodes = Collections.emptyList();
- if (augSchema != null) {
- childNodes = augmentationsToChild.get(augSchema);
- } else {
- childNodes = childs;
- }
-
- 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 CaseNodeDataWithSchema findChoice(final Collection<AbstractNodeDataWithSchema> childNodes, final DataSchemaNode choiceCandidate,
+ final DataSchemaNode caseCandidate) {
+ if (childNodes != null) {
+ for (AbstractNodeDataWithSchema nodeDataWithSchema : childNodes) {
+ if (nodeDataWithSchema instanceof ChoiceNodeDataWithSchema
+ && nodeDataWithSchema.getSchema().getQName().equals(choiceCandidate.getQName())) {
+ CaseNodeDataWithSchema casePrevious = ((ChoiceNodeDataWithSchema) nodeDataWithSchema).getCase();