Sun Microsystems has announced the availability of a JAXB beta Reference Implementation, version 0.75 Public Draft Specification, API documentation, and User's Guide. JAXB (Java Architecture for XML Binding) "provides an API and tools that automate the mapping between XML documents and Java objects. It is a Java technology that enables you to generate Java classes from XML schemas, providing an efficient and standard way to map between XML and Java code. With JAXB, you can quickly bind XML schemas to Java representations, making it easy to incorporate XML data and processing functions in your Java applications. JAXB makes XML easy to use by compiling an XML schema into one or more Java technology classes. The combination of the schema derived classes and the binding framework enable one to perform the following operations on an XML document: (1) unmarshal XML content into a Java representation; (2) access, update and validate the Java representation against schema constraint; (3) marshal the Java representation of the XML content into XML content. The current specification release provides several enhancements, including support for a subset of W3C XML Schema and XML Namespaces, more flexible unmarshalling and marshalling functionality, and validation process enhancements."
Specification information: The Java Architecture for XML Binding (JAXB). Public Draft 2, V0.75. October 4, 2002. Edited by Joseph Fialli and Sekhar Vajjhala. Status: Pre-FCS. 194 pages. Comments: send email to firstname.lastname@example.org.
From the The Java Architecture for XML Binding (JAXB) v0.75 specification Overview: "The primary components of the XML data-binding facility described in this specification are the binding compiler, the binding framework, and the binding language. (1) The binding compiler transforms, or binds, a source schema to a set of content classes in the Java programming language. As used in this specification, the term schema includes the W3C XML Schema as defined in the XML Schema 1.0 Recommendation; (2) The binding runtime framework provides the interfaces for the functionality of unmarshalling, marshalling, and validation for content classes. (3) The binding language is an XML-based language that describes the binding of a source schema to a Java representation. The binding declarations written in this language specify the details of the package, interfaces and classes derived from a particular source schema."
From the v0.75 specification Introduction:
Any nontrivial application of XML will be based upon one or more schemas and will involve one or more programs that create, consume, and manipulate documents whose syntax and semantics are governed by those schemas. While it is certainly possible to write such programs using the lowlevel SAX parser API or the somewhat higher-level DOM parse-tree API, doing so is likely to be tedious and error-prone. The resulting code is also likely to contain many redundancies that will make it difficult to maintain as bugs are fixed and as the schemas evolve.
It would be much easier to write XML-enabled programs if we could simply map the components of an XML document to in-memory objects that represent, in an obvious and useful way, the document's intended meaning according to its schema. Of what classes should these objects be instances? In some cases there will be an obvious mapping from schema components to existing classes, especially for common types such as String, Date, Vector, and so forth. In general, however, classes specific to the schema being used will be required. Rather than burden developers with having to write these classes we can generate the classes directly from the schema, thereby creating a Java-level binding of the schema.
An XML data-binding facility therefore contains a binding compiler that binds components of a source schema to schema-derived Java content classes. Each class provides access to the content of the corresponding schema component via a set of JavaBeans-style access (i.e., get and set) methods. Binding declarations provides a capability to customize the binding from schema components to Java representation. Such a facility also provides a binding framework, a runtime API that, in conjunction with the derived classes, supports three primary operations: (1) The unmarshalling of an XML document into a tree of interrelated instances of both existing and schema-derived classes, (2) The marshalling of such content trees back into XML documents, and (3) The validation of content trees against the constraints expressed in the schema.
The unmarshalling process has the capability to check incoming XML documents for validity with respect to the schema. Similarly, a JAXB implementation provides a means to enforce the constraints expressed in the schema; some of these constraints may always be enforced, while others may only be checked upon explicit request. Validation of a content tree before the marshalling process can be used to ensure that only valid documents are generated.
To sum up: Schemas describe the structure and meaning of an XML document, in much the same way that a class describes an object in a program. To work with an XML document in a program we would like to map its components directly to a set of objects that reflect the document's meaning according to its schema. We can achieve this by compiling the schema into a set of derived content classes that can be marshalled, unmarshalled and validated. Data binding thus allows XML-enabled programs to be written at the same conceptual level as the documents they manipulate, rather than at the more primitive level of parser events or parse trees.
From the FAQ document:
The Java Architecture for XML Binding (JAXB) simplifies the creation and maintenance of XML-enabled Java applications. JAXB provides a binding compiler and a runtime framework to support a two-way mapping between XML documents and Java objects. The binding compiler translates W3C XML Schema into one or more Java classes without requiring the developer to write complex parsing code. The schema-derived classes and binding framework enable error and validity checking of incoming and outgoing XML documents, thereby making it possible to ensure that only valid, error-free messages are accepted, processed, and generated by a system.
JAXB, SAX, and DOM: "SAX is an event-driven XML parser that is appropriate for high-speed processing of XML because it does not produce a representation of the data in memory. DOM, on the other hand, produces an in-memory data representation, which allows an application to manipulate the contents in memory. Both SAX and DOM automatically perform structure validation. An application could perform content validation with SAX and DOM, but such an application must provide the necessary extra code, which might be complicated, error-prone, and difficult to maintain. A JAXB application can perform structure and content validation with Java classes that it generates from a schema. A JAXB application builds an in-memory data structure, like a DOM, by marshalling an XML document to build a content tree, which contains objects that are instances of the derived classes. However, unlike a DOM tree, a content tree is specific to one source schema, does not contain extra tree-manipulation functionality, allows access to its data with the derived classes' accessor methods, and is not built dynamically. For these reasons, a JAXB application uses memory more efficiently than a DOM application does. If the content of a document is more dynamic and not well-constrained, DOM and SAX are more appropriate than JAXB for processing XML content that does not have a well-known schema prior to processing the content.
Building a JAXB application:
- Generate the Java source files by submitting the XML Schema [W3C 2001 Recommendation for XML Schema] to the binding compiler. One can use custom binding declarations to override the default binding of XML Schema components to Java representations
- Compile the Java source code
- With the classes and the binding framework, write Java applications that:
- Build object trees representing XML data that is valid against the XML Schema by either unmarshalling the data from a document or instantiating the classes you created
- Access and modify the data
- Optionally validate the modifications to the data relative to the constraints expressed in the XML Schema Marshal the data to new XML documents
- JAXB Downloads and Specifications
- JAXB Beta Reference Implementation
- JAXB v0.75 Public Draft Specification
- API documentation. JAXB Runtime Library. Public Draft 2 specification, version 0.75, October, 2002.
- JAXB User's Guide. "This guide provides instructions for using the Java Architecture for XML Binding (JAXB) to bind XML schemas to Java representations, making it easy for Java developers to incorporate XML data and processing functions in Java applications. The goal of this guide is to provide 'hands-on' instructions for using JAXB in a Java application, specifically by means of the JAXB 1.0 Reference Implementation (JAXB RI)... primarily for Java programmers who want to manipulate XML data in their Java applications."
- JAXB FAQ document
- JAXB Release Notes for Specification Version 0.75, Reference Implementation (RI)
- Java Technology and XML
- XML at Sun
- Java Web Services Developer Pack
- Java Technology and XML Downloads
- "Early Access Release of Java Architecture for XML Binding (JAXB)." News item June 14, 2002.
- Related announcement: Apache Xalan XSLT Compiler (XSLTC) Integrated into the Java Web Services Developer Pack (WSDP)
- "Java Architecture for XML Binding (JAXB)" - Main reference page.