Chapter 4 XML Processing
171
implementation of the schema derived classes, and they may also expose
the methods from the schema derived classes as part of the domain specific
class. Additionally, as a side effect, if the developer is not careful, this may
result in tightly binding the business logic to the schemas from which the
classes were generated.
c. The developer can use aggregation or composition and design domain
specific classes that only expose domain oriented methods and delegate to
the schema derived classes. Since the domain specific classes only depend
on the interfaces of the schema derived classes, the interfaces of the
domain specific classes may therefore not be as sensitive to changes in the
original schema.
Note that when no well defined schema or variable in nature (abstract) or in
number (including new schema revisions) is available, JAXB may be cumber
some to use due to the tight coupling between the schemas and the schema
derived classes. Also note that the more abstract the schema, the less effective the
binding.
Consider using the XML data binding programming model, such as JAXB,
when you have any of the following conditions:
E
You want to deal directly with plain Java objects and do not care about, nor
want to handle, document representation.
E
You are consuming or producing documents.
E
You do not need to maintain some aspects of a document, such as comments
and entity references. The JAXB specification does not require giving access
to the underlying document representation (infoset). For example, the JAXB
reference implementation is based on SAX 2.0 and therefore does not maintain
an underlying document representation. However, other implementations may
be layered on top of a DOM representation. A developer may fall back on this
DOM representation to access unexposed infoset elements.
E
You want to process the content tree more than once.
E
You want random access to parts of the document. For example, you may want
to traverse back and forth within the document.
E
Memory usage may be less of an issue. A JAXB implementation, such as the
standard implementation, creates a Java representation of the content of a doc
ument that is much more compact than the equivalent DOM tree. The standard
New Page 1