* @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;
}
Collection params = minfo.getInputParameterTypes();
String methodName = minfo.getMethodname();
Type retType = null;
boolean returntypeissimple = false;
boolean returntypeisarray = false;
String outparamType = null;
if (returntype != null)
retType = wscontext.getTypemap().getType(returntype.getSchemaName());
if (retType != null){
if (retType.isSimpleType()){
outparamType = CUtils.getclass4qname(retType.getBaseType());
}
else{
outparamType = retType.getLanguageSpecificName();
}
returntypeisarray = retType.isArray();
}
else if (returntype != null){
outparamType = returntype.getLangName();
}
if (returntype != null)
returntypeissimple = CUtils.isSimpleType(outparamType);
writer.write("\n/*\n");
writer.write(" * This method wrap the service method"+ methodName +"\n");
writer.write(" */\n");
//method signature
String paraTypeName;
boolean typeisarray = false;
boolean typeissimple = false;
Type type;
if (returntype == null){
writer.write("void");
}
else if (returntypeissimple || returntypeisarray){
writer.write(outparamType);
}else{
writer.write(outparamType+"*");
}
writer.write(" "+classname+"::" + methodName + "(");
ArrayList paramsB = (ArrayList)params;
if (0 < paramsB.size()){
type = wscontext.getTypemap().getType(((ParameterInfo)paramsB.get(0)).getSchemaName());
if (type != null){
if (type.isSimpleType()){ //schema defined simpleType
paraTypeName = CUtils.getclass4qname(type.getBaseType());
}
else{
paraTypeName = type.getLanguageSpecificName();
}
typeisarray = type.isArray();
}
else {
paraTypeName = ((ParameterInfo)paramsB.get(0)).getLangName();
typeisarray = false;
}
typeissimple = CUtils.isSimpleType(paraTypeName);
if(typeisarray || typeissimple){
writer.write(paraTypeName+" Value0");
}else{
writer.write(paraTypeName+"* Value0");
}
for (int i = 1; i < paramsB.size(); i++) {
type = wscontext.getTypemap().getType(((ParameterInfo)paramsB.get(i)).getSchemaName());
if (type != null){
if (type.isSimpleType()){ //schema defined simpleType
paraTypeName = CUtils.getclass4qname(type.getBaseType());
}
else{
paraTypeName = type.getLanguageSpecificName();
}
typeisarray = type.isArray();
}
else {
paraTypeName = ((ParameterInfo)paramsB.get(i)).getLangName();
typeisarray = false;
}
typeissimple = CUtils.isSimpleType(paraTypeName);
if(typeisarray || typeissimple){
writer.write(", "+paraTypeName+" Value"+i);
}else{
writer.write(", "+paraTypeName+"* 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(outparamType+" RetArray = {NULL, 0};\n");
}else if(!returntypeissimple){
writer.write(outparamType+"* pReturn = NULL;\n");
//for complex types
}else{
//for simple types
writer.write(outparamType+" Ret;\n");
//TODO initialize return parameter appropriately.
}
}
String channelSecurityType = (WrapperConstants.CHANNEL_SECURITY_SSL.equals(wscontext.getWrapInfo().getChannelSecurity()))?
"SSL_CHANNEL" : "NORMAL_CHANNEL";
writer.write("\tif (AXIS_SUCCESS != m_pCall->Initialize(CPP_DOC_PROVIDER, "+channelSecurityType+")) return ");
if (returntype != null){
writer.write((returntypeisarray?"RetArray":returntypeissimple?"Ret":"pReturn")+";\n\t");
}
else{
writer.write(";\n");
}
writer.write("\tm_pCall->SetTransportProperty(SOAPACTION_HEADER , \""+minfo.getSoapAction()+"\");\n");
writer.write("\tm_pCall->SetSOAPVersion(SOAP_VER_1_1);\n"); //TODO check which version is it really.
writer.write("\tm_pCall->SetOperation(\""+minfo.getInputMessage().getLocalPart()+"\", \""+ minfo.getInputMessage().getNamespaceURI()+"\");\n");
for (int i = 0; i < paramsB.size(); i++) {
type = wscontext.getTypemap().getType(((ParameterInfo)paramsB.get(i)).getSchemaName());
if (type != null){
if (type.isSimpleType()){//schema defined simpleType possibly with restrictions
paraTypeName = CUtils.getclass4qname(type.getBaseType());
}
else{
paraTypeName = type.getLanguageSpecificName();
}
typeisarray = type.isArray();
}
else {
paraTypeName = ((ParameterInfo)paramsB.get(i)).getLangName();
typeisarray = false;
}
typeissimple = CUtils.isSimpleType(paraTypeName);
if(typeisarray){
//arrays
Type arrayType = WrapperUtils.getArrayType(type);
QName qname = arrayType.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)).getElementName().getLocalPart()+"\"");
}
else if (arrayType.isSimpleType()){//SimpleType in the schema
containedType = CUtils.getclass4qname(arrayType.getBaseType());
writer.write("\tm_pCall->AddBasicArrayParameter(");
writer.write("(Axis_Array*)(&Value"+i+"), "+CUtils.getXSDTypeForBasicType(containedType)+", \""+((ParameterInfo)paramsB.get(i)).getElementName().getLocalPart()+"\"");
}
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)).getElementName().getLocalPart()+"\", Axis_URI_"+containedType);
}
}else if(typeissimple){
//for simple types
writer.write("\tm_pCall->AddParameter(");
writer.write("(void*)&Value"+i+", \"" + ((ParameterInfo)paramsB.get(i)).getElementName().getLocalPart()+"\", "+CUtils.getXSDTypeForBasicType(paraTypeName));
}else{
//for complex types
writer.write("\tm_pCall->AddCmplxParameter(");
writer.write("Value"+i+", (void*)Axis_Serialize_"+paraTypeName+", (void*)Axis_Delete_"+paraTypeName+", \"" + ((ParameterInfo)paramsB.get(i)).getElementName().getLocalPart()+"\", Axis_URI_"+paraTypeName);
}
writer.write(");\n");
}
writer.write("\tif (AXIS_SUCCESS == m_pCall->Invoke())\n\t{\n");
if(minfo.getOutputMessage()!=null)
writer.write("\t\tif(AXIS_SUCCESS == m_pCall->CheckMessage(\""+minfo.getOutputMessage().getLocalPart()+"\", \""+minfo.getOutputMessage().getNamespaceURI()+"\"))\n\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){
if (type.isSimpleType()){
currentParaType = CUtils.getclass4qname(type.getBaseType());
}
else{
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){
Type arrayType = WrapperUtils.getArrayType(type);
QName qname = arrayType.getName();
String containedType = null;
if (CUtils.isSimpleType(qname)){
containedType = CUtils.getclass4qname(qname);
writer.write("\t\t\t" + currentParamName + " = ("+currentParaType+"&)m_pCall->GetBasicArray("+CUtils.getXSDTypeForBasicType(containedType)+", \""+currentType.getElementName().getLocalPart()+"\", 0);\n");
}
else if (arrayType.isSimpleType()){//SimpleType in the schema
containedType = CUtils.getclass4qname(arrayType.getBaseType());
writer.write("\t\t\t" + currentParamName + " = ("+currentParaType+"&)m_pCall->GetBasicArray("+CUtils.getXSDTypeForBasicType(containedType)+", \""+currentType.getElementName().getLocalPart()+"\", 0);\n");
}
else{
containedType = qname.getLocalPart();
writer.write("\t\t\t" + currentParamName + " = ("+currentParaType+"&)m_pCall->GetCmplxArray((void*) Axis_DeSerialize_"+containedType);
writer.write(", (void*) Axis_Create_"+containedType+", (void*) Axis_Delete_"+containedType+", (void*) Axis_GetSize_"+containedType+", \""+currentType.getElementName().getLocalPart()+"\", Axis_URI_"+containedType+");\n");
}
}
else if(typeissimple){
writer.write("\t\t\t" + currentParamName + " = m_pCall->"+ CUtils.getParameterGetValueMethodName(currentParaType, false)+"(\""+currentType.getElementName().getLocalPart()+"\", 0);\n");
}
else{
writer.write("\t\t\t" + currentParamName + " = ("+currentParaType+"*)m_pCall->GetCmplxObject((void*) Axis_DeSerialize_"+currentParaType+", (void*) Axis_Create_"+currentParaType+", (void*) Axis_Delete_"+currentParaType+",\""+currentType.getElementName().getLocalPart()+"\", 0);\n");
}
}
writer.write("\t\t}\n");
writer.write("\t}\n\tm_pCall->UnInitialize();\n");
}