protected Map<String, Object> getContext(XmlRpcRequest xmlRpcReq, String serviceName) throws XmlRpcException {
ModelService model;
try {
model = dispatcher.getDispatchContext().getModelService(serviceName);
} catch (GenericServiceException e) {
throw new XmlRpcException(e.getMessage(), e);
}
// context placeholder
Map<String, Object> context = FastMap.newInstance();
if (model != null) {
int parameterCount = xmlRpcReq.getParameterCount();
// more than one parameter; use list notation based on service def order
if (parameterCount > 1) {
int x = 0;
for (String name: model.getParameterNames("IN", true, true)) {
context.put(name, xmlRpcReq.getParameter(x));
x++;
if (x == parameterCount) {
break;
}
}
// only one parameter; if its a map use it as the context; otherwise make sure the service takes one param
} else if (parameterCount == 1) {
Object param = xmlRpcReq.getParameter(0);
if (param instanceof Map) {
context = checkMap(param, String.class, Object.class);
} else {
if (model.getDefinedInCount() == 1) {
String paramName = (String) model.getInParamNames().iterator().next();
context.put(paramName, xmlRpcReq.getParameter(0));
} else {
throw new XmlRpcException("More than one parameter defined on service; cannot call via RPC with parameter list");
}
}
}
// do map value conversions