Example usage for javax.xml.stream XMLStreamConstants END_ELEMENT

List of usage examples for javax.xml.stream XMLStreamConstants END_ELEMENT

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamConstants END_ELEMENT.

Prototype

int END_ELEMENT

To view the source code for javax.xml.stream XMLStreamConstants END_ELEMENT.

Click Source Link

Document

Indicates an event is an end element

Usage

From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java

protected static final Multiplicity readTagDefinitionMultiplicity(final XMLStreamReader reader)
        throws XMLStreamException {
    assertName(XmiElementName.TAG_DEFINITION_DOT_MULTIPLICITY, reader);
    Multiplicity multiplicity = null;/* ww w.ja  v a  2s  .c  om*/
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.MULTIPLICITY, reader)) {
                multiplicity = assertNotNull(readMultiplicity(reader));
            } else {
                throw new AssertionError(reader.getLocalName());
                // skipElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.TAG_DEFINITION_DOT_MULTIPLICITY, reader);
            return assertNotNull(multiplicity);
        }
        case XMLStreamConstants.CHARACTERS: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java

protected static final TaggedValue readTaggedValue(final XMLStreamReader reader) throws XMLStreamException {
    assertName(XmiElementName.TAGGED_VALUE, reader);
    final Identifier id = getId(reader);
    String dataValue = "";
    Identifier tagDefinition = null;// w  w  w . j  a v a2 s.  co  m
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.TAGGED_VALUE_DOT_DATA_VALUE, reader)) {
                dataValue = assertNotNull(readTaggedValueData(reader));
            } else if (match(XmiElementName.TAGGED_VALUE_DOT_TYPE, reader)) {
                tagDefinition = assertNotNull(readTaggedValueType(reader));
            } else {
                throw new AssertionError(reader.getLocalName());
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.TAGGED_VALUE, reader);
            return new TaggedValue(id, EMPTY_TAGGED_VALUE_LIST, dataValue, tagDefinition);
        }
        case XMLStreamConstants.CHARACTERS: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java

protected static final String readTaggedValueData(final XMLStreamReader reader) throws XMLStreamException {
    assertName(XmiElementName.TAGGED_VALUE_DOT_DATA_VALUE, reader);
    final StringBuilder sb = new StringBuilder();
    while (reader.hasNext()) {
        reader.next();//from w ww  . j ava2  s . c o m
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            throw new AssertionError(reader.getLocalName());
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.TAGGED_VALUE_DOT_DATA_VALUE, reader);
            return collapseWhitespace(sb.toString());
        }
        case XMLStreamConstants.CHARACTERS: {
            sb.append(reader.getText());
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java

protected static final List<TaggedValue> readTaggedValueGroup(final XMLStreamReader reader) {
    final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>();
    try {/*  w w w .  j a v  a  2 s .  c o m*/
        if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) {
            while (reader.hasNext()) {
                reader.next();
                switch (reader.getEventType()) {
                case XMLStreamConstants.START_ELEMENT: {
                    if ("TaggedValue".equals(reader.getLocalName())) {
                        taggedValues.add(assertNotNull(readTaggedValue(reader)));
                        break;
                    } else {
                        throw new AssertionError(reader.getLocalName());
                    }
                }
                case XMLStreamConstants.END_ELEMENT: {
                    if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) {
                        return taggedValues;
                    } else {
                        throw new AssertionError(reader.getLocalName());
                    }
                }
                case XMLStreamConstants.CHARACTERS: {
                    // Ignore.
                    break;
                }
                default: {
                    throw new AssertionError(reader.getEventType());
                }
                }
            }
        } else {
            throw new AssertionError(reader.getLocalName());
        }
    } catch (final XMLStreamException e) {
        LOG.warn(e.getMessage());
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java

protected static final Identifier readTaggedValueType(final XMLStreamReader reader) throws XMLStreamException {
    assertName(XmiElementName.TAGGED_VALUE_DOT_TYPE, reader);
    Identifier reference = null;/*  w ww.  j  a va 2s . c o m*/
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.TAG_DEFINITION, reader)) {
                reference = assertNotNull(readIdentifier(reader));
            } else {
                throw new AssertionError(reader.getLocalName());
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.TAGGED_VALUE_DOT_TYPE, reader);
            return assertNotNull(reference);
        }
        case XMLStreamConstants.CHARACTERS: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java

protected static final Model readXMI(final XMLStreamReader reader) {
    try {// w  ww.j a va 2s.c  om
        if ("XMI".equals(reader.getLocalName())) {
            Model model = null;
            while (reader.hasNext()) {
                reader.next();
                switch (reader.getEventType()) {
                case XMLStreamConstants.START_ELEMENT: {
                    if ("XMI.header".equals(reader.getLocalName())) {
                        skipElement(reader, false);
                        break;
                    } else if ("XMI.content".equals(reader.getLocalName())) {
                        model = readContent(reader);
                        if (model == null) {
                            throw new IllegalStateException();
                        }
                        break;
                    } else {
                        throw new XmiRuntimeException("Expecting Foo element, got: " + reader.getLocalName());
                    }
                }
                case XMLStreamConstants.END_ELEMENT: {
                    if ("XMI".equals(reader.getLocalName())) {
                        if (model == null) {
                            throw new IllegalStateException();
                        }
                        return model;
                    } else {
                        throw new AssertionError(reader.getLocalName());
                    }
                }
                case XMLStreamConstants.CHARACTERS: {
                    // Ignore.
                    break;
                }
                default: {
                    throw new AssertionError(reader.getEventType());
                }
                }
            }
        } else {
            throw new AssertionError(reader.getLocalName());
        }
    } catch (final XMLStreamException e) {
        LOG.warn(e.getMessage());
    }
    return null;
}

From source file:org.slc.sli.modeling.xmi.reader.XmiReader.java

/**
 * Skips (recursively) over the element in question. Also useful during development.
 *
 * @param reader/* ww w.j  av a  2  s  . com*/
 *            The StAX {@link XMLStreamReader}.
 */
protected static final void skipElement(final XMLStreamReader reader, final boolean check)
        throws XMLStreamException {
    if (check) {
        throw new AssertionError(reader.getName());
    }
    final String localName = reader.getLocalName();
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            skipElement(reader, check);
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            if (localName.equals(reader.getLocalName())) {
                return;
            } else {
                throw new AssertionError(reader.getLocalName());
            }
        }
        case XMLStreamConstants.CHARACTERS: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.springmodules.remoting.xmlrpc.stax.AbstractStaxXmlRpcParser.java

/**
 * Creates a new <code>java.util.List</code> from the current element being
 * read in the specified <code>StreamReader</code>.
 * //from w w  w  . j a  v a 2  s.  c  o  m
 * @param reader
 *          the <code>StreamReader</code>.
 * @return the new array of <code>java.util.List</code>s.
 * @see #parseValueElement(XMLStreamReader)
 */
protected final XmlRpcArray parseDataElement(XMLStreamReader reader) throws XMLStreamException {
    XmlRpcArray array = new XmlRpcArray();

    while (reader.hasNext()) {
        int event = reader.next();
        String localName = null;

        switch (event) {
        case XMLStreamConstants.START_ELEMENT:
            localName = reader.getLocalName();

            if (XmlRpcElementNames.VALUE.equals(localName)) {
                XmlRpcElement element = parseValueElement(reader);
                array.add(element);
            }
            break;

        case XMLStreamConstants.END_ELEMENT:
            localName = reader.getLocalName();

            if (XmlRpcElementNames.DATA.equals(localName) || XmlRpcElementNames.ARRAY.equals(localName)) {
                return array;
            }
        }
    }

    // we should not reach this point.
    return null;
}

From source file:org.springmodules.remoting.xmlrpc.stax.AbstractStaxXmlRpcParser.java

/**
 * Parses the given <code>XMLStreamReader</code> containing parameters for a
 * XML-RPC request/response.//from ww w.jav  a  2s  .  c o m
 * 
 * @param reader
 *          the <code>StreamReader</code>.
 * @return the parameters of the XML-RPC request/response.
 */
protected final XmlRpcElement[] parseParametersElement(XMLStreamReader reader) throws XMLStreamException {
    List parameters = new ArrayList();

    while (reader.hasNext()) {
        int event = reader.next();

        String localName = null;
        switch (event) {
        case XMLStreamConstants.START_ELEMENT:
            localName = reader.getLocalName();

            if (XmlRpcElementNames.PARAM.equals(localName)) {
                XmlRpcElement parameter = parseParameterElement(reader);
                parameters.add(parameter);

            } else {
                XmlRpcParsingUtils.handleUnexpectedElementFound(localName);
            }
            break;

        case XMLStreamConstants.END_ELEMENT:
            localName = reader.getLocalName();

            if (XmlRpcElementNames.PARAMS.equals(localName)) {
                return (XmlRpcElement[]) parameters.toArray(new XmlRpcElement[parameters.size()]);
            }
        }
    }

    // we should not reach this point.
    return null;
}

From source file:org.springmodules.remoting.xmlrpc.stax.AbstractStaxXmlRpcParser.java

/**
 * Creates a new <code>java.util.Map</code> from the current element being
 * read in the specified <code>StreamReader</code>.
 * /*from w ww. j a  v a 2s.c om*/
 * @param reader
 *          the <code>StreamReader</code>.
 * @return the new array of <code>java.util.Map</code>s.
 * @see #parseMemberElement(XMLStreamReader)
 */
protected final XmlRpcStruct parseStructElement(XMLStreamReader reader) throws XMLStreamException {
    XmlRpcStruct struct = new XmlRpcStruct();

    while (reader.hasNext()) {
        int event = reader.next();
        String localName = null;

        switch (event) {
        case XMLStreamConstants.START_ELEMENT:
            localName = reader.getLocalName();

            if (XmlRpcElementNames.MEMBER.equals(localName)) {
                XmlRpcMember member = parseMemberElement(reader);
                struct.add(member);
            }
            break;

        case XMLStreamConstants.END_ELEMENT:
            localName = reader.getLocalName();

            if (XmlRpcElementNames.STRUCT.equals(localName)) {
                return struct;
            }
        }
    }

    // we should not reach this point.
    return null;
}