*/
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;
boolean returntypeissimple = false;
boolean returntypeisarray = false;
if (returntype != null){
retType = wscontext.getTypemap().getType(returntype.getSchemaName());
if (retType != null){
if (retType.isSimpleType()){ //schema defined simpleType possibly with restrictions
returntypeissimple = true;
outparamType = CUtils.getclass4qname(retType.getBaseType());
}
else{
outparamType = retType.getLanguageSpecificName();
returntypeisarray = retType.isArray();
returntypeissimple = CUtils.isSimpleType(outparamType);
}
}
else{
outparamType = returntype.getLangName();
returntypeissimple = CUtils.isSimpleType(outparamType);
}
}
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.getInputMessage().getLocalPart()+"\", \""+minfo.getInputMessage().getNamespaceURI()+"\")) return AXIS_FAIL;\n");
if(minfo.getOutputMessage()!=null)
writer.write("\tpIWSSZ->createSoapMethod(\""+minfo.getOutputMessage().getLocalPart()+"\", \""+minfo.getOutputMessage().getNamespaceURI()+"\");\n");
//create and populate variables for each parameter
String paraTypeName;
String parameterName;
String elementName;
String returnParamName;
ArrayList paramsB = new ArrayList(params);
for (int i = 0; i < paramsB.size(); i++) {
ParameterInfo param = (ParameterInfo)paramsB.get(i);
type = this.wscontext.getTypemap().getType(param.getSchemaName());
if (type != null && type.isSimpleType()){ //schema defined simpleType possibly with restrictions
paraTypeName = CUtils.getclass4qname(type.getBaseType());;
}
else{
paraTypeName = param.getLangName();
}
parameterName = param.getParamName();
elementName = param.getElementName().getLocalPart();
if (type != null && type.isSimpleType()){ //schema defined simpleType possibly with restrictions
writer.write("\t"+paraTypeName+" v"+i+" = pIWSDZ->"+CUtils.getParameterGetValueMethodName(paraTypeName, false)+"(\""+elementName+"\",0);\n");
}
else if((CUtils.isSimpleType(param.getLangName()))){
//for simple types
writer.write("\t"+paraTypeName+" v"+i+" = pIWSDZ->"+CUtils.getParameterGetValueMethodName(paraTypeName, false)+"(\""+elementName+"\",0);\n");
}else if((type != null) && type.isArray()){
Type arrayType = WrapperUtils.getArrayType(type);
QName qname = arrayType.getName();
String containedType = null;
if (CUtils.isSimpleType(qname)){
containedType = CUtils.getclass4qname(qname);
writer.write("\t"+paraTypeName+" v"+i+" = ("+CUtils.getBasicArrayNameforType(containedType)+"&)pIWSDZ->getBasicArray("+CUtils.getXSDTypeForBasicType(containedType)+ ", \""+elementName+"\",0);\n");
}
else if (arrayType.isSimpleType()){//SimpleType in the schema
containedType = CUtils.getclass4qname(arrayType.getBaseType());
writer.write("\t"+paraTypeName+" v"+i+" = ("+CUtils.getBasicArrayNameforType(containedType)+"&)pIWSDZ->getBasicArray("+CUtils.getXSDTypeForBasicType(containedType)+ ", \""+elementName+"\",0);\n");
}
else{
containedType = qname.getLocalPart();
writer.write("\t"+paraTypeName+" v"+i+" = ("+paraTypeName+"&)pIWSDZ->getCmplxArray((void*)Axis_DeSerialize_"+containedType+
"\n\t\t, (void*)Axis_Create_"+containedType+", (void*)Axis_Delete_"+containedType+
"\n\t\t, (void*)Axis_GetSize_"+containedType+", \""+elementName+"\", Axis_URI_"+containedType+");\n");
}
}else if (param.isAnyType()){
//for anyType
writer.write("\t"+paraTypeName+" *v"+i+" = ("+paraTypeName+"*)pIWSDZ->getAnyObject();\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, \""+elementName+"\", 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"); //nithya
if(returntype != null){ /* Invoke the service when return type not void */
returnParamName = returntype.getElementName().getLocalPart();
writer.write("\t"+outparamType+((returntypeisarray || returntypeissimple)?" ":" *")+ "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("\treturn pIWSSZ->addOutputParam(\""+returnParamName+"\", (void*)&ret, "+CUtils.getXSDTypeForBasicType(outparamType)+");\n");
}else if(returntypeisarray){
Type arrayType = WrapperUtils.getArrayType(retType);
QName qname = arrayType.getName();
String containedType = null;
if (CUtils.isSimpleType(qname)){
containedType = CUtils.getclass4qname(qname);
writer.write("\treturn pIWSSZ->addOutputBasicArrayParam((Axis_Array*)(&ret),"+CUtils.getXSDTypeForBasicType(containedType)+", \""+returnParamName+"\");\n");
}
else if (arrayType.isSimpleType()){//SimpleType in the schema
containedType = CUtils.getclass4qname(arrayType.getBaseType());
writer.write("\treturn pIWSSZ->addOutputBasicArrayParam((Axis_Array*)(&ret),"+CUtils.getXSDTypeForBasicType(containedType)+", \""+returnParamName+"\");\n");
}
else{
containedType = qname.getLocalPart();
writer.write("\treturn pIWSSZ->addOutputCmplxArrayParam((Axis_Array*)(&ret),"+
"(void*) Axis_Serialize_"+containedType+", (void*) Axis_Delete_"+containedType+", (void*) Axis_GetSize_"+containedType+", \""+returnParamName+"\", Axis_URI_"+containedType+");\n");
}
}else if(returntype.isAnyType()){
writer.write("\treturn pIWSSZ->addOutputAnyObject(ret);\n");
}
else{
//complex type
writer.write("\treturn pIWSSZ->addOutputCmplxParam(ret, (void*)Axis_Serialize_"+outparamType+", (void*)Axis_Delete_"+outparamType+", \""+returnParamName+"\", Axis_URI_"+outparamType+");\n");
}
}else if (isAllTreatedAsOutParams){
writer.write("\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++) {
ParameterInfo param = (ParameterInfo)paramsC.get(i);
retType = wscontext.getTypemap().getType(param.getSchemaName());
if (retType != null){
if (retType.isSimpleType()){
returntypeissimple = true;
outparamType = CUtils.getclass4qname(retType.getBaseType());
}
else{
outparamType = retType.getLanguageSpecificName();
returntypeisarray = retType.isArray();
returntypeissimple = CUtils.isSimpleType(outparamType);
}
}
else{
outparamType = param.getLangName();
returntypeissimple = CUtils.isSimpleType(outparamType);
}
returnParamName = param.getElementName().getLocalPart();
if (returntypeissimple){
writer.write("\tpIWSSZ->addOutputParam(\""+returnParamName+"\", (void*)&out"+i+", "+CUtils.getXSDTypeForBasicType(outparamType)+");\n");
}else if(returntypeisarray){
Type arrayType = WrapperUtils.getArrayType(retType);
QName qname = arrayType.getName();
String containedType = null;
if (CUtils.isSimpleType(qname)){
containedType = CUtils.getclass4qname(qname);
writer.write("\tpIWSSZ->addOutputBasicArrayParam((Axis_Array*)(&out"+i+"),"+CUtils.getXSDTypeForBasicType(containedType)+", \""+returnParamName+"\");\n");
}
else if (arrayType.isSimpleType()){//SimpleType in the schema
containedType = CUtils.getclass4qname(arrayType.getBaseType());
writer.write("\tpIWSSZ->addOutputBasicArrayParam((Axis_Array*)(&out"+i+"),"+CUtils.getXSDTypeForBasicType(containedType)+", \""+returnParamName+"\");\n");
}
else{
containedType = qname.getLocalPart();
writer.write("\tpIWSSZ->addOutputCmplxArrayParam((Axis_Array*)(&out"+i+"),"+
"(void*) Axis_Serialize_"+containedType+", (void*) Axis_Delete_"+containedType+", (void*) Axis_GetSize_"+containedType+", \""+returnParamName+"\", Axis_URI_"+containedType+");\n");
}
}
else if (param.isAnyType()){
//anyType
writer.write("\tpIWSSZ->addOutputAnyObject(out"+i+");\n");
}
else{
//complex type
writer.write("\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("\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);
}
}
writer.write("\tcatch(...){\n"); //nithya