if (isRPC) {
QName rpcWrapQName = new QName(bodyDef.getNamespaceURI(), rpcWrapper);
OMElement partWrapper = soapBody.getFirstChildWithName(rpcWrapQName);
if (partWrapper == null)
throw new OdeFault("Message body doesn't contain expected part wrapper.");
// In RPC the body element is the operation name, wrapping parts. Order doesn't really matter as far as
// we're concerned. All we need to do is copy the soap:body children, since doc-lit rpc looks the same
// in ode and soap.
for (Part pdef : bodyParts) {
OMElement srcPart = partWrapper.getFirstChildWithName(new QName(null, pdef.getName()));
if (srcPart == null)
throw new OdeFault("SOAP body doesn't contain required part.");
message.setPart(srcPart.getLocalName(), OMUtils.toDOM(srcPart));
}
} else {
// In doc-literal style, we expect the elements in the body to correspond (in order) to the
// parts defined in the binding. All the parts should be element-typed, otherwise it is a mess.
Iterator<OMElement> srcParts = soapBody.getChildElements();
for (Part partDef : bodyParts) {
if (!srcParts.hasNext())
throw new OdeFault("SOAP Mesaage body doesn't contain required part.");
OMElement srcPart = srcParts.next();
if (partDef.getElementName() == null)
throw new OdeFault("Binding defines non element doc list parts.");
if (!srcPart.getQName().equals(partDef.getElementName()))
throw new OdeFault("Unexpected element in SOAP body");
Document doc = DOMUtils.newDocument();
Element destPart = doc.createElementNS(null, partDef.getName());
destPart.appendChild(doc.importNode(OMUtils.toDOM(srcPart), true));
message.setPart(partDef.getName(), destPart);
}