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 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 w  w  .j ava  2  s.c  o m
        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   w  w  w  . ja v a2  s .com
    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();/* w w  w  . ja va2 s  .co  m*/
        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 a  va  2 s.  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 ava 2 s . com
    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();/*from w ww .  j av a2  s  . co m*/
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            skipElement(reader, false);
            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./*from  w w  w .j a v a 2  s. c om*/
 *
 * 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();// ww  w .j a  v  a  2s. c o  m
        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);
            }
            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 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.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 www  .  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_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();
}