@FallbackConverter
public static <T> T convertTo(Class<T> type, Exchange exchange, Object value, TypeConverterRegistry registry) {
// use fallback type converter, so we can probably convert into
// CxfPayloads from other types
if (type.isAssignableFrom(CxfPayload.class)) {
TypeConverter tc = registry.lookup(NodeList.class, value.getClass());
if (tc != null) {
NodeList nodeList = tc.convertTo(NodeList.class, exchange, value);
return (T) nodeListToCxfPayload(nodeList, exchange);
}
tc = registry.lookup(Document.class, value.getClass());
if (tc != null) {
Document document = tc.convertTo(Document.class, exchange, value);
return (T) documentToCxfPayload(document, exchange);
}
// maybe we can convert via an InputStream
CxfPayload<?> p = null;
p = convertVia(InputStream.class, exchange, value, registry);
if (p != null) {
return (T) p;
}
// String is the converter of last resort
p = convertVia(String.class, exchange, value, registry);
if (p != null) {
return (T) p;
}
}
// Convert a CxfPayload into something else
if (CxfPayload.class.isAssignableFrom(value.getClass())) {
TypeConverter tc = registry.lookup(type, NodeList.class);
if (tc != null) {
return tc.convertTo(type, cxfPayloadToNodeList((CxfPayload<?>) value, exchange));
}
// we cannot convert a node list, so we try the first item from the
// node list
tc = registry.lookup(type, Node.class);
if (tc != null) {
NodeList nodeList = cxfPayloadToNodeList((CxfPayload<?>) value, exchange);
if (nodeList.getLength() > 0) {
return tc.convertTo(type, nodeList.item(0));
}
}
}
return null;
}