in src/wsdl/org/apache/axis/wsdl/wsdl2ws/c/BeanParamWriter.java [485:767]
private void writeDeSerializeGlobalMethod() throws IOException, WrapperFault
{
CUtils.printMethodComment(c_writer, "Function to deserialize an object of type "
+ c_classname + ".");
c_writer.write("int Axis_DeSerialize_" + c_classname + "(" + c_classname
+ "* param, AXISCHANDLE pDZ)\n{\n");
//=============================================================================
// No attributes or elements to deserialize? Then deserialize extension and return.
//=============================================================================
if (attribs.length == 0)
{
writeDeSerializeExtensionCode();
c_writer.write("\treturn AXISC_SUCCESS;\n");
c_writer.write("}\n");
return;
}
// Declare variables we use
c_writer.write("\tconst char* peekedElementName;\n");
//=============================================================================
// Deserialize attributes.
// Actually, attribute deserialization takes place in same loop as elements
// in order to avoid duplication. But here, we put out a comment block.
//=============================================================================
if (attributeParamCount > 0)
CUtils.printBlockComment(c_writer, "Deserialize attributes.");
//=============================================================================
// Deserialize attributes and elements.
//=============================================================================
String arrayType = null;
boolean firstIfWritten = false;
int anyCounter = 0; //counter for any types.
int arrayCount = 0;
boolean handleAll = false;
boolean handleChoice = false;
// Tabs to ensure code alignment
String tab1 = "\t";
String tab2 = "\t";
int startingGroup=0;
int endingGroup=0;
for (int i = 0; i < attribs.length; i++)
{
if (i == attributeParamCount)
CUtils.printBlockComment(c_writer, "Deserialize elements.");
// If All, then the element order is arbitrary, so we need a loop. For both
// 'choice' and 'all', we need to do a peek.
if (attribs[i].getChoiceElement() || attribs[i].getAllElement())
{
endingGroup = i;
if (!firstIfWritten)
{
startingGroup = i;
handleChoice = attribs[i].getChoiceElement();
handleAll = attribs[i].getAllElement();
// Flag for us to know when we found element for 'choice'.
if (handleChoice)
CUtils.printComment(c_writer, "Deserialize \"choice\" group of elements.");
else
{
CUtils.printComment(c_writer, "Deserialize \"all\" group of elements.");
c_writer.write("\twhile (1)\n\t{\n");
// Need to adjust tabs since we will be in a loop
tab1 = "\t\t";
tab2 = "\t\t";
}
// for choice and all, we need to do a peek.
c_writer.write(tab1 + "peekedElementName=axiscSoapDeSerializerPeekNextElementName(pDZ);\n");
if (handleAll)
{
c_writer.write(tab1 + "if (0x00 == *peekedElementName)\n");
c_writer.write(tab1 + "\tbreak;\n");
}
c_writer.write("\n");
c_writer.write(tab1 + "if ");
firstIfWritten = true;
}
else
{
c_writer.write(tab1 + "else if ");
if (handleAll)
tab2 = "\t\t";
else if (handleChoice)
tab2 = "\t";
}
c_writer.write("(strcmp(peekedElementName,\""
+ attribs[i].getElementNameAsSOAPString() + "\")==0)\n");
c_writer.write(tab1 + "{\n");
if (handleAll)
{
c_writer.write(tab1 + "\tif (param->" + attribs[i].getParamNameAsMember() + ")\n");
c_writer.write(tab1 + "\t\taxiscAxisGenerateRedundantElementException(peekedElementName);\n\n");
}
}
else
{
if (firstIfWritten)
endChoiceOrAll(handleAll, handleChoice, tab1, startingGroup, endingGroup);
tab1 = "\t";
tab2 = "\t";
firstIfWritten = false;
handleAll = false;
handleChoice = false;
}
if (handleAll || handleChoice)
tab2 += "\t";
if (attribs[i].isAnyElement())
{
anyCounter += 1;
String fieldName = "any" + Integer.toString(anyCounter);
c_writer.write(tab2 + "param->" + fieldName + " = axiscSoapDeSerializerGetAnyObject(pDZ);\n");
}
else if (attribs[i].isArray())
{
arrayCount++;
String containedTypeArrayName = null;
if (attribs[i].isSimpleType() || attribs[i].getType().isSimpleType())
{
String baseTypeName = null;
if (!attribs[i].isSimpleType() && attribs[i].getType().isSimpleType())
baseTypeName = CUtils.getSimpleType(attribs[i].getType().getBaseType());
else
baseTypeName = attribs[i].getTypeName();
containedTypeArrayName = CUtils.getArrayNameForType(baseTypeName);
c_writer.write(tab2 + "if (param->" + attribs[i].getParamNameAsMember() + " != NULL)\n");
c_writer.write(tab2 + "{\n");
c_writer.write(tab2 + "\taxiscAxisDelete(param->" + attribs[i].getParamNameAsMember() + ", XSDC_ARRAY);\n");
c_writer.write(tab2 + "\tparam->" + attribs[i].getParamNameAsMember() + "= NULL;\n");
c_writer.write(tab2 + "}\n");
c_writer.write("\n");
c_writer.write(tab2 + "param->" + attribs[i].getParamNameAsMember()
+ " = (" + CUtils.sanitizeString(containedTypeArrayName) + " *)"
+ "axiscSoapDeSerializerGetBasicArray(pDZ, "
+ CUtils.getXSDEnumeratorForType(baseTypeName) + ", \""
+ attribs[i].getParamNameAsSOAPString() + "\",0);\n");
}
else
{
arrayType = CUtils.sanitizeString(attribs[i].getTypeName());
c_writer.write(tab1 + "axiscSoapDeSerializerGetCmplxArray(pDZ, (Axisc_Array *)param->" + attribs[i].getParamNameAsMember()
+ ", (void*)Axis_DeSerialize_" + arrayType
+ ", (void*)Axis_Create_" + arrayType
+ ", (void*)Axis_Delete_" + arrayType
+ ", \"" + attribs[i].getElementNameAsSOAPString() + "\", Axis_URI_" + arrayType + ");\n");
}
}
else if ((attribs[i].isSimpleType() || attribs[i].getType().isSimpleType()))
{
String soapTagName = (attribs[i].isAttribute() ? attribs[i].getParamNameAsSOAPString() : attribs[i].getElementNameAsSOAPString());
Type type = attribs[i].getType();
boolean isPointerType = false;
if (type.isSimpleType())
isPointerType = CUtils.isPointerType(CUtils.getSimpleType(type.getBaseType()));
else
isPointerType = CUtils.isPointerType(attribs[i].getTypeName());
if (attribs[i].isNillable() ||
isElementNillable(i) ||
isElementOptional(i) ||
attribs[i].getChoiceElement() ||
attribs[i].getAllElement() ||
attribs[i].isOptional() ||
isPointerType)
{
c_writer.write(tab2 + "param->"
+ attribs[i].getParamNameAsMember() + " = "
+ "axiscSoapDeSerializer"
+ CUtils.getDeserializerMethodName(attribs[i].getTypeName(), attribs[i].isAttribute())
+ "(pDZ, \"" + soapTagName + "\",0);\n");
}
else
{
String elementNameToSearchFor = attribs[i].isAttribute()? attribs[i].getParamNameAsSOAPString():attribs[i].getElementNameAsSOAPString();
c_writer.write(tab2 + "{\n"); // start local scope
c_writer.write(tab2 + "\t" + CUtils.sanitizeString((attribs[i].getTypeName())) + " * "
+ attribs[i].getParamNameAsMember() + " = "
+ "axiscSoapDeSerializer"
+ CUtils.getDeserializerMethodName(attribs[i].getTypeName(), attribs[i].isAttribute())
+ "(pDZ, \"" + elementNameToSearchFor + "\",0);\n");
c_writer.write(tab2 + "\tif (" + attribs[i].getParamNameAsMember() + " != NULL)\n");
c_writer.write(tab2 + "\t{\n");
c_writer.write(tab2 + "\t\tparam->" + attribs[i].getParamNameAsMember() + " = *"
+ attribs[i].getParamNameAsMember() + ";\n");
if (CUtils.getXSDEnumeratorForType( attribs[i].getTypeName()).equals("XSDC_HEXBINARY")
|| CUtils.getXSDEnumeratorForType( attribs[i].getTypeName()).equals("XSDC_BASE64BINARY"))
{
c_writer.write(tab2 + "\t\t" + attribs[i].getParamNameAsMember() + "->__ptr = NULL;\n");
}
c_writer.write(tab2 + "\t\taxiscAxisDelete( (void *) " + attribs[i].getParamNameAsMember()
+ ", " + CUtils.getXSDEnumeratorForType( attribs[i].getTypeName()) + ");\n");
c_writer.write(tab2 + "\t}\n");
c_writer.write(tab2 + "}\n"); // end local scope
}
}
else
{
//if complex type
String soapTagName = attribs[i].getParamNameAsSOAPString();
c_writer.write(tab2 + "param->" + attribs[i].getParamNameAsMember()
+ " = (" + attribs[i].getTypeName()
+ "*)axiscSoapDeSerializerGetCmplxObject(pDZ,(void*)Axis_DeSerialize_" + attribs[i].getTypeName()
+ ", (void*)Axis_Create_" + attribs[i].getTypeName()
+ ", (void*)Axis_Delete_" + attribs[i].getTypeName()
+ ", \"" + soapTagName + "\", Axis_URI_" + attribs[i].getTypeName() + ");\n");
}
if (attribs[i].getChoiceElement() || attribs[i].getAllElement())
c_writer.write(tab1 + "}\n");
c_writer.write("\n");
}
if (firstIfWritten)
endChoiceOrAll(handleAll, handleChoice, tab1, startingGroup, endingGroup);
//=============================================================================
// Deserialize extension, if any, and return status
//=============================================================================
writeDeSerializeExtensionCode();
//=============================================================================
// Ensure there are no more elements - there should not be!
//=============================================================================
c_writer.write("\n");
// Due to partial support of extensions, we need to add this hack in not
// performing a peek - due to the fact that on empty elements the extension
// deserialization will consume the end element, and then the peek will
// return next element causing it to mistakenly throw an exception.
if (extensionBaseAttrib == null
|| extensionBaseAttrib.getTypeName() == null)
{
CUtils.printBlockComment(c_writer, "Ensure no extraneous elements.");
c_writer.write("\tpeekedElementName = axiscSoapDeSerializerPeekNextElementName(pDZ);\n");
c_writer.write("\tif (0x00 != *peekedElementName)\n");
c_writer.write("\t\taxiscAxisGenerateUnknownElementException(peekedElementName);\n");
}
c_writer.write("\n");
c_writer.write("\treturn axiscSoapDeSerializerGetStatus(pDZ);\n");
c_writer.write("}\n");
}