private void marshalStaxResult(Marshaller jaxbMarshaller, Object graph, Result staxResult) throws JAXBException { XMLStreamWriter streamWriter = TraxUtils.getXMLStreamWriter(staxResult); if (streamWriter != null) { jaxbMarshaller.marshal(graph, streamWriter); } else { XMLEventWriter eventWriter = TraxUtils.getXMLEventWriter(staxResult); if (eventWriter != null) { jaxbMarshaller.marshal(graph, eventWriter); } else { throw new IllegalArgumentException("StAX Result contains neither XMLStreamWriter nor XMLEventConsumer"); } } }
/** * Template method for handling <code>StaxResult</code>s. This implementation defers to * <code>marshalXMLSteamWriter</code>, or <code>marshalXMLEventConsumer</code>, depending on what is contained in * the <code>StaxResult</code>. * * @param graph the root of the object graph to marshal * @param staxResult a Spring-WS {@link StaxSource} or JAXP 1.4 {@link StAXSource} * @throws XmlMappingException if the given object cannot be marshalled to the result * @throws IllegalArgumentException if the <code>domResult</code> is empty * @see #marshalDomNode(Object,org.w3c.dom.Node) */ protected void marshalStaxResult(Object graph, Result staxResult) throws XmlMappingException { XMLStreamWriter streamWriter = TraxUtils.getXMLStreamWriter(staxResult); if (streamWriter != null) { marshalXmlStreamWriter(graph, streamWriter); } else { XMLEventWriter eventWriter = TraxUtils.getXMLEventWriter(staxResult); if (eventWriter != null) { marshalXmlEventWriter(graph, eventWriter); } else { throw new IllegalArgumentException("StaxResult contains neither XMLStreamWriter nor XMLEventConsumer"); } } }
public void marshal(Object graph, Result result) { if (TraxUtils.isStaxResult(result)) { XMLStreamWriter streamWriter = TraxUtils.getXMLStreamWriter(result); if (streamWriter != null) { result = new StaxResult(streamWriter); } else { XMLEventWriter eventWriter = TraxUtils.getXMLEventWriter(result); if (eventWriter != null) { result = new StaxResult(eventWriter); } else { throw new IllegalArgumentException( "StAXResult contains neither XMLStreamWriter nor XMLEventWriter"); } } } try { createMarshaller().marshal(graph, result); } catch (JAXBException ex) { throw convertJaxbException(ex); } }