* @throws IOException
*/
public void writeMethodInWrapper(MethodInfo minfo) throws WrapperFault,IOException {
boolean isAllTreatedAsOutParams = false;
ParameterInfo returntype = null;
ParameterInfo returntype1 = 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;
boolean returntypeissimple = false;
boolean returntypeisarray = false;
String outparamTypeName = null;
if (returntype != null){
outparamTypeName = WrapperUtils.getClassNameFromParamInfoConsideringArrays(returntype, wscontext);
retType = wscontext.getTypemap().getType(returntype.getSchemaName());
if (retType != null){
returntypeisarray = retType.isArray();
if (WSDL2Ws.verbose)
System.out.println(retType.getLanguageSpecificName()+"LanguageName .................... ");
if (CUtils.isSimpleType(retType.getLanguageSpecificName())){
returntypeissimple = true;
}
}
}
writer.write("\n/*\n");
writer.write(" * This method wrap the service method "+ methodName +"\n");
writer.write(" */\n");
//method signature
String paramTypeName;
boolean typeisarray = false;
boolean typeissimple = false;
Type type;
if (returntype == null){
writer.write("void");
}else{
writer.write(outparamTypeName);
if (WSDL2Ws.verbose)
System.out.println("Output Parameter type Name :"+outparamTypeName);
}
writer.write(" "+classname+"::" + methodName + "(");
ArrayList paramsB = (ArrayList)params;
for (int i = 0; i < paramsB.size(); i++) {
paramTypeName = WrapperUtils.getClassNameFromParamInfoConsideringArrays((ParameterInfo)paramsB.get(i), wscontext);
if (i>0) writer.write(", ");
writer.write(paramTypeName+" Value"+i);
}
// Multiples parameters so fill the methods prototype
ArrayList paramsC = (ArrayList)minfo.getOutputParameterTypes();
if ( isAllTreatedAsOutParams ) {
String currentParaTypeName;
for (int i = 0; i < paramsC.size(); i++) {
type = wscontext.getTypemap().getType(((ParameterInfo)paramsC.get(i)).getSchemaName());
writer.write(", AXIS_OUT_PARAM "+WrapperUtils.getClassNameFromParamInfoConsideringArrays((ParameterInfo)paramsC.get(i),wscontext)+" *OutValue"+i);
}
}
writer.write(")\n{\n");
if (returntype != null){
writer.write("\t");
if(returntypeisarray){
//for arrays
writer.write(outparamTypeName+" RetArray = {NULL, 0};\n");
}else if(!returntypeissimple){
writer.write(outparamTypeName+" pReturn = NULL;\n");
//for complex types
}else{
//for simple types
String initValue = CUtils.getInitValue(outparamTypeName);
if (initValue != null)
writer.write(outparamTypeName+" Ret = " + initValue + ";\n");
else if (outparamTypeName.equals("xsd__base64Binary") || outparamTypeName.equals("xsd__hexBinary"))
{
writer.write(outparamTypeName+" Ret;\n");
writer.write("\tRet.__ptr = NULL;\n");
writer.write("\tRet.__size = 0;\n");
}
else
writer.write(outparamTypeName+" Ret;\n");
//TODO initialize return parameter appropriately.
}
}
String channelSecurityType = (WrapperConstants.CHANNEL_SECURITY_SSL.equals(wscontext.getWrapInfo().getChannelSecurity()))?
"SSL_CHANNEL" : "NORMAL_CHANNEL";
//writer.write("\tchar* cFaultcode;\n");
//writer.write("\tchar* cFaultstring;\n");
//writer.write("\tchar* cFaultactor;\n");
writer.write("\tconst char* pcCmplxFaultName;\n");
writer.write("\ttry\n\t{");
writer.write("\n\t\tif (AXIS_SUCCESS != m_pCall->initialize(CPP_RPC_PROVIDER, "+channelSecurityType +")) \n\t\t\treturn ");//damitha
if (returntype != null){
writer.write((returntypeisarray?"RetArray":returntypeissimple?"Ret":"pReturn")+";\n");
}
else{
writer.write(";\n");
}
writer.write("\t\tm_pCall->setTransportProperty(SOAPACTION_HEADER , \""+minfo.getSoapAction()+"\");\n");
writer.write("\t\tm_pCall->setSOAPVersion(SOAP_VER_1_1);\n"); //TODO check which version is it really.
writer.write("\t\tm_pCall->setOperation(\""+minfo.getMethodname()+"\", \""+wscontext.getWrapInfo().getTargetNameSpaceOfWSDL()+"\");\n");
writer.write("\t\tapplyUserPreferences();\n");
for (int i = 0; i < paramsB.size(); i++) {
type = wscontext.getTypemap().getType(((ParameterInfo)paramsB.get(i)).getSchemaName());
if (type != null){
paramTypeName = type.getLanguageSpecificName();
typeisarray = type.isArray();
}
else {
paramTypeName = ((ParameterInfo)paramsB.get(i)).getLangName();
typeisarray = false;
}
typeissimple = CUtils.isSimpleType(paramTypeName);
if(typeisarray){
//arrays
QName qname = WrapperUtils.getArrayType(type).getName();
String containedType = null;
if (CUtils.isSimpleType(qname)){
containedType = CUtils.getclass4qname(qname);
writer.write("\tm_pCall->addBasicArrayParameter(");
writer.write("(Axis_Array*)(&Value"+i+"), "+CUtils.getXSDTypeForBasicType(containedType)+", \""+((ParameterInfo)paramsB.get(i)).getParamName()+"\"");
}
else{
containedType = qname.getLocalPart();
writer.write("\tm_pCall->addCmplxArrayParameter(");
writer.write("(Axis_Array*)(&Value"+i+"), (void*)Axis_Serialize_"+containedType+", (void*)Axis_Delete_"+containedType+", (void*) Axis_GetSize_"+containedType+", \""+((ParameterInfo)paramsB.get(i)).getParamName()+"\", Axis_URI_"+containedType);
}
}else if(typeissimple){
//for simple types
writer.write("\t\tm_pCall->addParameter(");
writer.write("(void*)&Value"+i+", \"" + ((ParameterInfo)paramsB.get(i)).getParamName()+"\", "+CUtils.getXSDTypeForBasicType(paramTypeName));
}else{
//for complex types
writer.write("\tm_pCall->addCmplxParameter(");
writer.write("Value"+i+", (void*)Axis_Serialize_"+paramTypeName+", (void*)Axis_Delete_"+paramTypeName+", \"" + ((ParameterInfo)paramsB.get(i)).getParamName()+"\", Axis_URI_"+paramTypeName);
}
writer.write(");\n");
}
writer.write("\t\tif (AXIS_SUCCESS == m_pCall->invoke())\n\t\t{\n");
writer.write("\t\t\tif(AXIS_SUCCESS == m_pCall->checkMessage(\""+minfo.getOutputMessage().getLocalPart()+"\", \""+wscontext.getWrapInfo().getTargetNameSpaceOfWSDL()+"\"))\n\t\t\t{\n");
if ( isAllTreatedAsOutParams) {
String currentParamName;
String currentParaType;
for (int i = 0; i < paramsC.size(); i++) {
ParameterInfo currentType = (ParameterInfo)paramsC.get(i);
type = wscontext.getTypemap().getType(currentType.getSchemaName());
if (type != null){
currentParaType = type.getLanguageSpecificName();
typeisarray = type.isArray();
}
else {
currentParaType = ((ParameterInfo)paramsC.get(i)).getLangName();
typeisarray = false;
}
typeissimple = CUtils.isSimpleType(currentParaType);
currentParamName = "*OutValue"+i;
// Some code need to be merged as we have some duplicated in coding here.
if (typeisarray){
QName qname = WrapperUtils.getArrayType(type).getName();
String containedType = null;
if (CUtils.isSimpleType(qname)){
containedType = CUtils.getclass4qname(qname);
writer.write("\t\t\t\t" + currentParamName + " = ("+currentParaType+"&)m_pCall->getBasicArray("+CUtils.getXSDTypeForBasicType(containedType)+", \""+currentType.getParamName()+"\", 0);\n");
}
else{
containedType = qname.getLocalPart();
writer.write("\t\t\t\t" + currentParamName + " = ("+currentParaType+"&)m_pCall->getCmplxArray((void*) Axis_DeSerialize_"+containedType);
writer.write("\t\t\t\t, (void*) Axis_Create_"+containedType+", (void*) Axis_Delete_"+containedType+", (void*) Axis_GetSize_"+containedType+", \""+currentType.getParamName()+"\", Axis_URI_"+containedType+");\n");
}
}
else if(typeissimple){
writer.write("\t\t\t\t" + currentParamName + " = m_pCall->"+ CUtils.getParameterGetValueMethodName(currentParaType, false)+"(\""+currentType.getParamName()+"\", 0);\n");
}
else{
writer.write("\t\t\t\t" + currentParamName + " = ("+currentParaType+"*)m_pCall->getCmplxObject((void*) Axis_DeSerialize_"+currentParaType+", (void*) Axis_Create_"+currentParaType+", (void*) Axis_Delete_"+currentParaType+",\""+currentType.getParamName()+"\", 0);\n");
}
}
writer.write("\t\t\t}\n");
writer.write("\t\t}\n\t\tm_pCall->unInitialize();\n");
}
else if (returntype == null){
writer.write("\t\t\t/*not successful*/\n\t\t}\n");
writer.write("\t\t}\n\t\tm_pCall->unInitialize();\n");
}
else if (returntypeisarray){
QName qname = WrapperUtils.getArrayType(retType).getName();
String containedType = null;
if (CUtils.isSimpleType(qname)){
containedType = CUtils.getclass4qname(qname);
writer.write("\t\t\t\tRetArray = ("+outparamTypeName+"&)m_pCall->getBasicArray("+CUtils.getXSDTypeForBasicType(containedType)+", \""+returntype.getParamName()+"\", 0);\n\t\t\t}\n");
}
else{
containedType = qname.getLocalPart();
writer.write("\t\t\t\tRetArray = ("+outparamTypeName+"&)m_pCall->getCmplxArray((void*) Axis_DeSerialize_"+containedType);//damitha
writer.write(", (void*) Axis_Create_"+containedType+", (void*) Axis_Delete_"+containedType+", (void*) Axis_GetSize_"+containedType+", \""+returntype.getParamName()+"\", Axis_URI_"+containedType+");\n\t\t\t}\n");
}
writer.write("\t\t}\n\t\tm_pCall->unInitialize();\n");
writer.write("\t\treturn RetArray;\n");
}
else if(returntypeissimple){
writer.write("\t\t\t\tRet = m_pCall->"+ CUtils.getParameterGetValueMethodName(outparamTypeName, false)+"(\""+returntype.getParamName()+"\", 0);\n\t\t\t}\n");
writer.write("\t\t}\n\t\tm_pCall->unInitialize();\n");
writer.write("\t\treturn Ret;\n");
}
else{
outparamTypeName = returntype.getLangName();//need to have complex type name without *
writer.write("\t\t\t\tpReturn = ("+outparamTypeName+"*)m_pCall->getCmplxObject((void*) Axis_DeSerialize_"+outparamTypeName+", (void*) Axis_Create_"+outparamTypeName+", (void*) Axis_Delete_"+outparamTypeName+",\""+returntype.getParamName()+"\", 0);\n\t\t}\n");
writer.write("\t\t}\n\t\tm_pCall->unInitialize();\n");
writer.write("\t\treturn pReturn;\n");
}
//added by nithya
writer.write("\t}\n");
writer.write("\tcatch(AxisException& e)\n\t{\n");
writer.write("\t\tint iExceptionCode = e.getExceptionCode();\n");
writer.write("\t\tif(AXISC_NODE_VALUE_MISMATCH_EXCEPTION != iExceptionCode)\n");
writer.write("\t\t{\n");
writer.write("\t\t\tm_pCall->unInitialize();\n");
writer.write("\t\t\tthrow " + wscontext.getSerInfo().getServicename() + "_AxisClientException(e.what());\n");
writer.write("\t\t}\n");
//ISoapFault* pSoapFault = (ISoapFault*) m_pCall->checkFault("Fault", "http://localhost/axis/MathOps");
writer.write("\t\tISoapFault* pSoapFault = (ISoapFault*) m_pCall->checkFault(\"Fault\",\""+wscontext.getWrapInfo().getTargetEndpointURI()+"\" );\n");
writer.write("\t\tif(pSoapFault)\n");
writer.write("\t\t{\n");
//writer.write("\t\t\tpcCmplxFaultName = pSoapFault->getCmplxFaultObjectName().c_str();\n");
//to get fault info
Iterator paramsFault = minfo.getFaultType().iterator();
String faultInfoName =null;
String faultType =null;
String langName =null;
String paramName =null;
boolean flag =false;
int j =0;
if (!paramsFault.hasNext())
{
writer.write("\t\t\tm_pCall->unInitialize();\n");
writer.write("\t\t\tthrow " + wscontext.getSerInfo().getServicename() + "_AxisClientException(pSoapFault);\n");
}
else
{
flag =true;
writer.write("\t\t\tpcCmplxFaultName = pSoapFault->getCmplxFaultObjectName().c_str();\n");
}
while (paramsFault.hasNext()){
j =j+1;
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);
if ( j > 1){
writer.write("\t\t\telse if");
writeExceptions(faultType,faultInfoName,paramName,langName);
}