Professional Documents
Culture Documents
What is JAXB?
JAXB defines the behavior of a standard set of tools and interfaces
that automatically generate java class files from XML schema
JAXB is a framework or architecture, not an implementation.
Sun provides a reference implementation of JAXB with the Web
Services Developers kit, available as a separate download
http://java.sun.com/webservices/downloads/webservicespack.html
High-level comparison
Before diving into details of JAXB, its good to see a
birds-eye-view of the difference between JAXB and SAX
and/or DOM-like parsers
Study the books/ examples under the examples/jaxb
directory on the course website
JAXB steps
Note that this creates a huge number of files that together represent the
content of the books.xsd schema as a set of Java classes
It is not necessary to know all of these classes. Well study them only
at a high level so we can understand how to use them
Example: students.xsd
Generated interfaces
test/lottery/Students.java
Represents the root node <students>
test/lottery/StudentsType.java
Represents the unnamed type of each student object
Generated implementations
Each interface is implemented in the impl directory
test/lottery/impl/StudentsImpl.java
Vendor-specific implementation of the Students inteface
test/lottery/impl/StudentsTypeImpl.java
Vendor-specific implementation of the StudentsType Interface
Compilation
Next, the generated classes must be compiled:
javac students/*.java students/impl/*.java
Generated docs
Java API docs for these classes are generated in
students/docs/api/*.html
Sample Programs
Sample Programs
Easiest way to learn is to cover certain generic sample cases. These are
all on the course website under cspp53025/examples/jaxb
Summary of examples:
student/
Use JAXB to read an xml document composed of a single student complex
type
student/
Same, but for an xml document composed of a sequence of such student types
of indefinite length
purchaseOrder/
Another read example, but for a more complex schema
modify-marshal
Purchase-order example modified to read XML, change it and write
back to XML
The JAXB binding model follows the default binding rules summarized below:
A named simple type definition with a basetype that derives from "xsd:NCName" and has enumeration facets.
Attribute use
Particle with a term that is an element reference or local element declaration.
Bind model group with a repeating occurrence and complex type definitions with mixed {content type} to:
A general content property; a List content-property that holds Java instances representing element information items and character data
items.