Hi Claus, I have opened CAMEL-8250 for this extension of camel-saxon and attached a patch for it.
The converter can convert NodeInfo data of type DOCUMENT and ELEMENT to Document, all NodeInfo elements to Node or DOMSource, List<NodeInfo> to NodeList and has a fallback converter that can convert NodeInfo data via Node or NodeList, and List<NodeInfo> data via NodeList to the final type if an appropriate type converter is available. The fallback converter also supports the conversion of NodeOverNodeInfo (which is actually a Node implementation) because in contrast to the Node implementation from the JDK it does not implement NodeList and many type converters only convert from NodeList. Best regards Stephan -----Original Message----- From: Claus Ibsen [mailto:claus.ib...@gmail.com] Sent: Dienstag, 13. Januar 2015 08:16 To: dev Subject: Re: Question about type converter logic You can add a type converter to camel-saxon that converts a NodeInfo to DOMSource which Camel ought to use then. On Tue, Jan 13, 2015 at 8:12 AM, Siano, Stephan <stephan.si...@sap.com> wrote: > Hi, > > I am trying to figure out how to write a type converter that can convert e.g. > from net.sf.saxon.om.NodeInfo to DOMSource. The problem with this is that the > NodeInfo implements > (javax<eclipse-javadoc:%E2%98%82=com.sap.esb.sandbox.xpath/C:%5C/Program%20Files%5C/Java%5C/jdk1.7.0_72%5C/jre%5C/lib%5C/rt.jar%3Cjavax>.xml<eclipse-javadoc:%E2%98%82=com.sap.esb.sandbox.xpath/C:%5C/Program%20Files%5C/Java%5C/jdk1.7.0_72%5C/jre%5C/lib%5C/rt.jar%3Cjavax.xml>.transform<eclipse-javadoc:%E2%98%82=com.sap.esb.sandbox.xpath/C:%5C/Program%20Files%5C/Java%5C/jdk1.7.0_72%5C/jre%5C/lib%5C/rt.jar%3Cjavax.xml.transform>.Source), > so the XmlConverter from camel-core will kick in. > > > The relevant coding looks like that (and as NodeInfo is not DOMSource, > SAXSource, StreamSource, or StAXSource the converter will return null) > /** > * Converts the source instance to a {@link DOMSource} or returns null if > the conversion is not > * supported (making it easy to derive from this class to add new kinds > of conversion). > */ > @Converter > public DOMSource toDOMSource(Source source) throws > ParserConfigurationException, IOException, SAXException, TransformerException > { > if (source instanceof DOMSource) { > return (DOMSource) source; > } else if (source instanceof SAXSource) { > return toDOMSourceFromSAX((SAXSource) source); > } else if (source instanceof StreamSource) { > return toDOMSourceFromStream((StreamSource) source); > } else if (source instanceof StAXSource) { > return toDOMSourceFromStAX((StAXSource)source); > } else { > return null; > } > } > > I don't think that changing the XmlConverter is a good ideas (as it would > introduce a Saxon dependency to camel-core), but the comment at least implies > that it should be possible to extend the converter somewhere else (e.g. in > camel-saxon). However, I couldn't figure out how to do this. > > So far I have tried to create a SaxonConverter that extends XMLConverter, > overrides the toDOMSource method of XmlConverter and creates a new converter > method from NodeInfo to DOMSource, but those methods never get invoked in my > unit tests (and the type conversion keeps returning null). > > Is there any documentation about how type converters are selected and how > this extension could be done (or could someone explain that to me)? How is > this "making it easy to derive from this class to add new kinds of > conversion" comment meant? > > Best regards > Stephan -- Claus Ibsen ----------------- Red Hat, Inc. Email: cib...@redhat.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen hawtio: http://hawt.io/ fabric8: http://fabric8.io/