Chapter 4 XML Processing
161
// Returns the processed document as a Source object
public Source getDocument() throws ... {
return new StreamSource(new StringReader(
getDocumentAsString()));
}
// Returns the processed document as a String object
public String getDocumentAsString() throws ... {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
copyDocument(new StreamResult(stream));
return stream.toString(DEFAULT_ENCODING);
}
// Returns the orderId value extracted from the source document
public String getOrderId() {
return orderId;
}
}
Code Example 4.9
Supplier Service Endpoint Using
XML Document Editor
E
To summarize, it is recommended that you use a design similar to the XML
Document Editor presented above to abstract and encapsulate all XML docu
ment processing. In turn, the business object or service endpoint using such a
document editor only invokes the simple API provided by the document editor.
This hides all the complexities and details of interacting with the XML docu
ment from the business object clients.
As noted earlier, this design is not limited to the document centric processing
model where the application applies its business logic on the document itself. In
an object centric processing model, document editors can be used by the Web
service interaction layer closest to the service endpoint, to validate, transform, and
map documents to or from domain specific objects. In this case, using the docu
ment editor isolates the interaction logic from the XML processing logic.
New Page 1