Example usage for org.springframework.util.xml StaxUtils getXMLEventReader

List of usage examples for org.springframework.util.xml StaxUtils getXMLEventReader

Introduction

In this page you can find the example usage for org.springframework.util.xml StaxUtils getXMLEventReader.

Prototype

@Nullable
public static XMLEventReader getXMLEventReader(Source source) 

Source Link

Document

Return the XMLEventReader for the given StAX Source.

Usage

From source file:org.springframework.oxm.jaxb.Jaxb2Marshaller.java

protected Object unmarshalStaxSource(Unmarshaller jaxbUnmarshaller, Source staxSource) throws JAXBException {
    XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(staxSource);
    if (streamReader != null) {
        return (this.mappedClass != null ? jaxbUnmarshaller.unmarshal(streamReader, this.mappedClass).getValue()
                : jaxbUnmarshaller.unmarshal(streamReader));
    } else {/*w ww . j  a  v  a  2  s .c o  m*/
        XMLEventReader eventReader = StaxUtils.getXMLEventReader(staxSource);
        if (eventReader != null) {
            return (this.mappedClass != null
                    ? jaxbUnmarshaller.unmarshal(eventReader, this.mappedClass).getValue()
                    : jaxbUnmarshaller.unmarshal(eventReader));
        } else {
            throw new IllegalArgumentException(
                    "StaxSource contains neither XMLStreamReader nor XMLEventReader");
        }
    }
}

From source file:org.springframework.oxm.support.AbstractMarshaller.java

/**
 * Template method for handling {@code StaxSource}s.
 * <p>This implementation delegates to {@code unmarshalXmlStreamReader} or
 * {@code unmarshalXmlEventReader}./*from  w ww.  ja v a2s .com*/
 * @param staxSource the {@code StaxSource}
 * @return the object graph
 * @throws XmlMappingException if the given source cannot be mapped to an object
 */
protected Object unmarshalStaxSource(Source staxSource) throws XmlMappingException {
    XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(staxSource);
    if (streamReader != null) {
        return unmarshalXmlStreamReader(streamReader);
    } else {
        XMLEventReader eventReader = StaxUtils.getXMLEventReader(staxSource);
        if (eventReader != null) {
            return unmarshalXmlEventReader(eventReader);
        } else {
            throw new IllegalArgumentException(
                    "StaxSource contains neither XMLStreamReader nor XMLEventReader");
        }
    }
}