//*/
callLoop:
for (int callNum = 0; callNum < calls.getCallCount(); callNum++)
{
Call call = calls.getCall(callNum);
try
{
InboundContext inctx = batch.getInboundContexts().get(callNum);
// Get a list of the available matching methods with the coerced
// parameters that we will use to call it if we choose to use
// that method.
// Which method are we using?
call.findMethod(moduleManager, converterManager, inctx, callNum);
MethodDeclaration method = call.getMethodDeclaration();
if (method == null)
{
log.warn("No methods to match " + call.getScriptName() + '.' + call.getMethodName());
throw new IllegalArgumentException("Missing method or missing parameter converters");
}
// We are now sure we have the set of inputs lined up. They may
// cross-reference so we do the de-referencing all in one go.
// TODO: should we do this here? - why not earlier?
// do we need to know the method before we dereference?
inctx.dereference();
// Convert all the parameters to the correct types
int destParamCount = method.getParameterTypes().length;
Object[] arguments = new Object[destParamCount];
int inboundArgIndex = 0;
for (int outboundArgIndex = 0; outboundArgIndex < destParamCount; outboundArgIndex++)
{
InboundVariable param;
if (method.isVarArgs() && outboundArgIndex + 1 == destParamCount)
{
param = inctx.createArrayWrapper(callNum, destParamCount);
}
else
{
param = inctx.getParameter(callNum, inboundArgIndex);
}
Property property = new ParameterProperty(method, outboundArgIndex);
// TODO: Having just got a property, shouldn't we call property.getPropertyType() in place of this?
Class<?> paramType = method.getParameterTypes()[outboundArgIndex];
try
{
arguments[outboundArgIndex] = converterManager.convertInbound(paramType, param, property);
}
catch (Exception ex)
{
log.debug("Problem converting param=" + param + ", property=" + property + ", into paramType=" + paramType.getName() + ": " + ex);
throw ex;
}
// Only increment the inboundArgIndex if the parameterType of the destination method is not
// a Servlet class. // In this case the arguments value is auto-populated by DWR and a place-holder
// argument is not passed from the client.
if (!LocalUtil.isServletClass(paramType)) {
inboundArgIndex++;
}
}
call.setParameters(arguments);
}
catch (Exception ex)
{
log.debug("Marshalling exception", ex);
call.setMarshallFailure(ex);
continue callLoop;
}
}
return calls;