String partPrefix = (String)context.getProperty(PART_PREFIX_KEY);
String responseNamespace = configuration.getResponseNamespaceURI();
String responsePrefix = configuration.getResponseDefaultPrefixURI();
NamespacePrefixTracker namespaceManager =
context.getNamespacePrefixTracker();
namespaceManager.startPrefixMapping(responsePrefix,
responseNamespace);
consumer.startPrefixMapping(responsePrefix, responseNamespace);
// Get the qnames that are constant for this operation process
String responseQName = SAXUtils.createPrefixedName(responsePrefix,
RESPONSE);
String messageQName = SAXUtils.createPrefixedName(responsePrefix,
MESSAGE);
consumer.startElement(responseNamespace, RESPONSE, responseQName,
new AttributesImpl());
consumer.startElement(responseNamespace, MESSAGE, messageQName,
new AttributesImpl());
// If the parts have a prefix we need to map them now.
if (partPrefix != null) {
namespaceManager.startPrefixMapping(partPrefix,
partNamespace);
consumer.startPrefixMapping(partPrefix, partNamespace);
}
for (int i = 0; i < message.size(); i++) {
Part part = message.retrievePart(i);
String partQName = SAXUtils.createPrefixedName(partPrefix,
part.getName());
consumer.startElement(partNamespace, part.getName(), partQName,
new AttributesImpl());
Object value = part.getValue();
if (value instanceof Element) {
// This is a DOM Element. Use DOMToSAX.
Node node = (Node)value;
DOMToSAX dom2SAX = new DOMToSAX(node);
ContextManagerProcess cup = new ContextManagerProcess(true);
cup.setPipeline(getPipeline());
cup.setNextProcess(consumer);
dom2SAX.setContentHandler(cup);
dom2SAX.parse();
} else {
// Just a bunch of characters.
String chars = value.toString();
consumer.characters(chars.toCharArray(), 0, chars.length());
}
consumer.endElement(partNamespace, part.getName(), partQName);
}
// If the parts have a prefix we need to unmap them now.
if (partPrefix != null) {
consumer.endPrefixMapping(partPrefix);
namespaceManager.endPrefixMapping(partPrefix);
}
consumer.endElement(responseNamespace, MESSAGE, messageQName);
consumer.endElement(responseNamespace, RESPONSE, responseQName);
consumer.endPrefixMapping(responsePrefix);
namespaceManager.endPrefixMapping(responsePrefix);
}