Element returnElement = null;
if (isHeader) {
// In header
Block block = message.getHeaderBlock(headerNS, headerLocalPart, context, factory);
// Get the business object. We want to return the object that represents the type.
returnElement = new Element(block.getBusinessObject(true), block.getQName());
}
else {
// In Body
// Determine how many return elements are present
int numBodyBlocks = message.getNumBodyBlocks();
if (outputBodyArgIndex >= 0) {
numBodyBlocks = outputBodyArgIndex;
}
if (!unmarshalComponents) {
if (numBodyBlocks == 1) {
if (log.isDebugEnabled()) {
log.debug("Case A: Not unmarshalling components, and only 1 block");
}
// Normal case: Only one body block
// We can use the get body block method
// that streams the whole block content.
Block block = message.getBodyBlock(context, factory);
//We look for body block only when the return type associated with operation is not void.
//If a null body block is returned in response on a operation that is not void, its a user error.
returnElement = new Element(block.getBusinessObject(true), block.getQName());
} else if (numBodyBlocks > 1) {
if (log.isDebugEnabled()) {
log.debug("Case B: Not unmarshalling components, and multiple blocks");
}
// There is only one return element
Block block = message.getBodyBlock(0, context, factory);
returnElement = new Element(block.getBusinessObject(true), block.getQName());
}
} else {
if (numBodyBlocks > 0) {
if (log.isDebugEnabled()) {
log.debug("Case C: unmarshalling components. Number of blocks=" + numBodyBlocks);
}
// Assume that all the qnames matching the first QName are for the return
List<QName> qNames = message.getBodyBlockQNames();
int firstIndex = 0;
int lastIndex = 0;
QName returnQName = qNames.get(0);
if (log.isDebugEnabled()) {
log.debug(" returnQName =" + returnQName);
}
do {
lastIndex++;
} while (lastIndex < qNames.size() &&
returnQName.equals(qNames.get(lastIndex)));
// Multiple Elements for QName
int numElements = lastIndex - firstIndex;
if (log.isDebugEnabled()) {
log.debug(" number of return blocks=" + numElements);
}
Object container = makeContainer(javaTypeClass,
javaComponentTypeClass,
numElements);
for (int blockI=firstIndex; blockI<lastIndex; blockI++) {
Block block = message.getBodyBlock(blockI, context, factory);
Object value = block.getBusinessObject(true);
if (value instanceof JAXBElement) {
value = ((JAXBElement) value).getValue();
}
if (log.isDebugEnabled()) {
log.debug(" get return Business object (" + JavaUtils.getObjectIdentity(value) +