| /* |
| * Copyright 2003-2004 The Apache Software Foundation. |
| // (c) Copyright IBM Corp. 2004, 2005 All Rights Reserved |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| /** |
| * @author Susantha Kumara(susantha@opensource.lk, skumara@virtusa.com) |
| * @author Samisa Abeysinghe (sabeysinghe@virtusa.com) |
| */ |
| |
| |
| /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ |
| /* NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE */ |
| /* ---------------------------------------------------------------- */ |
| /* CHANGES TO FILE MAY NEED TO BE PROPAGATED TO THE */ |
| /* C-EQUIVALENT FILE IN SUPPORT OF THE C-BINDING INTERFACES. */ |
| /* ---------------------------------------------------------------- */ |
| /* NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE */ |
| /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ |
| |
| package org.apache.axis.wsdl.wsdl2ws.cpp; |
| |
| import java.io.IOException; |
| import java.util.ArrayList; |
| import java.util.Collection; |
| import java.util.Iterator; |
| |
| import javax.xml.namespace.QName; |
| |
| import org.apache.axis.wsdl.wsdl2ws.CUtils; |
| import org.apache.axis.wsdl.wsdl2ws.WrapperFault; |
| import org.apache.axis.wsdl.wsdl2ws.info.FaultInfo; |
| import org.apache.axis.wsdl.wsdl2ws.info.MethodInfo; |
| import org.apache.axis.wsdl.wsdl2ws.info.ParameterInfo; |
| import org.apache.axis.wsdl.wsdl2ws.info.Type; |
| import org.apache.axis.wsdl.wsdl2ws.info.WebServiceContext; |
| |
| public class ClientStubWriter extends CPPClassWriter |
| { |
| protected ArrayList methods; |
| |
| public ClientStubWriter(WebServiceContext wscontext) throws WrapperFault |
| { |
| super(wscontext.getServiceInfo().getServicename()); |
| this.wscontext = wscontext; |
| this.methods = wscontext.getServiceInfo().getMethods(); |
| } |
| |
| protected void writeClassComment() throws WrapperFault |
| { |
| try |
| { |
| c_writer.write("/*\n"); |
| c_writer.write(" * This file was auto-generated by the Axis C++ Web Service " |
| + "Generator (WSDL2Ws)\n"); |
| c_writer.write(" * This file contains Client Stub implementation for remote web service.\n"); |
| c_writer.write(" */\n\n"); |
| } |
| catch (IOException e) |
| { |
| throw new WrapperFault(e); |
| } |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.apache.axis.wsdl.wsdl2ws.cpp.HeaderFileWriter#writeConstructors() |
| */ |
| protected void writeConstructors() throws WrapperFault |
| { |
| try |
| { |
| CUtils.printMethodComment(c_writer, "Constructor for service " + c_classname + "."); |
| |
| c_writer.write(c_classname + "::\n" + c_classname |
| + "(const char* pcEndpointUri, AXIS_PROTOCOL_TYPE eProtocol)\n:Stub(pcEndpointUri, eProtocol)\n{\n"); |
| c_writer.write("}\n"); |
| |
| CUtils.printMethodComment(c_writer, "Constructor for service " + c_classname + "."); |
| c_writer.write(c_classname + "::\n" + c_classname + "()\n:Stub(\" \", APTHTTP1_1)\n{\n"); |
| //TODO get TransportURI from WrapInfo and check what the transport is and do the following line accordingly |
| c_writer.write("\tm_pCall->setEndpointURI(\"" |
| + wscontext.getServiceInfo().getTargetEndpointURI() + "\");\n"); |
| c_writer.write("}\n"); |
| } |
| catch (IOException e) |
| { |
| throw new WrapperFault(e); |
| } |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.apache.axis.wsdl.wsdl2ws.cpp.HeaderFileWriter#writeDistructors() |
| */ |
| protected void writeDestructors() throws WrapperFault |
| { |
| try |
| { |
| CUtils.printMethodComment(c_writer, "Destructor for service " + c_classname + "."); |
| |
| c_writer.write(c_classname + "::\n~" + c_classname + "()\n{\n}\n"); |
| } |
| catch (IOException e) |
| { |
| throw new WrapperFault(e); |
| } |
| } |
| |
| /* |
| * @see org.apache.axis.wsdl.wsdl2ws.cpp.HeaderFileWriter#writeMethods() |
| * Used by literal code too! |
| */ |
| protected void writeMethods() throws WrapperFault |
| { |
| try |
| { |
| MethodInfo minfo; |
| for (int i = 0; i < methods.size(); i++) |
| { |
| minfo = (MethodInfo) methods.get(i); |
| this.writeMethodInWrapper(minfo); |
| } |
| } |
| catch (IOException e) |
| { |
| throw new WrapperFault(e); |
| } |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.apache.axis.wsdl.wsdl2ws.cpp.HeaderFileWriter#writePreprocssorStatements() |
| */ |
| protected void writePreprocessorStatements() throws WrapperFault |
| { |
| try |
| { |
| if ("AxisClientException".equals(c_classname)) |
| { |
| c_writer.write("#include \"" + wscontext.getServiceInfo().getServicename() + "_" + c_classname |
| + CUtils.getHeaderFileExtension() + "\"\n\n"); |
| } |
| else |
| c_writer.write("#include \"" + c_classname + CUtils.getHeaderFileExtension() + "\"\n\n"); |
| |
| c_writer.write("#include <axis/AxisWrapperAPI.hpp>\n"); |
| c_writer.write ("#include <axis/Axis.hpp>\n"); |
| c_writer.write ("#include <axis/IWrapperSoapSerializer.hpp>\n\n"); |
| } |
| catch (IOException e) |
| { |
| throw new WrapperFault(e); |
| } |
| } |
| |
| /** |
| * This method genarate methods that wraps the each method of the service |
| * @param methodName |
| * @param params |
| * @param outparam |
| * @throws IOException |
| */ |
| |
| public void writeMethodInWrapper(MethodInfo minfo) throws WrapperFault, IOException |
| { |
| /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ |
| /* NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE */ |
| /* ---------------------------------------------------------------- */ |
| /* CHANGES TO FILE MAY NEED TO BE PROPAGATED TO THE */ |
| /* C-EQUIVALENT FILE IN SUPPORT OF THE C-BINDING INTERFACES. */ |
| /* ---------------------------------------------------------------- */ |
| /* NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE */ |
| /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ |
| |
| 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) |
| { |
| outparamType = CUtils.getClassNameFromParamInfoConsideringArrays(returntype, wscontext); |
| if (retType.isSimpleType()) |
| returntypeissimple = true; |
| else |
| { |
| returntypeissimple = CUtils.isSimpleType (outparamType); |
| returntypeisarray = CUtils.isArrayType(outparamType); |
| } |
| |
| returntypeisarray |= retType.isArray(); |
| } |
| else |
| { |
| outparamType = returntype.getLangName (); |
| returntypeissimple = CUtils.isSimpleType (outparamType); |
| } |
| } |
| |
| //============================================================================= |
| // Generate method prototype |
| //============================================================================= |
| |
| CUtils.printMethodComment(c_writer, "This method wraps the service method " + methodName + "."); |
| |
| //method signature |
| String paramTypeName; |
| boolean typeisarray = false; |
| boolean typeissimple = false; |
| Type type; |
| |
| if (returntype == null) |
| c_writer.write("void"); |
| else if (returntypeissimple |
| && (!(returntype.isNillable() || returntype.isOptional()) |
| || CUtils.isPointerType(outparamType))) |
| c_writer.write (outparamType); |
| else if (outparamType.lastIndexOf ("*") > 0) |
| c_writer.write (outparamType); |
| else |
| c_writer.write (outparamType + "*"); |
| |
| c_writer.write(" " + c_classname + "::\n" + methodName + "("); |
| ArrayList paramsB = (ArrayList) params; |
| for (int i = 0; i < paramsB.size(); i++) |
| { |
| paramTypeName = |
| CUtils.getClassNameFromParamInfoConsideringArrays((ParameterInfo) paramsB.get(i), wscontext); |
| |
| if (i > 0) |
| c_writer.write(", "); |
| |
| typeissimple = CUtils.isSimpleType(paramTypeName); |
| if (typeissimple |
| && (!(((ParameterInfo) paramsB.get (i)).isNillable () |
| || ((ParameterInfo) paramsB.get (i)).isOptional()) |
| || CUtils.isPointerType(paramTypeName))) |
| c_writer.write (paramTypeName + " Value" + i); |
| else if (paramTypeName.lastIndexOf ("*") > 0) |
| c_writer.write (paramTypeName + " Value" + i); |
| else |
| c_writer.write (paramTypeName + "* Value" + i); |
| } |
| |
| // Multiples parameters so fill the methods prototype |
| ArrayList paramsC = (ArrayList) minfo.getOutputParameterTypes(); |
| if (isAllTreatedAsOutParams) |
| { |
| for (int i = 0; i < paramsC.size(); i++) |
| { |
| type = wscontext.getTypemap().getType(((ParameterInfo) paramsC.get(i)).getSchemaName()); |
| c_writer.write(", AXIS_OUT_PARAM " |
| + CUtils.getClassNameFromParamInfoConsideringArrays( |
| (ParameterInfo) paramsC.get(i),wscontext) + " *OutValue" + i); |
| } |
| } |
| |
| c_writer.write(")\n{\n"); |
| |
| //============================================================================= |
| // Generate global variables (outside of try block) |
| //============================================================================= |
| |
| if (returntype != null) |
| { |
| c_writer.write("\t"); |
| |
| if (returntypeisarray) |
| c_writer.write(outparamType + " * RetArray = new " + outparamType + "();\n"); |
| else if (!returntypeissimple) |
| c_writer.write(outparamType + "\tpReturn = NULL;\n"); |
| else if (returntype.isNillable() || returntype.isOptional() |
| || CUtils.isPointerType(outparamType)) |
| { |
| c_writer.write(outparamType); |
| if (!CUtils.isPointerType(outparamType)) |
| c_writer.write(" *"); |
| |
| c_writer.write("\tRet = NULL;\n"); |
| } |
| else |
| { |
| String initValue = CUtils.getInitValueForType (outparamType); |
| if (initValue != null) |
| c_writer.write (outparamType + " Ret = " + initValue + ";\n"); |
| else if (CUtils.getXSDEnumeratorForType( outparamType).equals("XSD_DATETIME") |
| || CUtils.getXSDEnumeratorForType( outparamType).equals("XSD_DATE") |
| || CUtils.getXSDEnumeratorForType( outparamType).equals("XSD_TIME")) |
| { |
| c_writer.write (outparamType + " Ret;\n"); |
| c_writer.write ("\tmemset(&Ret,0,sizeof(" + outparamType + "));\n"); |
| } |
| else |
| c_writer.write (outparamType + " Ret;\n"); |
| } |
| } |
| |
| c_writer.write("\tconst char* pcCmplxFaultName = NULL;\n\n"); |
| |
| //============================================================================= |
| // Generate try block and method logic |
| //============================================================================= |
| |
| c_writer.write("\ttry\n\t{\n"); |
| |
| c_writer.write("\t\tif (AXIS_SUCCESS != m_pCall->initialize(CPP_RPC_PROVIDER" + "))\n"); |
| c_writer.write("\t\t\treturn "); |
| if (returntype != null) |
| { |
| if (returntypeisarray) |
| c_writer.write("RetArray;\n"); |
| else if (CUtils.isPointerType(outparamType) || |
| (returntypeissimple && !(returntype.isNillable() || returntype.isOptional()))) |
| c_writer.write("Ret;\n"); |
| else if (returntypeissimple) |
| c_writer.write("*Ret;\n"); |
| else |
| c_writer.write("pReturn;\n"); |
| } |
| else |
| c_writer.write(";\n"); |
| c_writer.write("\n"); |
| |
| c_writer.write("\t\tif( NULL == m_pCall->getTransportProperty( \"SOAPAction\", false))\n"); |
| c_writer.write("\t\t\tm_pCall->setTransportProperty( SOAPACTION_HEADER,\"" |
| + minfo.getSoapAction() + "\");\n"); |
| c_writer.write("\n"); |
| |
| c_writer.write("\t\tm_pCall->setSOAPVersion( SOAP_VER_1_1);\n"); |
| //TODO check which version is it really. |
| |
| // Use namespace specified in input binding if one exists |
| // For rpc/literal operations the namespace must be set, but if not, use |
| // the target namespace. |
| String namespaceURI = minfo.getInputNamespaceURI(); |
| if (namespaceURI == null) |
| namespaceURI = wscontext.getWrapperInfo().getTargetNameSpaceOfWSDL(); |
| |
| c_writer.write("\t\tm_pCall->setOperation( \"" |
| + minfo.getMethodname() + "\", \"" |
| + namespaceURI + "\");\n"); |
| |
| //============================================================================= |
| // Apply user specified properties |
| //============================================================================= |
| |
| c_writer.write("\n"); |
| c_writer.write ("\t\tincludeSecure();\n"); |
| c_writer.write ("\t\tapplyUserPreferences();\n"); |
| c_writer.write("\n"); |
| |
| //============================================================================= |
| // Process elements |
| //============================================================================= |
| |
| 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 = CUtils.getArrayType(type).getName(); |
| String containedType = null; |
| if (CUtils.isSimpleType(qname)) |
| { |
| containedType = CUtils.getSimpleType(qname); |
| c_writer.write("\t\tm_pCall->addBasicArrayParameter( "); |
| c_writer.write("Value" + i + ", " |
| + CUtils.getXSDEnumeratorForType(containedType) |
| + ", \"" |
| + ((ParameterInfo) paramsB.get(i)).getParamNameAsSOAPString() |
| + "\""); |
| } |
| else |
| { |
| containedType = qname.getLocalPart(); |
| c_writer.write("\t\tm_pCall->addCmplxArrayParameter( "); |
| c_writer.write("Value" + i |
| + ",(void *) Axis_Serialize_" + containedType |
| + ",(void *) Axis_Delete_" + containedType |
| + ",\"" + ((ParameterInfo) paramsB.get(i)).getParamNameAsSOAPString() + "\"" |
| + ",Axis_URI_" + containedType); |
| } |
| } |
| else if (typeissimple) |
| { |
| if (((ParameterInfo) paramsB.get(i)).isNillable() |
| || CUtils.isPointerType(paramTypeName)) |
| { |
| c_writer.write("\t\tm_pCall->addParameter( "); |
| c_writer.write("(void *) Value" + i + ", \"" |
| + ((ParameterInfo) paramsB.get(i)).getParamNameAsSOAPString() + "\", " |
| + CUtils.getXSDEnumeratorForType(paramTypeName)); |
| } |
| else |
| { |
| c_writer.write("\t\tm_pCall->addParameter( "); |
| c_writer.write("(void *) &Value" + i + ", \"" |
| + ((ParameterInfo) paramsB.get(i)).getParamNameAsSOAPString() + "\", " |
| + CUtils.getXSDEnumeratorForType(paramTypeName)); |
| } |
| } |
| else |
| { |
| //for complex types |
| c_writer.write("\t\tm_pCall->addCmplxParameter( "); |
| c_writer.write("Value" + i |
| + ",(void *) Axis_Serialize_" + paramTypeName |
| + ",(void *) Axis_Delete_" + paramTypeName |
| + ",\"" + ((ParameterInfo) paramsB.get(i)).getParamNameAsSOAPString() |
| + "\",Axis_URI_" + paramTypeName); |
| } |
| |
| c_writer.write(");\n"); |
| } |
| |
| //============================================================================= |
| // Invoke web service - two-way message processing |
| //============================================================================= |
| |
| c_writer.write("\n\t\tif( AXIS_SUCCESS == m_pCall->sendAndReceive())\n\t\t{\n"); |
| c_writer.write("\t\t\tif( AXIS_SUCCESS == m_pCall->checkMessage( \"" |
| + minfo.getOutputMessage().getLocalPart() + "\",\"" |
| + namespaceURI |
| + "\"))\n\t\t\t{\n"); |
| |
| String paramTagName = ""; |
| |
| if( returntype != null) |
| paramTagName = returntype.getParamNameAsSOAPString(); |
| |
| //============================================================================= |
| // Process output parameters |
| //============================================================================= |
| |
| if (isAllTreatedAsOutParams) |
| { |
| String currentParamName; |
| String currentParaType; |
| for (int i = 0; i < paramsC.size(); i++) |
| { |
| ParameterInfo currentType = (ParameterInfo) paramsC.get(i); |
| paramTagName = currentType.getParamNameAsSOAPString(); |
| |
| 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 = CUtils.getArrayType(type).getName(); |
| |
| String containedType = null; |
| String containedTypeArrayName = null; |
| |
| if (CUtils.isSimpleType(qname)) |
| { |
| containedType = CUtils.getSimpleType(qname); |
| c_writer.write("\n\t\t\tAxis_Array * pReturn" + i + " = m_pCall->getBasicArray( " + CUtils.getXSDEnumeratorForType (containedType) |
| + ",\"" + paramTagName |
| + "\", 0);\n\n"); |
| c_writer.write("\t\t\tif( pReturn" + i + " != NULL && OutValue" + i + " != NULL)\n"); |
| c_writer.write("\t\t\t{\n"); |
| c_writer.write("\t\t\t\tif( *OutValue" + i + " == NULL)\n"); |
| c_writer.write("\t\t\t\t\t*OutValue" + i + " = new " + currentParaType + "();\n"); |
| c_writer.write("\t\t\t\telse\n"); |
| c_writer.write("\t\t\t\t\t(*OutValue" + i + ")->clear();\n"); |
| c_writer.write("\t\t\t\t(*OutValue" + i + ")->clone( *pReturn" + i + ");\n"); |
| c_writer.write("\t\t\t}\n\n"); |
| c_writer.write("\t\t\tAxis::AxisDelete( (void *) pReturn" + i + ", XSD_ARRAY);\n"); |
| } |
| else |
| { |
| containedType = qname.getLocalPart(); |
| containedTypeArrayName = CUtils.getArrayNameForComplexType(qname); |
| |
| c_writer.write("\n\t\t\tif( OutValue" + i + " != NULL)\n" ); |
| c_writer.write("\t\t\t{\n"); |
| c_writer.write("\t\t\t\tif( " + currentParamName + " == NULL)\n"); |
| c_writer.write("\t\t\t\t\t" + currentParamName + " = new " + containedTypeArrayName + "();\n"); |
| c_writer.write("\t\t\t\telse\n"); |
| c_writer.write("\t\t\t\t\t(" + currentParamName + ")->clear();\n"); |
| c_writer.write("\t\t\t\tm_pCall->getCmplxArray( " + currentParamName |
| + ",(void *) Axis_DeSerialize_" + containedType |
| + ",(void *) Axis_Create_" + containedType |
| + ",(void *) Axis_Delete_" + containedType |
| + ",\"" +currentType.getElementNameAsSOAPString() |
| + "\",Axis_URI_" + containedType + ");\n"); |
| c_writer.write("\t\t\t}\n"); |
| c_writer.write("\t\t\telse\n"); |
| c_writer.write("\t\t\t{\n"); |
| c_writer.write("\t\t\t\t// Unable to return value, but will deserialize to ensure subsequent elements can be correctly processed.\n"); |
| c_writer.write("\t\t\t\t" + containedTypeArrayName + " * pTemp" + i |
| + " = new " + containedTypeArrayName + "();\n"); |
| c_writer.write("\t\t\t\tm_pCall->getCmplxArray( pTemp" + i |
| + ",(void *) Axis_DeSerialize_" + containedType |
| + ",(void *) Axis_Create_" + containedType |
| + ",(void *) Axis_Delete_" + containedType |
| + ",\"" + currentType.getElementNameAsSOAPString() |
| + "\",Axis_URI_" + containedType + ");\n"); |
| c_writer.write("\t\t\t\tdelete pTemp" + i + ";\n"); |
| c_writer.write("\t\t\t}\n"); |
| } |
| } |
| else if (typeissimple) |
| { |
| if( i > 0) |
| c_writer.write( "\n"); |
| |
| if (CUtils.isPointerType(currentParaType)) |
| { |
| String xsdType = CUtils.getClassNameFromParamInfoConsideringArrays ((ParameterInfo) paramsC.get (i), wscontext); |
| |
| if( !CUtils.isPointerType(xsdType)) |
| xsdType += " *"; |
| |
| c_writer.write( "\t\t\t" + currentParaType + " pReturn" + i |
| + " = m_pCall->" + CUtils.getDeserializerMethodName( currentParaType, false) |
| + "( \"" + paramTagName + "\", 0);\n"); |
| c_writer.write( "\n"); |
| c_writer.write( "\t\t\tif( pReturn" + i + " != NULL && OutValue" + i + " != NULL)\n"); |
| c_writer.write( "\t\t\t\t{\n"); |
| c_writer.write( "\t\t\t\tif( *OutValue" + i + " != NULL)\n"); |
| c_writer.write( "\t\t\t\t{\n"); |
| c_writer.write( "\t\t\t\t\tint\tiStringSize" + i + " = strlen( (char *) *OutValue" + i + ");\n"); |
| c_writer.write( "\t\t\t\t\tint\tiStrLenValue" + i + " = strlen( pReturn" + i + ");\n"); |
| c_writer.write( "\n"); |
| c_writer.write( "\t\t\t\t\tif( iStrLenValue" + i + " > iStringSize" + i + ")\n"); |
| c_writer.write( "\t\t\t\t\t{\n"); |
| c_writer.write( "\t\t\t\t\t\t*OutValue" + i + " =(" + xsdType + ") new char[iStrLenValue" + i + " + 1];\n"); |
| c_writer.write( "\t\t\t\t\t\tstrcpy( (char *) *OutValue" + i + ", pReturn" + i + ");\n"); |
| c_writer.write( "\t\t\t\t\t}\n"); |
| c_writer.write( "\t\t\t\t\telse\n"); |
| c_writer.write( "\t\t\t\t\t\tstrcpy( (char *) *OutValue" + i + ", pReturn" + i + ");\n"); |
| c_writer.write( "\t\t\t\t}\n"); |
| c_writer.write( "\t\t\t\telse\n"); |
| c_writer.write( "\t\t\t\t{\n"); |
| c_writer.write( "\t\t\t\t\t*OutValue" + i + " = (" + xsdType + ") new char[strlen( pReturn" + i + ") + 1];\n"); |
| c_writer.write( "\t\t\t\t\tstrcpy( (char *) *OutValue" + i + ", pReturn" + i + ");\n"); |
| c_writer.write( "\t\t\t\t}\n"); |
| c_writer.write( "\t\t\t}\n"); |
| c_writer.write( "\n"); |
| c_writer.write( "\t\t\tAxis::AxisDelete( (void *) pReturn" + i + ", " |
| + CUtils.getXSDEnumeratorForType( currentParaType) + ");\n"); |
| } |
| else |
| { |
| c_writer.write( "\t\t\t" + currentParaType + " * pReturn" + i + " = m_pCall->" |
| + CUtils.getDeserializerMethodName( currentParaType, false) |
| + "( \"" + paramTagName + "\", 0);\n"); |
| c_writer.write( "\n"); |
| c_writer.write( "\t\t\tif( pReturn" + i + " != NULL && OutValue" + i + " != NULL)\n"); |
| c_writer.write( "\t\t\t{\n"); |
| c_writer.write( "// OutValue" + i + " is not nillable.\n"); |
| c_writer.write( "\t\t\t\tOutValue" + i + " = new " + currentParaType + "();\n"); |
| c_writer.write( "\n"); |
| c_writer.write( "\t\t\t\t*OutValue" + i + " = *pReturn" + i + ";\n"); |
| c_writer.write( "\t\t\t}\n"); |
| c_writer.write( "\n"); |
| c_writer.write( "\t\t\tAxis::AxisDelete( (void *) pReturn" + i + ", " |
| + CUtils.getXSDEnumeratorForType( currentParaType) + ");\n"); |
| } |
| } |
| else |
| { |
| c_writer.write("\t\t\t\t" |
| + currentParamName + " = (" + currentParaType |
| + " *) m_pCall->getCmplxObject( (void *) Axis_DeSerialize_" + currentParaType |
| + ",(void *) Axis_Create_" + currentParaType |
| + ",(void *) Axis_Delete_" + currentParaType |
| + ",\"" + paramTagName + "\",0);\n"); |
| } |
| } // end for-loop for paramsC |
| |
| c_writer.write("\t\t\t}\n"); |
| c_writer.write("\t\t}\n\n"); |
| c_writer.write("\t\tm_pCall->unInitialize();\n"); |
| } |
| else if (returntype == null) |
| { |
| c_writer.write("\t\t\t\t/*not successful*/\n\t\t\t}\n"); |
| c_writer.write("\t\t}\n\n"); |
| c_writer.write("\t\tm_pCall->unInitialize();\n"); |
| } |
| else if (returntypeisarray) |
| { |
| QName qname = CUtils.getArrayType(retType).getName(); |
| |
| String containedType = null; |
| String containedTypeArrayName = null; |
| |
| if (CUtils.isSimpleType(qname)) |
| { |
| containedType = CUtils.getSimpleType(qname); |
| c_writer.write("\t\t\t\tAxis_Array * RetAxisArray = m_pCall->getBasicArray( " |
| + CUtils.getXSDEnumeratorForType(containedType) + ",\"" |
| + paramTagName + "\",0);\n"); |
| c_writer.write ("\t\t\t\tRetArray->clone( *RetAxisArray);\n"); |
| c_writer.write ("\t\t\t\tAxis::AxisDelete( (void *) RetAxisArray, XSD_ARRAY);\n"); |
| } |
| else |
| { |
| containedType = qname.getLocalPart(); |
| containedTypeArrayName = CUtils.getArrayNameForComplexType(qname); |
| |
| c_writer.write("\t\t\t\tRetArray = (" + containedTypeArrayName |
| + " *) m_pCall->getCmplxArray( RetArray,(void *) Axis_DeSerialize_" |
| + containedType); |
| c_writer.write(",(void *) Axis_Create_" + containedType |
| + ",(void *) Axis_Delete_" + containedType |
| + ",\"" + paramTagName |
| + "\",Axis_URI_" + containedType + ");\n"); |
| } |
| c_writer.write("\t\t\t}\n\t\t}\n\n"); |
| c_writer.write("\t\tm_pCall->unInitialize();\n\n"); |
| c_writer.write("\t\treturn RetArray;\n"); |
| } |
| else if (returntypeissimple) |
| { |
| if (returntype.isNillable () || CUtils.isPointerType(outparamType)) |
| { |
| c_writer.write( "\t\t\t\tRet = m_pCall->" |
| + CUtils.getDeserializerMethodName( outparamType, false) |
| + "(\"" + returntype.getParamNameAsSOAPString() + "\", 0);\n"); |
| } |
| else |
| { |
| c_writer.write ("\t\t\t\t" + outparamType + " * pReturn = m_pCall->" + |
| CUtils.getDeserializerMethodName(outparamType, false) + "(\"" + |
| returntype.getElementNameAsSOAPString() + "\", 0);\n"); |
| c_writer.write ("\t\t\t\tif(pReturn)\n"); |
| c_writer.write ("\t\t\t\t{\n"); |
| c_writer.write ("\t\t\t\t\tRet = *pReturn;\n"); |
| c_writer.write ("\t\t\t\t\tAxis::AxisDelete( (void *) pReturn, " + CUtils.getXSDEnumeratorForType( outparamType) + ");\n"); |
| c_writer.write ("\t\t\t\t}\n"); |
| |
| // TODO If we unexpectedly receive a nill value, when nillable="false" we should do something appropriate, perhaps as below: |
| // writer.write("\t\t\telse"); |
| // writer.write("\t\t\t\tthrow new Exception(\"Unexpected use of nill\");"); |
| } |
| c_writer.write("\t\t\t}\n"); |
| c_writer.write("\t\t}\n\n"); |
| c_writer.write("\t\tm_pCall->unInitialize();\n"); |
| c_writer.write("\t\treturn Ret;\n"); |
| } |
| else |
| { |
| outparamType = returntype.getLangName(); |
| //need to have complex type name without * |
| c_writer.write("\t\t\t\tpReturn = (" + outparamType |
| + " *) m_pCall->getCmplxObject( (void *) Axis_DeSerialize_" |
| + outparamType + ",(void *) Axis_Create_" |
| + outparamType + ",(void *) Axis_Delete_" |
| + outparamType + ",\"" + paramTagName |
| + "\",0);\n\t\t\t}\n"); |
| c_writer.write("\t\t}\n\n"); |
| c_writer.write("\t\tm_pCall->unInitialize();\n\n"); |
| c_writer.write("\t\treturn pReturn;\n"); |
| } |
| |
| c_writer.write("\t}\n"); |
| |
| //============================================================================= |
| // End of try block, beginning of catch block |
| //============================================================================= |
| |
| writeCatchBlock(minfo); |
| |
| //============================================================================= |
| // End of method |
| //============================================================================= |
| |
| c_writer.write("}\n"); |
| } |
| |
| /** |
| * Used to write out the catch blocks |
| * Used by literal code too! |
| */ |
| protected void writeCatchBlock(MethodInfo minfo) throws WrapperFault, IOException |
| { |
| c_writer.write ("\tcatch(AxisException& e)\n\t{\n"); |
| |
| c_writer.write ("\t\tint iExceptionCode = e.getExceptionCode();\n\n"); |
| c_writer.write ("\t\tif(AXISC_NODE_VALUE_MISMATCH_EXCEPTION != iExceptionCode)\n"); |
| c_writer.write ("\t\t{\n"); |
| c_writer.write ("\t\t\tm_pCall->unInitialize();\n"); |
| c_writer.write ("\t\t\tthrow;\n"); |
| c_writer.write ("\t\t}\n\n"); |
| c_writer.write ("\t\tISoapFault* pSoapFault = (ISoapFault*)\n"); |
| c_writer.write ("\t\t\tm_pCall->checkFault(\"Fault\",\"" |
| + wscontext.getServiceInfo().getTargetEndpointURI () + "\" );\n\n"); |
| c_writer.write ("\t\tif(pSoapFault)\n"); |
| c_writer.write ("\t\t{\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 ()) |
| { |
| c_writer.write ("\t\t\tconst char *detail = pSoapFault->getSimpleFaultDetail();\n"); |
| c_writer.write ("\t\t\tbool deleteDetail=false;\n\n"); |
| c_writer.write ("\t\t\tif (NULL==detail || 0==strlen(detail))\n"); |
| c_writer.write ("\t\t\t{\n"); |
| c_writer.write ("\t\t\t\tdetail=m_pCall->getFaultAsXMLString();\n"); |
| c_writer.write ("\t\t\t\tif (NULL==detail)\n"); |
| c_writer.write ("\t\t\t\t\tdetail=\"\";\n"); |
| c_writer.write ("\t\t\t\telse\n"); |
| c_writer.write ("\t\t\t\t\tdeleteDetail=true;\n"); |
| c_writer.write ("\t\t\t}\n\n"); |
| c_writer.write ("\t\t\tOtherFaultException ofe(pSoapFault->getFaultcode(),\n"); |
| c_writer.write ("\t\t\t\tpSoapFault->getFaultstring(), pSoapFault->getFaultactor(),\n"); |
| c_writer.write ("\t\t\t\tdetail, iExceptionCode);\n\n"); |
| c_writer.write ("\t\t\tif (deleteDetail && NULL!=detail)\n"); |
| c_writer.write ("\t\t\t\tAxis::AxisDelete( (void *) const_cast<char*>(detail), XSD_STRING);\n"); |
| c_writer.write ("\n"); |
| c_writer.write ("\t\t\tm_pCall->unInitialize();\n"); |
| c_writer.write ("\t\t\tdelete pSoapFault;\n"); |
| c_writer.write ("\t\t\tthrow ofe;\n"); |
| } |
| else |
| { |
| flag = true; |
| c_writer.write ("\t\t\tpcCmplxFaultName = pSoapFault->getCmplxFaultObjectName();\n"); |
| } |
| |
| while (paramsFault.hasNext ()) |
| { |
| j = j + 1; |
| FaultInfo info = (FaultInfo) paramsFault.next (); |
| faultInfoName = info.getFaultInfo (); |
| |
| // FJP - D0004 > Looking through the list of attributes for the 'error' part of |
| // the fault message. If found, update the faultInfoName with the |
| // 'localname' of the qname of the attribute. |
| Iterator infoArrayListIterator = info.getParams ().iterator (); |
| while (infoArrayListIterator.hasNext ()) |
| { |
| ParameterInfo paramInfo = (ParameterInfo) infoArrayListIterator.next (); |
| |
| if (paramInfo != null) |
| if ("error".equals (paramInfo.getParamName ())) |
| { |
| faultInfoName = paramInfo.getElementName ().getLocalPart (); |
| break; |
| } |
| } |
| // FJP - D0004 < |
| |
| 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 = CUtils.getClassNameFromParamInfoConsideringArrays (par,wscontext); |
| if (j > 1) |
| { |
| c_writer.write ("\t\t\telse if"); |
| writeExceptions (faultType, faultInfoName, paramName, langName); |
| } |
| else |
| { |
| c_writer.write ("\t\t\tif"); |
| writeExceptions (faultType,faultInfoName, paramName, langName); |
| } |
| } |
| } |
| |
| if (flag == true) |
| { |
| c_writer.write ("\t\t\telse\n"); |
| c_writer.write ("\t\t\t{\n"); |
| c_writer.write ("\t\t\t\tconst char *detail = pSoapFault->getSimpleFaultDetail();\n"); |
| c_writer.write ("\t\t\t\tbool deleteDetail=false;\n\n"); |
| c_writer.write ("\t\t\t\tif (NULL==detail || 0==strlen(detail))\n"); |
| c_writer.write ("\t\t\t\t{\n"); |
| c_writer.write ("\t\t\t\t\tdetail=m_pCall->getFaultAsXMLString();\n\n"); |
| c_writer.write ("\t\t\t\t\tif (NULL==detail)\n"); |
| c_writer.write ("\t\t\t\t\t\tdetail=\"\";\n"); |
| c_writer.write ("\t\t\t\t\telse\n"); |
| c_writer.write ("\t\t\t\t\t\tdeleteDetail=true;\n"); |
| c_writer.write ("\t\t\t\t}\n\n"); |
| c_writer.write ("\t\t\t\tOtherFaultException ofe(pSoapFault->getFaultcode(),\n"); |
| c_writer.write ("\t\t\t\t\tpSoapFault->getFaultstring(), pSoapFault->getFaultactor(),\n"); |
| c_writer.write ("\t\t\t\t\tdetail, iExceptionCode);\n\n"); |
| c_writer.write ("\t\t\t\tif (deleteDetail && NULL!=detail)\n"); |
| c_writer.write ("\t\t\t\t\tAxis::AxisDelete( (void *) const_cast<char*>(detail), XSD_STRING);\n"); |
| c_writer.write ("\n"); |
| c_writer.write ("\t\t\t\tm_pCall->unInitialize();\n"); |
| c_writer.write ("\t\t\t\tdelete pSoapFault;\n"); |
| c_writer.write ("\t\t\t\tthrow ofe;\n"); |
| c_writer.write ("\t\t\t}\n"); |
| } |
| |
| c_writer.write ("\t\t}\n"); |
| c_writer.write ("\t\telse\n"); |
| c_writer.write ("\t\t{\n"); |
| c_writer.write ("\t\t\tm_pCall->unInitialize();\n"); |
| c_writer.write ("\t\t\tdelete pSoapFault;\n"); |
| c_writer.write ("\t\t\tthrow;\n"); |
| c_writer.write ("\t\t}\n"); |
| |
| c_writer.write ("\t}\n"); |
| } |
| |
| /** |
| * Used by literal code too! |
| */ |
| protected void writeExceptions(String faulttype, |
| String faultInfoName, |
| String paramName, |
| String langName) throws WrapperFault |
| { |
| try |
| { |
| c_writer.write("(0 == strcmp(\"" + faultInfoName + "\", pcCmplxFaultName))\n"); |
| c_writer.write("\t\t\t{\n"); |
| c_writer.write("\t\t\t\t" + faulttype + " pFaultDetail = \n"); |
| c_writer.write("\t\t\t\t\t(" + faulttype + ")pSoapFault->getCmplxFaultObject(\n"); |
| c_writer.write("\t\t\t\t\t\t(void*) Axis_DeSerialize_" + langName + ",\n"); |
| c_writer.write("\t\t\t\t\t\t(void*) Axis_Create_" + langName + ",\n"); |
| c_writer.write("\t\t\t\t\t\t(void*) Axis_Delete_" + langName + ",\n"); |
| c_writer.write("\t\t\t\t\t\t\"" + faultInfoName + "\",\n"); |
| c_writer.write("\t\t\t\t\t\t0);\n\n"); |
| c_writer.write("\t\t\t\tpFaultDetail->setFaultCode(pSoapFault->getFaultcode());\n"); |
| c_writer.write("\t\t\t\tpFaultDetail->setFaultString(pSoapFault->getFaultstring());\n"); |
| c_writer.write("\t\t\t\tpFaultDetail->setFaultActor(pSoapFault->getFaultactor());\n"); |
| c_writer.write("\t\t\t\tpFaultDetail->setExceptionCode(e.getExceptionCode());\n"); |
| c_writer.write("\t\t\t\tm_pCall->unInitialize();\n"); |
| c_writer.write ("\t\t\t\tdelete pSoapFault;\n"); |
| |
| String faultTypeName; |
| if (faulttype.lastIndexOf('*') != -1) |
| faultTypeName = faulttype.substring(0, faulttype.lastIndexOf('*')); |
| else |
| faultTypeName = faulttype; |
| |
| c_writer.write ("\t\t\t\t" + faultTypeName + " fault = *pFaultDetail;\n"); |
| c_writer.write ("\t\t\t\tdelete pFaultDetail;\n"); |
| c_writer.write ("\t\t\t\tthrow fault;\n"); |
| c_writer.write("\t\t\t}\n"); |
| } |
| catch (IOException e) |
| { |
| throw new WrapperFault(e); |
| } |
| } |
| } |