public void writeMethodInWrapper(MethodInfo minfo)
throws WrapperFault, IOException
{
Type type;
boolean isAllTreatedAsOutParams = false;
ParameterInfo returntype = null;
int noOfOutParams = minfo.getOutputParameterTypes().size();
if (0 == noOfOutParams)
{
returntype = null;
}
else
{
if (1 == noOfOutParams)
{
returntype =
(ParameterInfo) minfo
.getOutputParameterTypes()
.iterator()
.next();
}
else
{
isAllTreatedAsOutParams = true;
}
}
Collection params = minfo.getInputParameterTypes();
String methodName = minfo.getMethodname();
Type retType = null;
String outparamType = null;
String outparamTypeName = null;
boolean returntypeissimple = false;
boolean returntypeisarray = false;
if (returntype != null)
{
outparamTypeName =
WrapperUtils.getClassNameFromParamInfoConsideringArrays(
returntype,
wscontext);
retType =
wscontext.getTypemap().getType(returntype.getSchemaName());
if (retType != null)
{
returntypeisarray = retType.isArray();
if (CUtils.isSimpleType(retType.getLanguageSpecificName()))
{
returntypeissimple = true;
}
}
}
writer.write("\n/*\n");
writer.write(" * This method wrap the service method \n");
writer.write(" */\n");
//method signature
writer.write(
"int " + classname + "::" + methodName + "(void* pMsg)\n{\n");
writer.write("\tIMessageData* mc = (IMessageData*)pMsg;\n");
writer.write("\tint nStatus;\n");
writer.write("\tIWrapperSoapSerializer* pIWSSZ = NULL;\n");
writer.write("\tmc->getSoapSerializer(&pIWSSZ);\n");
writer.write("\tif (!pIWSSZ) return AXIS_FAIL;\n");
writer.write("\tIWrapperSoapDeSerializer* pIWSDZ = NULL;\n");
writer.write("\tmc->getSoapDeSerializer(&pIWSDZ);\n");
writer.write("\tif (!pIWSDZ) return AXIS_FAIL;\n");
writer.write("\t/* check whether we have got correct message */\n");
writer.write(
"\tif (AXIS_SUCCESS != pIWSDZ->checkMessageBody(\""
+ minfo.getMethodname()
+ "\", \""
+ wscontext.getWrapInfo().getTargetNameSpaceOfWSDL()
+ "\")) return AXIS_FAIL;\n");
writer.write(
"\tpIWSSZ->createSoapMethod(\""
+ minfo.getMethodname()
+ "Response\", \""
+ wscontext.getWrapInfo().getTargetNameSpaceOfWSDL()
+ "\");\n");
//create and populate variables for each parameter
String paraTypeName;
String parameterName;
String returnParamName;
String paramType;
ArrayList paramsB = new ArrayList(params);
for (int i = 0; i < paramsB.size(); i++)
{
paraTypeName = ((ParameterInfo) paramsB.get(i)).getLangName();
paramType =
WrapperUtils.getClassNameFromParamInfoConsideringArrays(
(ParameterInfo) paramsB.get(i),
wscontext);
parameterName = ((ParameterInfo) paramsB.get(i)).getParamName();
if ((CUtils
.isSimpleType(((ParameterInfo) paramsB.get(i)).getLangName())))
{
//for simple types
writer.write(
"\t"
+ paraTypeName
+ " v"
+ i
+ " = pIWSDZ->"
+ CUtils.getParameterGetValueMethodName(
paraTypeName,
false)
+ "(\""
+ parameterName
+ "\",0);\n");
}
else
if ((type =
this.wscontext.getTypemap().getType(
((ParameterInfo) paramsB.get(i)).getSchemaName()))
!= null
&& type.isArray())
{
QName qname = WrapperUtils.getArrayType(type).getName();
String containedType = null;
if (CUtils.isSimpleType(qname))
{
containedType = CUtils.getclass4qname(qname);
writer.write(
"\t"
+ paramType
+ " v"
+ i
+ " = ("
+ CUtils.getBasicArrayNameforType(containedType)
+ "&)pIWSDZ->getBasicArray("
+ CUtils.getXSDTypeForBasicType(containedType)
+ ", \""
+ parameterName
+ "\",0);\n");
}
else
{
containedType = qname.getLocalPart();
writer.write(
"\t"
+ paramType
+ " v"
+ i
+ " = ("
+ paramType
+ "&)pIWSDZ->getCmplxArray((void*)Axis_DeSerialize_"
+ containedType
+ "\n\t\t, (void*)Axis_Create_"
+ containedType
+ ", (void*)Axis_Delete_"
+ containedType
+ "\n\t\t, (void*)Axis_GetSize_"
+ containedType
+ ", \""
+ parameterName
+ "\", Axis_URI_"
+ containedType
+ ");\n");
}
}
else
{
//for complex types
writer.write(
"\t"
+ paraTypeName
+ " *v"
+ i
+ " = ("
+ paraTypeName
+ "*)pIWSDZ->getCmplxObject((void*)Axis_DeSerialize_"
+ paraTypeName
+ "\n\t\t, (void*)Axis_Create_"
+ paraTypeName
+ ", (void*)Axis_Delete_"
+ paraTypeName
+ "\n\t\t, \""
+ parameterName
+ "\", Axis_URI_"
+ paraTypeName
+ ");\n");
}
}
writer.write(
"\tif (AXIS_SUCCESS != (nStatus = pIWSDZ->getStatus())) return nStatus;\n");
// Multiples parameters so fill the methods prototype
if (isAllTreatedAsOutParams)
{
ArrayList paramsC = (ArrayList) minfo.getOutputParameterTypes();
for (int i = 0; i < paramsC.size(); i++)
{
type =
wscontext.getTypemap().getType(
((ParameterInfo) paramsC.get(i)).getSchemaName());
writer.write(
"\t"
+ WrapperUtils
.getClassNameFromParamInfoConsideringArrays(
(ParameterInfo) paramsC.get(i),
wscontext)
+ " out"
+ i
+ ";\n");
}
}
writer.write("\ttry\n\t{\n");
if (returntype != null)
{
/* Invoke the service when return type not void */
writer.write(
"\t\t"
+ outparamTypeName
+ " ret = "
+ "pWs->"
+ methodName
+ "(");
if (0 < paramsB.size())
{
for (int i = 0; i < paramsB.size() - 1; i++)
{
writer.write("v" + i + ",");
}
writer.write("v" + (paramsB.size() - 1));
}
writer.write(");\n");
/* set the result */
if (returntypeissimple)
{
writer.write(
"\t\treturn pIWSSZ->addOutputParam(\""
+ methodName
+ "Return\", (void*)&ret, "
+ CUtils.getXSDTypeForBasicType(outparamTypeName)
+ ");\n");
}
else
if (returntypeisarray)
{
QName qname = WrapperUtils.getArrayType(retType).getName();
String containedType = null;
if (CUtils.isSimpleType(qname))
{
containedType = CUtils.getclass4qname(qname);
writer.write(
"\t\treturn pIWSSZ->addOutputBasicArrayParam((Axis_Array*)(&ret),"
+ CUtils.getXSDTypeForBasicType(containedType)
+ ", \""
+ methodName
+ "Return\");\n");
}
else
{
containedType = qname.getLocalPart();
writer.write(
"\t\treturn pIWSSZ->addOutputCmplxArrayParam((Axis_Array*)(&ret),"
+ "(void*) Axis_Serialize_"
+ containedType
+ ", (void*) Axis_Delete_"
+ containedType
+ ", (void*) Axis_GetSize_"
+ containedType
+ ", \""
+ methodName
+ "Return\", Axis_URI_"
+ containedType
+ ");\n");
}
}
else
{
//complex type
outparamTypeName = returntype.getLangName();
//need to have complex type name without *
writer.write(
"\t\treturn pIWSSZ->addOutputCmplxParam(ret, (void*)Axis_Serialize_"
+ outparamTypeName
+ ", (void*)Axis_Delete_"
+ outparamTypeName
+ ", \""
+ methodName
+ "Return\", Axis_URI_"
+ outparamTypeName
+ ");\n");
}
}
else
if (isAllTreatedAsOutParams)
{
writer.write("\t\tpWs->" + methodName + "(");
if (0 < paramsB.size())
{
for (int i = 0; i < paramsB.size(); i++)
{
writer.write("v" + i + ",");
}
}
ArrayList paramsC = (ArrayList) minfo.getOutputParameterTypes();
for (int i = 0; i < paramsC.size() - 1; i++)
{
writer.write("&out" + i + ",");
}
writer.write("&out" + (paramsC.size() - 1));
writer.write(");\n");
paramsC = (ArrayList) minfo.getOutputParameterTypes();
for (int i = 0; i < paramsC.size(); i++)
{
retType =
wscontext.getTypemap().getType(
((ParameterInfo) paramsC.get(i)).getSchemaName());
if (retType != null)
{
outparamType = retType.getLanguageSpecificName();
returntypeisarray = retType.isArray();
}
else
{
outparamType = returntype.getLangName();
}
returntypeissimple = CUtils.isSimpleType(outparamType);
returnParamName =
((ParameterInfo) paramsC.get(i)).getParamName();
if (returntypeissimple)
{
writer.write(
"\t\tpIWSSZ->addOutputParam(\""
+ returnParamName
+ "\", (void*)&out"
+ i
+ ", "
+ CUtils.getXSDTypeForBasicType(outparamType)
+ ");\n");
}
else
if (returntypeisarray)
{
QName qname =
WrapperUtils.getArrayType(retType).getName();
String containedType = null;
if (CUtils.isSimpleType(qname))
{
containedType = CUtils.getclass4qname(qname);
writer.write(
"\t\tpIWSSZ->addOutputBasicArrayParam((Axis_Array*)(&out"
+ i
+ "),"
+ CUtils.getXSDTypeForBasicType(
containedType)
+ ", \""
+ returnParamName
+ "\");\n");
}
else
{
containedType = qname.getLocalPart();
writer.write(
"\t\tpIWSSZ->addOutputCmplxArrayParam((Axis_Array*)(&out"
+ i
+ "),"
+ "(void*) Axis_Serialize_"
+ containedType
+ ", (void*) Axis_Delete_"
+ containedType
+ ", (void*) Axis_GetSize_"
+ containedType
+ ", \""
+ returnParamName
+ "\", Axis_URI_"
+ containedType
+ ");\n");
}
}
else
{
//complex type
writer.write(
"\t\tpIWSSZ->addOutputCmplxParam(out"
+ i
+ ", (void*)Axis_Serialize_"
+ outparamType
+ ", (void*)Axis_Delete_"
+ outparamType
+ ", \""
+ returnParamName
+ "\", Axis_URI_"
+ outparamType
+ ");\n");
}
}
writer.write("\treturn AXIS_SUCCESS;\n");
}
else
{ //method does not return anything
/* Invoke the service when return type is void */
writer.write("\t\tpWs->" + methodName + "(");
if (0 < paramsB.size())
{
for (int i = 0; i < paramsB.size() - 1; i++)
{
writer.write("v" + i + ",");
}
writer.write("v" + (paramsB.size() - 1));
}
writer.write(");\n");
writer.write("\treturn AXIS_SUCCESS;\n");
}
writer.write("\t}\n"); //nithya
Iterator paramsFault = minfo.getFaultType().iterator();
String faultInfoName = null;
String faultType = null;
String langName = null;
String paramName = null;
while (paramsFault.hasNext())
{
FaultInfo info = (FaultInfo) paramsFault.next();
faultInfoName = info.getFaultInfo();
ArrayList paramInfo = info.getParams();
for (int i = 0; i < paramInfo.size(); i++)
{
ParameterInfo par = (ParameterInfo) paramInfo.get(i);
paramName = par.getParamName();
langName = par.getLangName();
faultType =
WrapperUtils.getClassNameFromParamInfoConsideringArrays(
par,
wscontext);
writeExceptions(faultType, faultInfoName, paramName, langName);