Example usage for javax.xml.stream XMLStreamReader hasNext

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

Introduction

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

Prototype

public boolean hasNext() throws XMLStreamException;

Source Link

Document

Returns true if there are more parsing events and false if there are no more events.

Usage

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

private static final Application readDocument(final XMLStreamReader reader) {
    try {//from w  ww  .  ja v  a  2  s.  c  o  m
        if (XMLStreamConstants.START_DOCUMENT == reader.getEventType()) {
            Application app = null;
            while (reader.hasNext()) {
                reader.next();
                switch (reader.getEventType()) {
                case XMLStreamConstants.START_ELEMENT: {
                    if (match(WadlElementName.APPLICATION, reader)) {
                        app = readApplication(reader);
                        if (app == null) {
                            throw new IllegalStateException();
                        }
                        break;
                    } else {
                        throw new AssertionError(reader.getLocalName());
                    }
                }
                case XMLStreamConstants.END_DOCUMENT: {
                    if (app == null) {
                        throw new IllegalStateException();
                    }
                    return app;
                }
                default: {
                    throw new AssertionError(reader.getEventType());
                }
                }
            }
            throw new AssertionError();
        } else {
            throw new AssertionError(reader.getLocalName());
        }
    } catch (final XMLStreamException e) {
        throw new WadlRuntimeException(e);
    }
}

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

private static final Documentation readDocumentation(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.DOCUMENTATION, reader);
    final String title = getTitle(reader, null);
    final String lang = getLang(reader, null);
    final List<DmNode> content = new LinkedList<DmNode>();
    while (reader.hasNext()) {
        reader.next();//from  w w  w  .j  a  v a  2 s  .c  o m
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            content.add(readMixedElement(reader));
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.DOCUMENTATION, reader);
            return new Documentation(title, lang, content);
        }
        case XMLStreamConstants.CHARACTERS: {
            content.add(new DmText(reader.getText()));
            break;
        }
        case XMLStreamConstants.COMMENT: {
            content.add(new DmComment(reader.getText()));
            break;
        }
        case XMLStreamConstants.PROCESSING_INSTRUCTION: {
            content.add(new DmProcessingInstruction(reader.getPITarget(), reader.getPIData()));
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

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

private static final Option readOption(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.OPTION, reader);
    final String value = getStringAttribute(WadlAttributeName.VALUE, null, reader);
    final List<Documentation> doc = new LinkedList<Documentation>();
    while (reader.hasNext()) {
        reader.next();//from ww w.  j  a va 2  s .c  o  m
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(WadlElementName.DOCUMENTATION, reader)) {
                doc.add(readDocumentation(reader));
            } else {
                skipForeignNamespaceElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.OPTION, reader);
            return new Option(value, doc);
        }
        case XMLStreamConstants.CHARACTERS: {
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

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

private static final Grammars readGrammars(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.GRAMMARS, reader);
    final List<Documentation> documentation = new LinkedList<Documentation>();
    final List<Include> includes = new LinkedList<Include>();
    while (reader.hasNext()) {
        reader.next();//from  ww  w. ja va  2 s  . c om
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(WadlElementName.INCLUDE, reader)) {
                includes.add(readInclude(reader));
            } else {
                skipForeignNamespaceElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.GRAMMARS, reader);
            return new Grammars(documentation, includes);
        }
        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 Include readInclude(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.INCLUDE, reader);
    final String href = getHRef(reader);
    final List<Documentation> doc = new LinkedList<Documentation>();
    while (reader.hasNext()) {
        reader.next();/*from  ww w . j a va  2 s . c om*/
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(WadlElementName.DOCUMENTATION, reader)) {
                doc.add(readDocumentation(reader));
            } else {
                skipForeignNamespaceElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.INCLUDE, reader);
            return new Include(href, doc);
        }
        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 Method readMethod(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.METHOD, reader);
    final String id = getId(reader);
    final String name = getName(reader, null);
    @SuppressWarnings("unused")
    final String href = getHRef(reader, null);
    final List<Documentation> doc = new LinkedList<Documentation>();
    Request request = null;// w  ww. ja v  a2 s . c  o m
    final List<Response> responses = new LinkedList<Response>();
    while (reader.hasNext()) {
        reader.next();
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(WadlElementName.REQUEST, reader)) {
                request = readRequest(reader);
            } else if (match(WadlElementName.RESPONSE, reader)) {
                responses.add(readResponse(reader));
            } else if (match(WadlElementName.DOCUMENTATION, reader)) {
                doc.add(readDocumentation(reader));
            } else {
                skipForeignNamespaceElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.METHOD, reader);
            return new Method(id, name, doc, request, responses);
        }
        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 DmElement readMixedElement(final XMLStreamReader reader) throws XMLStreamException {
    final QName name = reader.getName();
    final List<DmNode> children = new LinkedList<DmNode>();
    while (reader.hasNext()) {
        reader.next();//from  w  w  w. jav a2s .  co m
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            children.add(readMixedElement(reader));
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            if (name.equals(reader.getName())) {
                return new DmElement(name, children);
            } else {
                throw new AssertionError(reader.getLocalName());
            }
        }
        case XMLStreamConstants.CHARACTERS: {
            // Assume that the element will coalesce text nodes.
            children.add(new DmText(reader.getText()));
            break;
        }
        case XMLStreamConstants.COMMENT: {
            // Ignore for now.
            break;
        }
        default: {
            throw new AssertionError(reader.getEventType());
        }
        }
    }
    throw new AssertionError();
}

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

private static final Param readParam(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.PARAM, reader);
    final String name = getName(reader, null);
    final ParamStyle style = getParamStyle(reader, WadlAttributeName.STYLE);
    final String id = getId(reader);
    final QName type = getQNameAttribute(WadlAttributeName.TYPE,
            new QName("http://www.w3.org/2001/XMLSchema", "string"), reader);
    final String defaultValue = getStringAttribute(WadlAttributeName.DEFAULT_VALUE, null, reader);
    final boolean required = getBooleanAttribute(WadlAttributeName.REQUIRED, false, reader);
    final boolean repeating = getBooleanAttribute(WadlAttributeName.REPEATING, false, reader);
    final String fixed = getStringAttribute(WadlAttributeName.FIXED, null, reader);
    final String path = getStringAttribute(WadlAttributeName.PATH, null, reader);
    final List<Documentation> doc = new LinkedList<Documentation>();
    final List<Option> options = new LinkedList<Option>();
    final Link link = null;
    while (reader.hasNext()) {
        reader.next();/*from  ww  w.j av  a 2 s. c  o m*/
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            if (match(WadlElementName.DOCUMENTATION, reader)) {
                doc.add(readDocumentation(reader));
            } else if (match(WadlElementName.OPTION, reader)) {
                options.add(readOption(reader));
            } else {
                skipForeignNamespaceElement(reader);
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.PARAM, reader);
            return new Param(name, style, id, type, defaultValue, required, repeating, fixed, path, doc,
                    options, link);
        }
        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 Representation readRepresentation(final XMLStreamReader reader) throws XMLStreamException {
    assertName(WadlElementName.REPRESENTATION, reader);
    final String id = getId(reader);
    final QName element = getQNameAttribute(WadlAttributeName.ELEMENT, null, reader);
    final String mediaType = getStringAttribute(WadlAttributeName.MEDIA_TYPE, null, reader);
    @SuppressWarnings("unused")
    final String href = getHRef(reader, null);
    final List<String> profiles = getStringListType(WadlAttributeName.PROFILE, reader);
    final List<Param> params = new LinkedList<Param>();
    final List<Documentation> documentation = new LinkedList<Documentation>();
    while (reader.hasNext()) {
        reader.next();/*  ww w .  j av a 2 s .co  m*/
        switch (reader.getEventType()) {
        case XMLStreamConstants.START_ELEMENT: {
            skipForeignNamespaceElement(reader);
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            assertName(WadlElementName.REPRESENTATION, reader);
            return new Representation(id, element, mediaType, profiles, documentation, params);
        }
        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 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();/*w ww  .  j  av a  2s . 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 {
                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();
}