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.wadl.reader.WadlReader.java

private static final Request readRequest(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.REQUEST, reader);
    final List<Param> params = new LinkedList<Param>();
    final List<Representation> representations = new LinkedList<Representation>();
    final List<Documentation> documentation = new LinkedList<Documentation>();
    while (reader.hasNext()) {
        reader.next();/*from www  .ja va2  s  . com*/
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(WadlElementName.REPRESENTATION, reader)) {
                representations.add(readRepresentation(reader));
            } else if (match(WadlElementName.PARAM, reader)) {
                params.add(readParam(reader));
            } else {
                skipForeignNamespaceElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.REQUEST, reader);
            return new Request(documentation, params, representations);
        }
        case XMLStreamConstants.CHARACTERS: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.wadl.reader.WadlReader.java

private static final Resource readResource(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.RESOURCE, reader);
    final String id = getId(reader);
    final List<String> type = getStringListType(WadlAttributeName.TYPE, reader);
    final String queryType = getQueryType(reader, WadlSyntax.QUERY_TYPE_APPLICATION_X_WWW_FORM_URLENCODED);
    final String path = getStringAttribute(WadlAttributeName.PATH, null, reader);
    final String resourceClass = getStringAttribute(WadlAttributeName.RESOURCE_CLASS, null, reader);
    final List<Documentation> documentation = new LinkedList<Documentation>();
    final List<Param> params = new LinkedList<Param>();
    final List<Method> methods = new LinkedList<Method>();
    final List<Resource> resources = new LinkedList<Resource>();
    while (reader.hasNext()) {
        reader.next();/*from  w ww . ja  va2  s  .c  o  m*/
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(WadlElementName.RESOURCE, reader)) {
                resources.add(readResource(reader));
            } else if (match(WadlElementName.DOCUMENTATION, reader)) {
                documentation.add(readDocumentation(reader));
            } else if (match(WadlElementName.PARAM, reader)) {
                params.add(readParam(reader));
            } else if (match(WadlElementName.METHOD, reader)) {
                methods.add(readMethod(reader));
            } else {
                skipForeignNamespaceElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.RESOURCE, reader);
            return new Resource(id, type, queryType, path, documentation, params, methods, resources,
                    resourceClass);
        }
        case XMLStreamConstants.CHARACTERS:
        case XMLStreamConstants.COMMENT: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.wadl.reader.WadlReader.java

private static final Resources readResources(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.RESOURCES, reader);
    final String base = getBase(reader, null);
    final List<Documentation> documentation = new LinkedList<Documentation>();
    final List<Resource> resources = new LinkedList<Resource>();
    while (reader.hasNext()) {
        reader.next();/*from   w w w  .  j a  va 2 s  .c  om*/
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(WadlElementName.RESOURCE, reader)) {
                resources.add(readResource(reader));
            } else if (match(WadlElementName.DOCUMENTATION, reader)) {
                documentation.add(readDocumentation(reader));
            } else {
                skipForeignNamespaceElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.RESOURCES, reader);
            return new Resources(base, documentation, resources);
        }
        case XMLStreamConstants.CHARACTERS: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.wadl.reader.WadlReader.java

private static final Response readResponse(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.RESPONSE, reader);
    final List<String> statusCodes = new LinkedList<String>();
    final List<Param> params = new LinkedList<Param>();
    final List<Representation> representations = new LinkedList<Representation>();
    final List<Documentation> documentation = new LinkedList<Documentation>();
    while (reader.hasNext()) {
        reader.next();/*from w  w  w .  ja  va 2 s .c  o m*/
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(WadlElementName.REPRESENTATION, reader)) {
                representations.add(readRepresentation(reader));
            } else if (match(WadlElementName.PARAM, reader)) {
                params.add(readParam(reader));
            } else if (match(WadlElementName.DOCUMENTATION, reader)) {
                documentation.add(readDocumentation(reader));
            } else {
                skipForeignNamespaceElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.RESPONSE, reader);
            return new Response(statusCodes, documentation, params, representations);
        }
        case XMLStreamConstants.CHARACTERS: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

From source file:org.slc.sli.modeling.wadl.reader.WadlReader.java

/**
 * Skips (recursively) over the element in question. Also useful during development.
 *
 * @param reader//ww w.  jav  a  2s  .  c  om
 *            The StAX {@link XMLStreamReader}.
 */
private static final void skipElementReally(final XMLStreamReader reader) throws XMLStreamException {
    final String localName = reader.getLocalName();
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            skipElementReally(reader);
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            if (localName.equals(reader.getLocalName())) {
                return;
            } else {
                throw new AssertionError(reader.getLocalName());
            }
        }
        case XMLStreamConstants.CHARACTERS:
        case XMLStreamConstants.COMMENT: {
            // 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 void assertStartElement(final XMLStreamReader reader) {
    if (XMLStreamConstants.START_ELEMENT != reader.getEventType()) {
        throw new AssertionError(reader.getLocalName());
    }//from   w ww  . j a  va2 s  . c  o  m
}

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

private static final XmiComparison readDocument(final XMLStreamReader reader) throws XMLStreamException {
    assertStartDocument(reader);//from   ww  w .j av a2 s  .  c  o m
    XmiComparison dm = null;
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiMappingConstants.DOCUMENT_ELEMENT, reader)) {
                dm = assertNotNull(readMappingList(reader));
                return dm;
            } else {
                XMLStreamReaderTools.skipElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_DOCUMENT: {
            return validateNotNull(dm, "Missing root element: " + XmiMappingConstants.DOCUMENT_ELEMENT);
        }
        case XMLStreamConstants.PROCESSING_INSTRUCTION: {
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

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

private static final String readStringContent(final QName elementName, final XMLStreamReader reader)
        throws XMLStreamException {
    assertStartElement(reader);/*from w  ww  .j a va 2s.co m*/
    assertName(elementName, 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(elementName, reader);
            done = true;
            break;
        }
        case XMLStreamConstants.CHARACTERS: {
            sb.append(reader.getText());
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    return sb.toString().trim();
}

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

private static final XmiFeature readFeature(final QName elementName, final XMLStreamReader reader)
        throws XMLStreamException {
    assertStartElement(reader);//w  ww .  ja v a 2s . c  o  m
    assertName(elementName, reader);
    String className = null;
    String name = null;
    boolean exists = true;
    boolean classExists = true;
    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.OWNER_NAME, reader)) {
                className = readStringContent(reader.getName(), reader);
            } else if (match(XmiMappingConstants.EXISTS, reader)) {
                exists = readBooleanContent(reader.getName(), reader, true);
            } else if (match(XmiMappingConstants.OWNER_EXISTS, reader)) {
                classExists = readBooleanContent(reader.getName(), reader, true);
            } 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 XmiFeature(name, exists, className, classExists);
}

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

private static final XmiMapping readMapping(final XMLStreamReader reader) throws XMLStreamException {
    assertStartElement(reader);/*from  ww  w  .  j  a v  a 2s.  c  om*/
    assertName(XmiMappingConstants.MAPPING, reader);
    XmiFeature lhs = null;
    XmiFeature rhs = null;
    XmiMappingStatus status = null;
    String comment = null;
    String tracking = "";
    boolean done = false;
    while (!done && reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(XmiMappingConstants.LHS_FEATURE, reader)) {
                if (lhs == null) {
                    lhs = readFeature(reader.getName(), reader);
                } else {
                    throw new XMLStreamException("duplicate " + XmiMappingConstants.LHS_FEATURE + " tag.");
                }
            } else if (match(XmiMappingConstants.RHS_FEATURE, reader)) {
                rhs = readFeature(reader.getName(), reader);
            } else if (match(XmiMappingConstants.STATUS, reader)) {
                status = readStatus(reader);
            } else if (match(XmiMappingConstants.COMMENT, reader)) {
                comment = readStringContent(reader.getName(), reader);
            } else if (match(XmiMappingConstants.TRACKING, reader)) {
                tracking = readStringContent(reader.getName(), reader);
            } else if (match(XmiMappingConstants.LHS_MISSING, reader)) {
                XMLStreamReaderTools.skipElement(reader);
            } else if (match(XmiMappingConstants.RHS_MISSING, reader)) {
                XMLStreamReaderTools.skipElement(reader);
            } else {
                throw new AssertionError(reader.getLocalName());
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(XmiMappingConstants.MAPPING, reader);
            done = true;
            break;
        }
        case XMLStreamConstants.CHARACTERS:
        case XMLStreamConstants.COMMENT: {
            // Ignore.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    return new XmiMapping(lhs, rhs, status, tracking, comment);
}