Example usage for javax.xml.stream XMLStreamReader getEventType

List of usage examples for javax.xml.stream XMLStreamReader getEventType

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamReader getEventType.

Prototype

public int getEventType();

Source Link

Document

Returns an integer code that indicates the type of the event the cursor is pointing to.

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;//from   w w w  .j  a va  2s .  c o m
    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;//from  ww w. ja  v  a  2 s  .c  o  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();// ww  w .j  a v  a2 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  ww  .j ava 2s  . co 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;//from  w  w w  .j a  v  a 2  s . co 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 {/*www.  j  a  va  2s.c o  m*/
        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//  w  w w  .j  a v a 2  s . c om
 *            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.tobarsegais.webapp.data.Index.java

public static Index read(String bundle, XMLStreamReader reader) throws XMLStreamException {
    while (reader.hasNext() && !reader.isStartElement()) {
        reader.next();/*from   w ww .  jav  a  2 s  . c  o  m*/
    }
    if (reader.getEventType() != XMLStreamConstants.START_ELEMENT) {
        throw new IllegalStateException("Expecting a start element");
    }
    if (!"index".equals(reader.getLocalName())) {
        throw new IllegalStateException("Expecting a <index> element, found a <" + reader.getLocalName() + ">");
    }
    List<IndexEntry> entries = new ArrayList<IndexEntry>();
    int depth = 0;
    while (reader.hasNext() && depth >= 0) {
        switch (reader.next()) {
        case XMLStreamConstants.START_ELEMENT:
            if (depth == 0 && "entry".equals(reader.getLocalName())) {
                entries.add(IndexEntry.read(bundle, Collections.<String>emptyList(), reader));
            } else {
                depth++;
            }
            break;
        case XMLStreamConstants.END_ELEMENT:
            depth--;
            break;
        }
    }
    return new Index(entries);
}

From source file:org.tobarsegais.webapp.data.Plugin.java

public static Plugin read(XMLStreamReader reader) throws XMLStreamException {
    while (reader.hasNext() && !reader.isStartElement()) {
        reader.next();/*  w ww  .j  a va2s.c o m*/
    }
    if (reader.getEventType() != XMLStreamConstants.START_ELEMENT) {
        throw new IllegalStateException("Expecting a start element");
    }
    if (!"plugin".equals(reader.getLocalName())) {
        throw new IllegalStateException("Expecting a <plugin> element");
    }
    String name = reader.getAttributeValue(null, "name");
    String id = reader.getAttributeValue(null, "id");
    String version = reader.getAttributeValue(null, "version");
    String providerName = reader.getAttributeValue(null, "provider-name");
    List<Extension> extensions = new ArrayList<Extension>();
    int depth = 0;
    while (reader.hasNext() && depth >= 0) {
        switch (reader.next()) {
        case XMLStreamConstants.START_ELEMENT:
            if (depth == 0 && "extension".equals(reader.getLocalName())) {
                extensions.add(Extension.read(reader));
            } else {
                depth++;
            }
            break;
        case XMLStreamConstants.END_ELEMENT:
            depth--;
            break;
        }
    }
    return new Plugin(name, id, version, providerName, extensions);
}

From source file:org.tobarsegais.webapp.data.Toc.java

public static Toc read(XMLStreamReader reader) throws XMLStreamException {
    while (reader.hasNext() && !reader.isStartElement()) {
        reader.next();/*from   w  w  w  . j a va 2  s.com*/
    }
    if (reader.getEventType() != XMLStreamConstants.START_ELEMENT) {
        throw new IllegalStateException("Expecting a start element");
    }
    if (!"toc".equals(reader.getLocalName())) {
        throw new IllegalStateException("Expecting a <toc> element");
    }
    String label = reader.getAttributeValue(null, "label");
    String topic = reader.getAttributeValue(null, "topic");
    List<Topic> topics = new ArrayList<Topic>();
    int depth = 0;
    while (reader.hasNext() && depth >= 0) {
        switch (reader.next()) {
        case XMLStreamConstants.START_ELEMENT:
            if (depth == 0 && "topic".equals(reader.getLocalName())) {
                topics.add(Topic.read(reader));
            } else {
                depth++;
            }
            break;
        case XMLStreamConstants.END_ELEMENT:
            depth--;
            break;
        }
    }
    return new Toc(label, topic, topics);
}