-
- public static Optional<CaseSchemaNode> findInstantiatedCase(final ChoiceSchemaNode instantiatedChoice,
- final CaseSchemaNode originalDefinition) {
- CaseSchemaNode potential = instantiatedChoice.getCaseNodeByName(originalDefinition.getQName());
- if (originalDefinition.equals(potential)) {
- return Optional.of(potential);
- }
- if (potential != null) {
- SchemaNode potentialRoot = SchemaNodeUtils.getRootOriginalIfPossible(potential);
- if (originalDefinition.equals(potentialRoot)) {
- return Optional.of(potential);
- }
- }
-
- // We try to find case by name, then lookup its root definition
- // and compare it with original definition
- // This solves case, if choice was inside grouping
- // which was used in different module and thus namespaces are
- // different, but local names are still same.
- //
- // Still we need to check equality of definition, because local name is not
- // sufficient to uniquelly determine equality of cases
- //
- for (CaseSchemaNode caze : instantiatedChoice.findCaseNodes(originalDefinition.getQName().getLocalName())) {
- if (originalDefinition.equals(SchemaNodeUtils.getRootOriginalIfPossible(caze))) {
- return Optional.of(caze);
- }
- }
- return Optional.empty();
- }
-