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