Example usage for javax.xml.stream XMLStreamConstants START_ELEMENT

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

Introduction

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

Prototype

int START_ELEMENT

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

Click Source Link

Document

Indicates an event is a start element

Usage

From source file:org.slc.sli.modeling.xmi.comp.XmiMappingReader.java

private static final XmiComparison readMappingList(final XMLStreamReader reader) throws XMLStreamException {
    assertStartElement(reader);//w ww . j  a  v a2  s.  c  o  m
    assertName(XmiMappingConstants.DOCUMENT_ELEMENT, reader);
    XmiDefinition lhsModel = null;
    XmiDefinition rhsModel = null;
    final List<XmiMapping> mappingList = new LinkedList<XmiMapping>();
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiMappingConstants.MAPPING, reader)) {
                mappingList.add(assertNotNull(readMapping(reader)));
            } else if (match(XmiMappingConstants.LHS_MODEL, reader)) {
                lhsModel = assertNotNull(readModel(reader));
            } else if (match(XmiMappingConstants.RHS_MODEL, reader)) {
                rhsModel = assertNotNull(readModel(reader));
            } else {
                throw new AssertionError(reader.getLocalName());
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiMappingConstants.DOCUMENT_ELEMENT, reader);
            return new XmiComparison(lhsModel, rhsModel, mappingList);
        }
        case XMLStreamConstants.CHARACTERS:
        case XMLStreamConstants.COMMENT:
        case XMLStreamConstants.PROCESSING_INSTRUCTION: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.xmi.comp.XmiMappingReader.java

private static final XmiDefinition readModel(final XMLStreamReader reader) throws XMLStreamException {
    assertStartElement(reader);/*w ww.ja v  a2 s .  co m*/
    final QName elementName = reader.getName();
    assertName(elementName, reader);
    String name = null;
    String version = null;
    String xmi = null;
    boolean done = false;
    while (!done && reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiMappingConstants.NAME, reader)) {
                name = readStringContent(reader.getName(), reader);
            } else if (match(XmiMappingConstants.VERSION, reader)) {
                version = readStringContent(reader.getName(), reader);
            } else if (match(XmiMappingConstants.FILE, reader)) {
                xmi = readStringContent(reader.getName(), reader);
            } else {
                throw new AssertionError(reader.getLocalName());
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(elementName, reader);
            done = true;
            break;
        }
        case XMLStreamConstants.CHARACTERS:
        case XMLStreamConstants.COMMENT: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    return new XmiDefinition(name, version, xmi);
}

From source file:org.slc.sli.modeling.xmi.comp.XmiMappingReader.java

private static final XmiMappingStatus readStatus(final XMLStreamReader reader) throws XMLStreamException {
    assertStartElement(reader);/*from   w  ww.  j av  a2  s.  c  o  m*/
    assertName(XmiMappingConstants.STATUS, reader);
    final StringBuilder sb = new StringBuilder();
    boolean done = false;
    while (!done && reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            throw new AssertionError(reader.getLocalName());
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiMappingConstants.STATUS, reader);
            done = true;
            break;
        }
        case XMLStreamConstants.CHARACTERS: {
            sb.append(reader.getText());
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    // Intentionally make the coupling loose between the serialization and
    // the enumeration.
    final String value = sb.toString().trim();
    if (XmiMappingValues.STATUS_MATCH.equals(value)) {
        return XmiMappingStatus.MATCH;
    } else if (XmiMappingValues.STATUS_IGNORABLE.equals(value)) {
        return XmiMappingStatus.IGNORABLE;
    } else if (XmiMappingValues.STATUS_ALIGN.equals(value)) {
        return XmiMappingStatus.ALIGN;
    } else if (XmiMappingValues.STATUS_UNKNOWN.equals(value)) {
        return XmiMappingStatus.UNKNOWN;
    } else if (XmiMappingValues.STATUS_TRANSIENT.equals(value)) {
        return XmiMappingStatus.TRANSIENT;
    } else if (XmiMappingValues.STATUS_BUG.equals(value)) {
        return XmiMappingStatus.BUG;
    } else if (XmiMappingValues.STATUS_FINANCIAL.equals(value)) {
        return XmiMappingStatus.FINANCIAL;
    } else {
        throw new AssertionError(XmiMappingConstants.STATUS + " : " + value);
    }
}

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

protected static final XmiAssociationConnection readAssociationConnection(final XMLStreamReader reader) {
    try {//  w  w w. j  a va 2 s.c  om
        assertName(XmiElementName.ASSOCIATION_DOT_CONNECTION, reader);
        final List<AssociationEnd> ends = new ArrayList<AssociationEnd>();
        while (reader.hasNext()) {
            reader.next();
            switch (reader.getEventType()) {
            case XMLStreamConstants.START_ELEMENT: {
                if (match(XmiElementName.ASSOCIATION_END, reader)) {
                    ends.add(readAssociationEnd(reader));
                } else {
                    skipElement(reader, true);
                }
                break;
            }
            case XMLStreamConstants.END_ELEMENT: {
                assertName(XmiElementName.ASSOCIATION_DOT_CONNECTION, reader);
                return new XmiAssociationConnection(ends.get(0), ends.get(1));
            }
            case XMLStreamConstants.CHARACTERS: {
                // Ignore.
                break;
            }
            default: {
                throw new AssertionError(reader.getEventType());
            }
            }
        }
    } 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 AssociationEnd readAssociationEnd(final XMLStreamReader reader) {
    try {/*  w  ww . j  a va2 s . c om*/
        assertName(XmiElementName.ASSOCIATION_END, reader);
        final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>();
        final Identifier id = getId(reader);
        final String name = getName(reader, DEFAULT_EMPTY_NAME, XmiAttributeName.NAME);
        final String associatedAttribName = getName(reader, DEFAULT_EMPTY_NAME,
                XmiAttributeName.ASSOCIATED_ATTRIBUTE_NAME);
        final boolean isNavigable = getBoolean(XmiAttributeName.IS_NAVIGABLE, true, reader);
        Identifier participant = null;
        final Range range = new Range(Identifier.random(), Occurs.ONE, Occurs.ONE, EMPTY_TAGGED_VALUE_LIST);
        Multiplicity multiplicity = new Multiplicity(Identifier.random(), EMPTY_TAGGED_VALUE_LIST, range);
        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));
                } else if (match(XmiElementName.ASSOCIATION_END_DOT_MULTIPLICITY, reader)) {
                    multiplicity = assertNotNull(readAssociationEndMultiplicity(reader));
                } else if (match(XmiElementName.ASSOCIATION_END_DOT_PARTICIPANT, reader)) {
                    participant = readAssociationEndParticipant(reader);
                } else {
                    throw new UnsupportedOperationException(reader.getName().toString());
                    // skipElement(reader);
                }
                break;
            }
            case XMLStreamConstants.END_ELEMENT: {
                assertName(XmiElementName.ASSOCIATION_END, reader);
                if (participant == null) {
                    throw new AssertionError(XmiElementName.ASSOCIATION_END_DOT_PARTICIPANT);
                }
                return new AssociationEnd(multiplicity, name, isNavigable, id, taggedValues, participant,
                        associatedAttribName);
            }
            case XMLStreamConstants.CHARACTERS: {
                // Ignore.
                break;
            }
            default: {
                throw new AssertionError(reader.getEventType());
            }
            }
        }
    } catch (final XMLStreamException e) {
        throw new XmiRuntimeException(e);
    }
    throw new AssertionError();
}

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

protected static final Multiplicity readAssociationEndMultiplicity(final XMLStreamReader reader)
        throws XMLStreamException {
    assertName(XmiElementName.ASSOCIATION_END_DOT_MULTIPLICITY, reader);
    Multiplicity multiplicity = null;/* www.j a 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 {
                skipElement(reader, true);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.ASSOCIATION_END_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 Identifier readAssociationEndParticipant(final XMLStreamReader reader)
        throws XMLStreamException {
    assertName(XmiElementName.ASSOCIATION_END_DOT_PARTICIPANT, reader);
    Identifier reference = null;/*from  w  ww  .  jav a  2 s.c  om*/
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.CLASS, reader)) {
                reference = readIdentifier(reader);
            } else if (match(XmiElementName.ASSOCIATION_CLASS, reader)) {
                reference = readIdentifier(reader);
            } else {
                skipElement(reader, true);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.ASSOCIATION_END_DOT_PARTICIPANT, reader);
            return 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 Attribute readAttribute(final XMLStreamReader reader) throws XMLStreamException {
    assertName(XmiElementName.ATTRIBUTE, reader);
    final Identifier id = getId(reader);
    final String name = getName(reader, null, XmiAttributeName.NAME);
    Identifier type = null;/*from   w  ww . j a v a  2s  .c  o m*/
    Multiplicity multiplicity = null;
    final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>();
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.STRUCTURAL_FEATURE_DOT_MULTIPLICITY, reader)) {
                multiplicity = assertNotNull(readStructuralFeatureDotMultiplicity(reader));
            } else if (match(XmiElementName.STRUCTURAL_FEATURE_DOT_TYPE, reader)) {
                try {
                    type = assertNotNull(
                            readIdentifierWrapper(XmiElementName.STRUCTURAL_FEATURE_DOT_TYPE, reader));
                } catch (final AssertionError e) {
                    throw new XmiBadAttributeException(name.toString(), e);
                }
            } else if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) {
                taggedValues.addAll(readTaggedValueGroup(reader));
            } else {
                throw new AssertionError(reader.getLocalName());
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.ATTRIBUTE, reader);
            return new Attribute(id, name, type, multiplicity, 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<Attribute> readClassifierDotFeature(final XMLStreamReader reader)
        throws XMLStreamException {
    assertName(XmiElementName.CLASSIFIER_DOT_FEATURE, reader);
    final List<Attribute> attributes = new LinkedList<Attribute>();
    while (reader.hasNext()) {
        reader.next();/*from  w  w w  .j  ava2 s.c  om*/
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.ATTRIBUTE, reader)) {
                attributes.add(assertNotNull(readAttribute(reader)));
            } else if (match(XmiElementName.OPERATION, reader)) {
                skipElement(reader, false);
            } else {
                throw new AssertionError(reader.getLocalName());
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.CLASSIFIER_DOT_FEATURE, reader);
            return assertNotNull(attributes);
        }
        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 ClassType readClassType(final QName elementName, final XMLStreamReader reader)
        throws XMLStreamException {
    assertName(elementName, reader);/* w  w  w . ja va2 s . c o  m*/
    boolean isAbstract = false;
    final List<Attribute> attributes = new LinkedList<Attribute>();
    final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>();
    final Identifier id = getId(reader);
    final String name = getName(reader, null, XmiAttributeName.NAME);
    XmiAssociationConnection connection = 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));
            } else if (match(XmiElementName.CLASSIFIER_DOT_FEATURE, reader)) {
                try {
                    attributes.addAll(readClassifierDotFeature(reader));
                } catch (final AssertionError e) {
                    throw new XmiBadModelElementException(name.toString(), e);
                }
            } else if ("GeneralizableElement.generalization".equals(reader.getLocalName())) {
                skipElement(reader, false);
            } else if ("ModelElement.comment".equals(reader.getLocalName())) {
                skipElement(reader, false);
            } else if ("ModelElement.clientDependency".equals(reader.getLocalName())) {
                skipElement(reader, false);
            } else if ("Namespace.ownedElement".equals(reader.getLocalName())) {
                skipElement(reader, false);
            } else if (match(XmiElementName.ASSOCIATION_DOT_CONNECTION, reader)) {
                connection = assertNotNull(readAssociationConnection(reader));
            } else {
                skipElement(reader, true);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(elementName, reader);
            if (match(XmiElementName.CLASS, elementName)) {
                return new ClassType(id, name, isAbstract, attributes, taggedValues);
            } else if (match(XmiElementName.ASSOCIATION_CLASS, elementName)) {
                return new ClassType(id, name, isAbstract, attributes, connection.getLHS(), connection.getRHS(),
                        taggedValues);
            } else if (match(XmiElementName.ASSOCIATION, elementName)) {
                return new ClassType(id, name, connection.getLHS(), connection.getRHS(), taggedValues);
            } else {
                throw new AssertionError(elementName);
            }
        }
        case XMLStreamConstants.CHARACTERS: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}