Example usage for javax.xml.stream XMLStreamReader hasNext

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

Introduction

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

Prototype

public boolean hasNext() throws XMLStreamException;

Source Link

Document

Returns true if there are more parsing events and false if there are no more events.

Usage

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

protected static final Model readDocument(final XMLStreamReader reader) {
    try {/*from  ww  w  . jav  a 2s . c o m*/
        if (XMLStreamConstants.START_DOCUMENT == reader.getEventType()) {
            Model model = null;
            while (reader.hasNext()) {
                reader.next();
                switch (reader.getEventType()) {
                case XMLStreamConstants.START_ELEMENT: {
                    if ("XMI".equals(reader.getLocalName())) {
                        model = readXMI(reader);
                        if (model == null) {
                            throw new IllegalStateException();
                        }
                        break;
                    } else {
                        throw new XmiRuntimeException("Expecting Foo element, got: " + reader.getLocalName());
                    }
                }
                case XMLStreamConstants.END_DOCUMENT: {
                    if (model == null) {
                        throw new IllegalStateException();
                    }
                    return model;
                }
                default: {
                    throw new AssertionError(reader.getEventType());
                }
                }
            }
            throw new AssertionError();
        } else {
            throw new AssertionError(reader.getLocalName());
        }
    } catch (final XMLStreamException e) {
        throw new XmiRuntimeException(e);
    }
}

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

protected static final EnumType readEnumeration(final XMLStreamReader reader) throws XMLStreamException {
    assertName(XmiElementName.ENUMERATION, reader);
    final List<EnumLiteral> literals = new LinkedList<EnumLiteral>();
    final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>();
    final Identifier id = Identifier.fromString(reader.getAttributeValue("", "xmi.id"));
    final String name = getName(reader, null, XmiAttributeName.NAME);
    while (reader.hasNext()) {
        reader.next();// w w  w  .  jav a 2 s .com
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) {
                taggedValues.addAll(readTaggedValueGroup(reader));
            } else if (match(XmiElementName.ENUMERATION_LITERAL_GROUP, reader)) {
                literals.addAll(readEnumerationLiteralGroup(reader));
            } else {
                skipElement(reader, true);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.ENUMERATION, reader);
            return new EnumType(id, name, literals, taggedValues);
        }
        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 EnumLiteral readEnumerationLiteral(final XMLStreamReader reader)
        throws XMLStreamException {
    assertName(XmiElementName.ENUMERATION_LITERAL, reader);
    final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>();
    final Identifier id = getId(reader);
    final String name = getName(reader, null, XmiAttributeName.NAME);
    while (reader.hasNext()) {
        reader.next();/*w  w  w .  j  a  va  2  s .com*/
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) {
                taggedValues.addAll(readTaggedValueGroup(reader));
                break;
            } else {
                throw new AssertionError(reader.getLocalName());
            }
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.ENUMERATION_LITERAL, reader);
            return new EnumLiteral(id, name, taggedValues);
        }
        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 List<EnumLiteral> readEnumerationLiteralGroup(final XMLStreamReader reader)
        throws XMLStreamException {
    assertName(XmiElementName.ENUMERATION_LITERAL_GROUP, reader);
    final List<EnumLiteral> literals = new LinkedList<EnumLiteral>();
    while (reader.hasNext()) {
        reader.next();/*  ww  w .  ja v  a  2  s .  c  o m*/
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.ENUMERATION_LITERAL, reader)) {
                literals.add(assertNotNull(readEnumerationLiteral(reader)));
            } else {
                skipElement(reader, true);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.ENUMERATION_LITERAL_GROUP, reader);
            return literals;
        }
        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 Generalization readGeneralization(final XMLStreamReader reader)
        throws XMLStreamException {
    assertName(XmiElementName.GENERALIZATION, reader);
    final Identifier id = getId(reader);
    final String name = getName(reader, DEFAULT_EMPTY_NAME, XmiAttributeName.NAME);
    final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>();
    Identifier child = null;/*  ww w.  j  ava2 s.  com*/
    Identifier parent = null;
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) {
                taggedValues.addAll(readTaggedValueGroup(reader));
                break;
            } else if (match(XmiElementName.GENERALIZATION_DOT_CHILD, reader)) {
                child = assertNotNull(readIdentifierWrapper(XmiElementName.GENERALIZATION_DOT_CHILD, reader));
                break;
            } else if (match(XmiElementName.GENERALIZATION_DOT_PARENT, reader)) {
                parent = assertNotNull(readIdentifierWrapper(XmiElementName.GENERALIZATION_DOT_PARENT, reader));
                break;
            } else {
                throw new AssertionError(reader.getLocalName());
            }
            // skipElement(reader);
            // break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.GENERALIZATION, reader);
            return new Generalization(name, id, taggedValues, child, parent);
        }
        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 Identifier readIdentifier(final XMLStreamReader reader) throws XMLStreamException {
    final XmiElementName name = assertNotNull(XmiElementName.getElementName(reader.getLocalName()));
    final Identifier id = getIdRef(reader);
    while (reader.hasNext()) {
        reader.next();/*from w  ww  .j  av a  2s  .  com*/
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            skipElement(reader, false);
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(name, reader);
            return id;
        }
        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 Identifier readIdentifierWrapper(final XmiElementName name, final XMLStreamReader reader)
        throws XMLStreamException {
    assertName(name, reader);//from   www .j  a  v a  2s .co  m
    Identifier reference = null;
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.DATA_TYPE, reader)) {
                reference = assertNotNull(readIdentifier(reader));
            } else if (match(XmiElementName.CLASS, reader)) {
                reference = assertNotNull(readIdentifier(reader));
            } else if (match(XmiElementName.ASSOCIATION_CLASS, reader)) {
                reference = assertNotNull(readIdentifier(reader));
            } else if (match(XmiElementName.ENUMERATION, reader)) {
                reference = assertNotNull(readIdentifier(reader));
            } else {
                skipElement(reader, true);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(name, 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 readModel(final XMLStreamReader reader) throws XMLStreamException {
    assertName(XmiElementName.MODEL, reader);
    final Identifier id = getId(reader);
    final String name = getName(reader, null, XmiAttributeName.NAME);
    List<TaggedValue> taggedValues = EMPTY_TAGGED_VALUE_LIST;
    List<NamespaceOwnedElement> ownedElements = EMPTY_NAMESPACE_OWNED_ELEMENTS;
    while (reader.hasNext()) {
        reader.next();//www .  ja v  a 2s. com
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) {
                taggedValues = readTaggedValueGroup(reader);
            } else if (match(XmiElementName.NAMESPACE_DOT_OWNED_ELEMENT, reader)) {
                ownedElements = readNamespaceOwnedElement(reader);
            } else {
                throw new AssertionError(reader.getLocalName());
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.MODEL, reader);
            return new Model(id, name, taggedValues, ownedElements);
        }
        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 Multiplicity readMultiplicity(final XMLStreamReader reader) throws XMLStreamException {
    assertName(XmiElementName.MULTIPLICITY, reader);
    final Identifier id = getId(reader);

    Range range = null;//from w  ww  . j  ava  2s .  c o  m
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.MULTIPLICITY_DOT_RANGE, reader)) {
                range = readMultiplicityDotRange(reader);
            } else {
                throw new AssertionError(reader.getLocalName());
                // skipElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.MULTIPLICITY, reader);
            return new Multiplicity(id, EMPTY_TAGGED_VALUE_LIST, range);
        }
        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 Range readMultiplicityDotRange(final XMLStreamReader reader) throws XMLStreamException {
    assertName(XmiElementName.MULTIPLICITY_DOT_RANGE, reader);
    Range range = null;/*from  w  w w  .j  a v  a2s  .  c  o m*/
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.MULTIPLICITY_RANGE, reader)) {
                range = assertNotNull(readMultiplicityRange(reader));
            } else {
                throw new AssertionError(reader.getLocalName());
                // skipElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.MULTIPLICITY_DOT_RANGE, reader);
            return assertNotNull(range);
        }
        case XMLStreamConstants.CHARACTERS: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}