public void require()

in components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivot.java [574:623]


    public void require(int expectedType, String expectedNamespaceURI, String expectedLocalName)
            throws XMLStreamException {
        if (expectedType != eventType) {
            throw new XMLStreamException(
                    "Required type "
                            + XMLEventUtils.getEventTypeString(expectedType)
                            + ", actual type "
                            + XMLEventUtils.getEventTypeString(eventType));
        }

        if (expectedLocalName != null) {
            if (eventType != START_ELEMENT
                    && eventType != END_ELEMENT
                    && eventType != ENTITY_REFERENCE) {
                throw new XMLStreamException(
                        "Required a non-null local name, but current token "
                                + "not a START_ELEMENT, END_ELEMENT or ENTITY_REFERENCE (was "
                                + XMLEventUtils.getEventTypeString(eventType)
                                + ")");
            }
            String localName = getLocalName();
            if (!localName.equals(expectedLocalName)) {
                throw new XMLStreamException(
                        "Required local name '"
                                + expectedLocalName
                                + "'; current local name '"
                                + localName
                                + "'.");
            }
        }

        if (expectedNamespaceURI != null) {
            if (eventType != START_ELEMENT && eventType != END_ELEMENT) {
                throw new XMLStreamException(
                        "Required non-null namespace URI, but current token "
                                + "not a START_ELEMENT or END_ELEMENT (was "
                                + XMLEventUtils.getEventTypeString(eventType)
                                + ")");
            }
            String namespaceURI = elementStack[3 * depth];
            if (!expectedNamespaceURI.equals(namespaceURI)) {
                throw new XMLStreamException(
                        "Required namespace '"
                                + expectedNamespaceURI
                                + "'; have '"
                                + namespaceURI
                                + "'.");
            }
        }
    }