Hi,
I have written some extension for the XPathBuilder (
https://issues.apache.org/jira/browse/CAMEL-8273 ). While doing so, I stumbled
over the following code:
// okay we can try to remedy the failed conversion by some special types
if (answer == null) {
// let's try coercing some common types into something JAXP work
with the best for special types
if (body instanceof WrappedFile) {
// special for files so we can work with them out of the box
InputStream is =
exchange.getContext().getTypeConverter().convertTo(InputStream.class, exchange,
body);
answer = new InputSource(is);
} else if (body instanceof BeanInvocation) {
// if its a null bean invocation then handle that specially
BeanInvocation bi =
exchange.getContext().getTypeConverter().convertTo(BeanInvocation.class,
exchange, body);
if (bi.getArgs() != null && bi.getArgs().length == 1 &&
bi.getArgs()[0] == null) {
// its a null argument from the bean invocation so use null
as answer
answer = null;
}
} else if (body instanceof String) {
answer = new InputSource(new StringReader((String) body));
}
}
The stuff for WrappedFile and String makes sense, but I actually don't
understand the coding for the BeanInvocation body:
If the body is already of type BeanInvocation why using a type converter to
convert it to BeanInvocation (wouldn't a cast be sufficient)?
If the bean invocation has exactly one argument and that is null, the answer is
set to null (but if this code is reached it is already null).
>From my perspective the " else if (body instanceof BeanInvocation) " branch
>can be removed without losing any functionality. Do I miss some side effect
>there?
Best regards
Stphan