Example usage for javax.xml.stream XMLStreamConstants CHARACTERS

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

Introduction

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

Prototype

int CHARACTERS

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

Click Source Link

Document

Indicates an event is characters

Usage

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;/*w  ww  . j  ava2  s.c om*/
    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();/*  w  ww.  ja  v  a2 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 .j ava 2 s . com
    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();
}

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

protected static final Model readContent(final XMLStreamReader reader) {
    try {//  w ww.ja v  a 2s  .  com
        if ("XMI.content".equals(reader.getLocalName())) {
            Model model = null;
            while (reader.hasNext()) {
                reader.next();
                switch (reader.getEventType()) {
                case XMLStreamConstants.START_ELEMENT: {
                    if ("Model".equals(reader.getLocalName())) {
                        model = readModel(reader);
                        if (model == null) {
                            throw new IllegalStateException();
                        }
                        break;
                    } else {
                        throw new XmiRuntimeException("Expecting Foo element, got: " + reader.getLocalName());
                    }
                }
                case XMLStreamConstants.END_ELEMENT: {
                    if ("XMI.content".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());
                }
                }
            }
            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 DataType readDataType(final XMLStreamReader reader) throws XMLStreamException {
    assertName(XmiElementName.DATA_TYPE, reader);
    boolean isAbstract = false;
    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();/*from   w w w .  j  a v  a  2 s . c  om*/
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiElementName.MODEL_ELEMENT_DOT_TAGGED_VALUE, reader)) {
                try {
                    taggedValues.addAll(readTaggedValueGroup(reader));
                } catch (final AssertionError e) {
                    throw new XmiBadModelElementException(name, e);
                }
            } else if (match(XmiElementName.CLASSIFIER_DOT_FEATURE, reader)) {
                skipElement(reader, false);
            } else {
                skipElement(reader, true);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiElementName.DATA_TYPE, reader);
            return new DataType(id, name, isAbstract, 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 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();/*from   w  w  w. j av  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  ww  . j  a  v  a  2 s .c  o  m*/
        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();/*  w  w  w  . j a  v  a2s . 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;//from  w w  w.  jav a  2s.c  o  m
    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  w w  .ja v a 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();
}