TreeSet<String> packages = marshalDesc.getPackages();
String packagesKey = marshalDesc.getPackagesKey();
// Create the message
MessageFactory mf = (MessageFactory)FactoryRegistry.getFactory(MessageFactory.class);
Message m = mf.create(protocol);
// In usage=WRAPPED, there will be a single block in the body.
// The signatureArguments represent the child elements of that block
// The first step is to convert the signature arguments into a list
// of parameter values
List<PDElement> pdeList =
MethodMarshallerUtils.getPDElements(marshalDesc,
pds,
signatureArgs,
false, // output
true, false);
// Now we want to create a single JAXB element that contains the
// parameter values. We will use the wrapper tool to do this.
// Create the inputs to the wrapper tool
ArrayList<String> nameList = new ArrayList<String>();
Map<String, Object> objectList = new HashMap<String, Object>();
Map<String, Class> declaredClassMap = new HashMap<String, Class>();
List<PDElement> headerPDEList = new ArrayList<PDElement>();
Iterator<PDElement> it = pdeList.iterator();
while (it.hasNext()) {
PDElement pde = it.next();
String name = pde.getParam().getParameterName();
if (!pde.getParam().isHeader()) {
// Normal case
// The object list contains type rendered objects
Object value = pde.getElement().getTypeValue();
Class dclClass = pde.getParam().getParameterActualType();
nameList.add(name);
objectList.put(name, value);
declaredClassMap.put(name, dclClass);
} else {
// Header Case:
// Remove the header from the list, it will
// not be placed in the wrapper
it.remove();
headerPDEList.add(pde);
}
}
Class returnType = operationDesc.getResultActualType();
if (!operationDesc.isResultHeader()) {
// Normal (Body Result): Add the return object to the nameList and objectList
if (returnType != void.class) {
String name = operationDesc.getResultName();
Class dclClass = operationDesc.getResultActualType();
nameList.add(name);
objectList.put(name, returnObject);
declaredClassMap.put(name, dclClass);
}
} else {
// Header Result:
// Put the return object onto the message
if (returnType != void.class) {
Element returnElement = null;
QName returnQName = new QName(operationDesc.getResultTargetNamespace(),
operationDesc.getResultName());
if (marshalDesc.getAnnotationDesc(returnType).hasXmlRootElement()) {
returnElement = new Element(returnObject, returnQName);
} else {
returnElement = new Element(returnObject, returnQName, returnType);
}
Class byJavaType =
MethodMarshallerUtils.isNotJAXBRootElement(returnType, marshalDesc) ? returnType : null;
MethodMarshallerUtils.toMessage(returnElement,
returnType,
operationDesc.isListType(),
marshalDesc,
m,
byJavaType,
true);
}
}
// Now create the single JAXB element
String wrapperName = marshalDesc.getResponseWrapperClassName(operationDesc);
Class cls = loadClass(wrapperName, endpointDesc);
JAXBWrapperTool wrapperTool = new JAXBWrapperToolImpl();
Object object = wrapperTool.wrap(cls, nameList, objectList, declaredClassMap,
marshalDesc.getPropertyDescriptorMap(cls));
QName wrapperQName = new QName(operationDesc.getResponseWrapperTargetNamespace(),
operationDesc.getResponseWrapperLocalName());
// Make sure object can be rendered as an element
if (!marshalDesc.getAnnotationDesc(cls).hasXmlRootElement()) {
object = new JAXBElement(wrapperQName, cls, object);
}
// Put the object into the message
JAXBBlockFactory factory =
(JAXBBlockFactory)FactoryRegistry.getFactory(JAXBBlockFactory.class);
JAXBBlockContext blockContext = new JAXBBlockContext(packages, packagesKey);
blockContext.setWebServiceNamespace(ed.getTargetNamespace());
Block block = factory.createFrom(object,
blockContext,
wrapperQName); // The factory will get the qname from the value
m.setBodyBlock(block);
// Now place the headers in the message
if (headerPDEList.size() > 0) {
// Use "by java type" marshalling if necessary
for (PDElement pde : headerPDEList) {
Class actualType = pde.getParam().getParameterActualType();
if (MethodMarshallerUtils.isNotJAXBRootElement(actualType, marshalDesc)) {
pde.setByJavaTypeClass(actualType);
}
}
MethodMarshallerUtils.toMessage(headerPDEList, m, packages, null);
}
// Enable SWA for nested SwaRef attachments
if (operationDesc.hasResponseSwaRefAttachments()) {
m.setDoingSWA(true);
}
return m;
} catch (Exception e) {
throw ExceptionFactory.makeWebServiceException(e);