Implementing XML Based Applications
1. Set up the JAXB context (
) with the list of schema derived pack
ages that are used to unmarshal the documents.
2. Unmarshal an XML document into a content tree. Validation of the document
is performed if enabled by the application.
3. You can then directly apply the application's logic to the content tree. Or, you
can extract and consolidate information from the content tree and then apply
the application's logic on the consolidated information. As described later, this
consolidated information may very well be domain specific objects that may
expose a more adequate, schema independent interface.
This programming model also supports serialization to XML, or marshalling a
content tree to an XML format. Marshalling of a document has the following
1. Modify an existing content tree, or create a new tree, from the application's
business logic output.
2. Optionally, validate in memory the content tree against the source schema.
Validation is performed in memory and can be applied independently of the
3. Marshal the content tree into an XML document.
There are various ways a developer can design an application with the
schema derived classes that JAXB generates:
1. The developer may use them directly in the business logic, but, as noted in
Choosing Processing Models on page 151, this tightly binds the business
logic to the schemas from which the classes were generated. This type of usage
shares most of the issues of a document centric processing model.
2. The developer can use the schema derived classes in conjunction with an
object centric processing model:
a. The developer may design domain specific classes whose instances will be
populated from the content objects created by unmarshalling an XML
document, and vice versa.
b. The developer may design domain specific classes, which inherit from the
schema derived classes, and define additional domain oriented methods.
The problem with this design is that these classes are tightly coupled to the