Example usage for javax.xml.stream XMLStreamReader next

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

Introduction

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

Prototype

public int next() throws XMLStreamException;

Source Link

Document

Get next parsing event - a processor may return all contiguous character data in a single chunk, or it may split it into several chunks.

Usage

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  w w w.j av  a2s. c o 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();
        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());
            }// www.  jav  a  2 s .  co m
            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  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.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;/*  w w w  .j a v  a 2s.  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();
}

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

protected static final Range readMultiplicityRange(final XMLStreamReader reader) throws XMLStreamException {
    assertName(XmiElementName.MULTIPLICITY_RANGE, reader);
    final Identifier id = getId(reader);
    final Occurs lowerBound = getOccurs(reader, XmiAttributeName.LOWER);
    final Occurs upperBound = getOccurs(reader, XmiAttributeName.UPPER);
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            skipElement(reader, false);/*  www  .  j  ava 2s. c o  m*/
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.MULTIPLICITY_RANGE, reader);
            return new Range(id, lowerBound, upperBound, EMPTY_TAGGED_VALUE_LIST);
        }
        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

/**
 * The UML:Namespace.ownedElement is simply a list of model elements that can belong in a
 * name-space.// w w w  .  j av a  2 s  . com
 *
 * It has no identity of its own and is only present in the serialization format.
 */
protected static final List<NamespaceOwnedElement> readNamespaceOwnedElement(final XMLStreamReader reader)
        throws XMLStreamException {
    assertName(XmiElementName.NAMESPACE_DOT_OWNED_ELEMENT, reader);
    final List<NamespaceOwnedElement> ownedElements = new LinkedList<NamespaceOwnedElement>();
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.CLASS, reader)) {
                ownedElements.add(assertNotNull(readClassType(reader.getName(), reader)));
            } else if (match(XmiElementName.ASSOCIATION_CLASS, reader)) {
                ownedElements.add(assertNotNull(readClassType(reader.getName(), reader)));
            } else if (match(XmiElementName.ASSOCIATION, reader)) {
                ownedElements.add(assertNotNull(readClassType(reader.getName(), reader)));
            } else if (match(XmiElementName.DATA_TYPE, reader)) {
                ownedElements.add(assertNotNull(readDataType(reader)));
            } else if (match(XmiElementName.ENUMERATION, reader)) {
                ownedElements.add(assertNotNull(readEnumeration(reader)));
            } else if (match(XmiElementName.TAG_DEFINITION, reader)) {
                ownedElements.add(assertNotNull(readTagDefinition(reader)));
            } else if (match(XmiElementName.GENERALIZATION, reader)) {
                ownedElements.add(assertNotNull(readGeneralization(reader)));
            } else if (match(XmiElementName.COMMENT, reader)) {
                skipElement(reader, false);
            } else if (match(XmiElementName.PACKAGE, reader)) {
                ownedElements.add(assertNotNull(readPackage(reader)));
            } else {
                throw new AssertionError(reader.getName());
                // skipElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.NAMESPACE_DOT_OWNED_ELEMENT, reader);
            return Collections.unmodifiableList(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 UmlPackage readPackage(final XMLStreamReader reader) throws XMLStreamException {
    assertName(XmiElementName.PACKAGE, reader);
    final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>();
    final Identifier id = getId(reader);
    final String name = assertNotNull(getName(reader, null, XmiAttributeName.NAME));
    List<NamespaceOwnedElement> ownedElements = EMPTY_NAMESPACE_OWNED_ELEMENTS;
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.NAMESPACE_DOT_OWNED_ELEMENT, reader)) {
                ownedElements = readNamespaceOwnedElement(reader);
            } else if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) {
                taggedValues.addAll(readTaggedValueGroup(reader));
            } else {
                throw new AssertionError(reader.getLocalName());
                // skipElement(reader);
            }/*from w w w  .  j a va2 s .  c  o m*/
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.PACKAGE, reader);
            return new UmlPackage(name, id, 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 readStructuralFeatureDotMultiplicity(final XMLStreamReader reader)
        throws XMLStreamException {
    assertName(XmiElementName.STRUCTURAL_FEATURE_DOT_MULTIPLICITY, reader);
    Multiplicity multiplicity = null;/* w w  w.  j  a va  2  s .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.STRUCTURAL_FEATURE_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 TagDefinition readTagDefinition(final XMLStreamReader reader) throws XMLStreamException {
    assertName(XmiElementName.TAG_DEFINITION, reader);
    final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>();
    final Identifier id = getId(reader);
    final String name = assertNotNull(getName(reader, null, XmiAttributeName.NAME));
    Multiplicity multiplicity = null;/*from  w w  w.j  a v a  2 s  .c o m*/
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.TAG_DEFINITION_DOT_MULTIPLICITY, reader)) {
                multiplicity = assertNotNull(readTagDefinitionMultiplicity(reader));
            } else if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) {
                skipElement(reader, false);
            } else {
                skipElement(reader, true);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.TAG_DEFINITION, reader);
            return new TagDefinition(id, taggedValues, name, 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 Multiplicity readTagDefinitionMultiplicity(final XMLStreamReader reader)
        throws XMLStreamException {
    assertName(XmiElementName.TAG_DEFINITION_DOT_MULTIPLICITY, reader);
    Multiplicity multiplicity = null;//  w  w w  . ja v a 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();
}