ServiceDescription serviceDescription = getRegistry(context).getServiceDescription(serviceName);
/*
* Input
*/
ParameterContextImpl inputParam = new ParameterContextImpl();
ServiceDescriptionType serviceDescriptionType = serviceDescription.getType();
for (Parameter parameter : serviceDescriptionType.getInputParametersArray()) {
OMElement element = input.getFirstChildWithName(new QName(null,parameter.getParameterName()));
if (element == null) {
throw new Exception("Parameter is not found in the message");
}
//todo this implementation doesn't work when there are n number of nodes connecting .. need to fix
// String xmlContent = "";
// if(!element.getChildElements().hasNext()){
// xmlContent = "<type:GFacParameter xsi:type=\"type:" + MappingFactory.getActualParameterType(parameter.getParameterType().getType())
// +"\" xmlns:type=\"http://schemas.airavata.apache.org/gfac/type\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + element.getText() + "</type:GFacParameter>";
// }else{
// xmlContent = "<type:GFacParameter xsi:type=\"type:" + MappingFactory.getActualParameterType(parameter.getParameterType().getType())
// +"\" xmlns:type=\"http://schemas.airavata.apache.org/gfac/type\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + element.toStringWithConsume() + "</type:GFacParameter>";
// }
// System.out.println(xmlContent);
// inputParam.add(parameter.getParameterName(),ActualParameter.fromXML(xmlContent));
ActualParameter actualParameter = getInputActualParameter(parameter, element);
inputParam.add(parameter.getParameterName(),actualParameter);
}
/*
* Output
*/
ParameterContextImpl outputParam = new ParameterContextImpl();
// List<Parameter> outputs = serviceDescription.getOutputParameters();
for (OutputParameterType parameter : serviceDescriptionType.getOutputParametersArray()) {
ActualParameter actualParameter = new ActualParameter();
if("String".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(StringParameterType.type);
}else if("Double".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(DoubleParameterType.type);
}else if("Integer".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(IntegerParameterType.type);
}else if("Float".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(FloatParameterType.type);
}else if("Boolean".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(BooleanParameterType.type);
}else if("File".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(FileParameterType.type);
}else if("URI".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(URIParameterType.type);
}else if("StringArray".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(StringArrayType.type);
}else if("DoubleArray".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(DoubleArrayType.type);
}else if("IntegerArray".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(IntegerArrayType.type);
}else if("FloatArray".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(FloatArrayType.type);
}else if("BooleanArray".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(BooleanArrayType.type);
}else if("FileArray".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(FileArrayType.type);
}else if("URIArray".equals(parameter.getParameterType().getName())){
actualParameter.getType().changeType(URIArrayType.type);
}
outputParam.add(parameter.getParameterName(), new ActualParameter());
}
invocationContext.setInput(inputParam);
invocationContext.setOutput(outputParam);
if (service == null) {
service = new PropertyServiceFactory(GFacService.REPOSITORY_PROPERTIES).createService();
}
// invoke service
service.execute(invocationContext);
/*
* Process Output
*/
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://ws.apache.org/axis2/xsd", "ns1");
outputElement = fac.createOMElement("invokeResponse", omNs);
ParameterContextImpl paramContext = (ParameterContextImpl) invocationContext
.<ActualParameter> getMessageContext("output");
for (Iterator<String> iterator = paramContext.getNames(); iterator.hasNext();) {
String name = iterator.next();
String outputString = paramContext.getValue(name).toXML().replaceAll("GFacParameter", name);
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(outputString));
StAXOMBuilder builder = new StAXOMBuilder(reader);
outputElement.addChild(builder.getDocumentElement());
}