* @see org.apache.airavata.xbaya.test.service.arrayadder.ArrayAdder#add(org.xmlpull.v1.builder.XmlElement)
*/
public XmlElement add(XmlElement inputElement) {
logger.info(XMLUtil.xmlElementToString(inputElement));
ServiceNotificationSender notifier = ServiceNotificationSender.invoked(inputElement);
XmlElement arrayElement = inputElement.requiredElement(null, "input");
int sum = 0;
@SuppressWarnings("rawtypes")
Iterator valueIt = arrayElement.elements(null, "value").iterator();
while (valueIt.hasNext()) {
XmlElement valueElement = (XmlElement) valueIt.next();
String valueString = valueElement.requiredTextContent();
int value = Integer.parseInt(valueString);
sum += value;
}
Random random = new Random();
int msec = random.nextInt(5000);
logger.info("Sleep for " + msec + " msec");
try {
Thread.sleep(msec);
} catch (InterruptedException e) {
logger.error(e.getMessage(), e);
}
String sumString = "" + sum;
XmlNamespace namespace = XmlConstants.BUILDER.newNamespace("typens",
"http://www.extreme.indiana.edu/math/arrayadder/xsd/");
XmlElement outputElement = XmlConstants.BUILDER.newFragment(namespace, "ArrayAdderOutput");
XmlElement sumElement = outputElement.addElement("sum");
sumElement.addChild(sumString);
if (notifier != null) {
notifier.sendingResult(outputElement);
}
logger.info(XMLUtil.xmlElementToString(outputElement));
return outputElement;
}