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

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

Introduction

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

Prototype

@Nullable
public static XMLStreamReader getXMLStreamReader(Source source) 

Source Link

Document

Return the XMLStreamReader for the given StAX Source.

Usage

From source file:org.javelin.sws.ext.bind.SoapEncodingMarshaller.java

@Override
public Object unmarshal(Source source) throws IOException, XmlMappingException {
    try {/*from  w ww  . java  2 s.c  o  m*/
        XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(source);
        streamReader.next();
        return streamReader.getElementText();
    } catch (XMLStreamException e) {
        throw new UnmarshallingFailureException(e.getMessage(), e);
    }
}

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 {/*from  w ww .  jav  a  2s . 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   ww  w  .  ja va  2  s  . c om*/
 * @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");
        }
    }
}