Object msg = context.getMessage().getPayload();
double data = NumberUtils.toDouble(msg);
if (data == NumberUtils.DOUBLE_ERROR)
{
throw new TransformerException(MessageFactory.createStaticMessage("Unable to convert message to double: " + msg));
}
if (operation.equalsIgnoreCase("add"))
{
accumulatedValue += data;
}
else if (operation.equalsIgnoreCase("subtract"))
{
accumulatedValue -= data;
}
else if (operation.equalsIgnoreCase("multiply"))
{
accumulatedValue *= data;
}
else if (operation.equalsIgnoreCase("divide"))
{
accumulatedValue /= data;
}
else
{
throw new TransformerException(MessageFactory.createStaticMessage("Operation " + operation + " not recognized"));
}
// no auto-boxing
return new Double(accumulatedValue);
}