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); } }