public void endElement()

in xmlschema-walker/src/main/java/org/apache/ws/commons/schema/docpath/XmlSchemaPathFinder.java [833:893]


    public void endElement(String uri, String localName, String qName) throws SAXException {
        final QName elemQName = new QName(uri, localName);

        try {
            final boolean isAny = (currentPath.getStateMachineNode().getNodeType()
                .equals(XmlSchemaStateMachineNode.Type.ANY)
                                   && (anyStack != null) && !anyStack.isEmpty());

            if (!isAny && !elementStack.get(elementStack.size() - 1).equals(elemQName)) {
                throw new IllegalStateException("Attempting to end element " + elemQName
                                                + " but the stack is expecting "
                                                + elementStack.get(elementStack.size() - 1));
            }

            if (!isAny) {
                walkUpToElement(elemQName);
            }

            final XmlSchemaStateMachineNode state = currentPath.getStateMachineNode();

            if (state.getNodeType().equals(XmlSchemaStateMachineNode.Type.ELEMENT)) {

                // 1. Is this the element we are looking for?
                if (!state.getElement().getQName().equals(elemQName)) {
                    throw new IllegalStateException("We are ending element " + elemQName
                                                    + " but our current position is for element "
                                                    + state.getElement().getQName() + '.');
                }

                // 2. Check the element received the expected content, if any.
                final XmlSchemaTypeInfo elemTypeInfo = state.getElementType();

                final boolean elemExpectsContent = (elemTypeInfo != null)
                                                   && (!elemTypeInfo.getType()
                                                       .equals(XmlSchemaTypeInfo.Type.COMPLEX));

                if (elemExpectsContent && !state.getElement().isNillable()
                    && (state.getElement().getDefaultValue() == null)
                    && (state.getElement().getFixedValue() == null)
                    && !currentPath.getDocumentNode().getReceivedContent()) {
                    throw new IllegalStateException("We are ending element " + elemQName
                                                    + "; it expected to receive content but did not.");
                }
            }

            traversedElements.add(new TraversedElement(elemQName, TraversedElement.Traversal.END));

            elementStack.remove(elementStack.size() - 1);
            if (isAny) {
                anyStack.remove(anyStack.size() - 1);
            }

            if ((anyStack == null) || anyStack.isEmpty()) {
                walkUpTree(elemQName);
            }

        } catch (Exception e) {
            throw new RuntimeException("Error occurred while ending element " + elemQName
                                       + "; traversed path was " + getElementsTraversedAsString(), e);
        }
    }