+ if (dsn instanceof ChoiceNode) {
+ choiceSubnodes.put(dsn.getQName().getLocalName(), (ChoiceNode) dsn);
+ } else if (node.getNodeType().getLocalName().equals(dsn.getQName().getLocalName())) {
+ return new SchemaLocation(dsn);
+ }
+ }
+
+ for (ChoiceNode choiceSubnode : choiceSubnodes.values()) {
+ if ((!pathIterator.isEmpty() && pathIterator.peekLast().equals(choiceSubnode.getQName().getLocalName()))
+ || pathIterator.isEmpty()) {
+ String pathPartChoice = pathIterator.pollLast();
+ for (ChoiceCaseNode concreteCase : choiceSubnode.getCases()) {
+ if ((!pathIterator.isEmpty() && pathIterator.peekLast().equals(
+ concreteCase.getQName().getLocalName()))
+ || pathIterator.isEmpty()) {
+ String pathPartCase = pathIterator.pollLast();
+ SchemaLocation schemaLocation = findFirstSchemaForNode(node, concreteCase.getChildNodes(),
+ pathIterator);
+ if (schemaLocation != null) {
+ schemaLocation.addPathPart(concreteCase.getQName().getLocalName());
+ schemaLocation.addPathPart(choiceSubnode.getQName().getLocalName());
+ return schemaLocation;
+ }
+ if (pathPartCase != null) {
+ pathIterator.addLast(pathPartCase);
+ }
+ }
+ }
+ if (pathPartChoice != null) {
+ pathIterator.addLast(pathPartChoice);
+ }