camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Siano, Stephan" <>
Subject Question about type converter logic
Date Tue, 13 Jan 2015 07:12:22 GMT

I am trying to figure out how to write a type converter that can convert e.g. from
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).
    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

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

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message