Hi Claus,

Sure, I will contribute the converter to camel-saxon, once I get it running, 
but at least in my unit test it never gets executed (so I obviously do 
something wrong). How is type converter selection done?

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.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/

Reply via email to