* @throws IOException
*/
public void writeMethodInWrapper(MethodInfo minfo) throws WrapperFault,IOException {
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;
}
String methodName = minfo.getMethodname();
Collection params = minfo.getInputParameterTypes();
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);
}
}
String paraTypeName;
ArrayList paramsB = new ArrayList(params);
Type type;
writer.write("\n/*forward declaration for the c method "+methodName+" */\n");
//TODO forward declaration writing logic should be changed when arrays come into picture
if (returntype == null){
writer.write("extern void "+methodName+"(");
}
else{
writer.write("extern "+outparamType+((returntypeissimple||returntypeisarray)?" ":" *")+methodName+"(");
}
for (int i = 0; i < paramsB.size(); i++) {
if (i>0) writer.write(",");
type = this.wscontext.getTypemap().getType(((ParameterInfo)paramsB.get(i)).getSchemaName());
paraTypeName = ((ParameterInfo)paramsB.get(i)).getLangName();
if((CUtils.isSimpleType(paraTypeName)) || (type != null && type.isSimpleType())){
//for simple types
writer.write(paraTypeName);
}else if(type != null && type.isArray()){
writer.write(paraTypeName);
}else{
writer.write(paraTypeName+"*");
}
}
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(", AXIS_OUT_PARAM "+WrapperUtils.getClassNameFromParamInfoConsideringArrays((ParameterInfo)paramsC.get(i),wscontext)+"*");
}
}
writer.write(");\n");
writer.write("\n/*\n");
writer.write(" * This method wrap the service method \n");
writer.write(" */\n");
//method signature
writer.write("int "+ methodName + CUtils.WRAPPER_METHOD_APPENDER+ "(IWrapperSoapDeSerializer DZ, IWrapperSoapSerializer SZ)\n{\n");
writer.write("\tint nStatus;\n");
boolean aretherearrayparams = false;
String parameterName;
String elementName;
String returnParamName;
for (int i = 0; i < paramsB.size(); i++) {
type = this.wscontext.getTypemap().getType(((ParameterInfo)paramsB.get(i)).getSchemaName());
paraTypeName = ((ParameterInfo)paramsB.get(i)).getLangName();
if((CUtils.isSimpleType(paraTypeName)) || (type != null && type.isSimpleType())){
//for simple types
writer.write("\t"+paraTypeName+" v"+i+";\n");
}else if(type != null && type.isArray()){
//for arrays
aretherearrayparams = true;
writer.write("\t"+paraTypeName+" v"+i+";\n");
}else{
//for complex types
writer.write("\t"+paraTypeName+" *v"+i+";\n");
}
}
if(returntype != null){
writer.write("\t"+outparamType+((returntypeisarray || returntypeissimple)?" ":" *")+ "ret;\n");
}
if (aretherearrayparams){
writer.write("\tAxis_Array array;\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("\tif (AXIS_SUCCESS != DZ._functions->CheckMessageBody(DZ._object, \""+minfo.getInputMessage().getLocalPart()+"\", \""+minfo.getInputMessage().getNamespaceURI()+"\")) return AXIS_FAIL;\n");
writer.write("\tpSZ->_functions->CreateSoapMethod(SZ._object, \""+minfo.getOutputMessage().getLocalPart()+"\", \""+minfo.getOutputMessage().getNamespaceURI()+"\");\n");
//create and populate variables for each parameter
for (int i = 0; i < paramsB.size(); i++) {
type = this.wscontext.getTypemap().getType(((ParameterInfo)paramsB.get(i)).getSchemaName());
if (type.isSimpleType()){ //schema defined simpleType possibly with restrictions
paraTypeName = CUtils.getclass4qname(type.getBaseType());;
}
else{
paraTypeName = ((ParameterInfo)paramsB.get(i)).getLangName();
}
parameterName = ((ParameterInfo)paramsB.get(i)).getParamName();
elementName = ((ParameterInfo)paramsB.get(i)).getElementName().getLocalPart();
if (type.isSimpleType()){ //schema defined simpleType possibly with restrictions
writer.write("\tv"+i+" = DZ._functions->"+CUtils.getParameterGetValueMethodName(paraTypeName, false)+"(DZ._object,\""+elementName+"\", 0);\n");
}
else if((CUtils.isSimpleType(((ParameterInfo)paramsB.get(i)).getLangName()))){
//for simple types
writer.write("\tv"+i+" = DZ._functions->"+CUtils.getParameterGetValueMethodName(paraTypeName, false)+"(DZ._object,\""+elementName+"\", 0);\n");
}else if(type != null && type.isArray()){
QName qname = WrapperUtils.getArrayType(type).getName();
String containedType = null;
if (CUtils.isSimpleType(qname)){
containedType = CUtils.getclass4qname(qname);
writer.write("\tarray = DZ._functions->GetBasicArray(DZ._object, "+CUtils.getXSDTypeForBasicType(containedType)+", \""+elementName+"\", 0);\n");
writer.write("\tmemcpy(&v"+i+", &array, sizeof(Axis_Array));\n");
}
else{
containedType = qname.getLocalPart();
writer.write("\tarray = DZ._functions->GetCmplxArray(DZ._object, (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");
writer.write("\tmemcpy(&v"+i+", &array, sizeof(Axis_Array));\n");
}
}else{
//for complex types
writer.write("\tv"+i+" = ("+paraTypeName+"*)DZ._functions->GetCmplxObject(DZ._object, (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 = DZ._functions->GetStatus(DZ._object))) return nStatus;\n");
if(returntype != null){
returnParamName = returntype.getElementName().getLocalPart();
/* Invoke the service when return type not void */
writer.write("\tret = "+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 pSZ->_functions->AddOutputParam(SZ._object, \""+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 pSZ->_functions->AddOutputBasicArrayParam(SZ._object, (Axis_Array*)(&ret),"+CUtils.getXSDTypeForBasicType(containedType)+", \""+returnParamName+"\");\n");
}
else if (arrayType.isSimpleType()){//SimpleType in the schema
containedType = CUtils.getclass4qname(arrayType.getBaseType());
writer.write("\treturn pSZ->_functions->AddOutputBasicArrayParam(SZ._object, (Axis_Array*)(&ret),"+CUtils.getXSDTypeForBasicType(containedType)+", \""+returnParamName+"\");\n");
}
else{
containedType = qname.getLocalPart();
writer.write("\treturn pSZ->_functions->AddOutputCmplxArrayParam(SZ._object, (Axis_Array*)(&ret), (void*) Axis_Serialize_"+containedType
+", (void*) Axis_Delete_"+containedType+", (void*) Axis_GetSize_"+containedType+", \""+returnParamName+"\", Axis_URI_"+containedType+");\n");
}
}
else{
//complex type
writer.write("\treturn pSZ->_functions->AddOutputCmplxParam(SZ._object, ret, (void*)Axis_Serialize_"+outparamType+", (void*)Axis_Delete_"+outparamType+", \""+returnParamName+"\", Axis_URI_"+outparamType+");\n");
}
}else if (isAllTreatedAsOutParams){
writer.write("\t" + 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){
if (retType.isSimpleType()){
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);
}
returnParamName = ((ParameterInfo)paramsC.get(i)).getElementName().getLocalPart();
if (returntypeissimple){
writer.write("\tSZ._functions->AddOutputParam(SZ._object, \""+returnParamName+"\", (void*)&out"+i+", "+CUtils.getXSDTypeForBasicType(outparamType)+");\n");