Skip Headers
Oracle® XML Developer's Kit Programmer's Guide
10g Release 2 (10.1.2)
Part No. B14033-01
  Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

6 Using JAXB Class Generator

This chapter contains these topics:

What Is JAXB?

Java Architecture for XML Binding (JAXB) consists of an API and tools that map to and from XML data and Java objects. It is an implementation of the JSR-31 "The Java Architecture for XML Binding (JAXB)", Version 1.0, recommendation of the JCP (Java Community Process). JSR is a Java Specification Request of the JCP.

The JAXB compiler generates the interfaces and the implementation classes corresponding to the XML Schema. The classes can be used to read, manipulate and re-create XML documents. The JAXB compiler generates Java classes corresponding to an XML Schema, and interfaces that are needed to access XML data. The Java classes, which can be extended, give you access to the XML data without any specific knowledge about the underlying data structure.


Note:


Replacing the XML Class Generator with JAXB Class Generator

You are requested to use JAXB Class Generator for new applications in order to use the object binding feature for XML data. The Oracle9i Class Generator for Java is deprecated. However, the Oracle9i Class Generator runtime was included in release 10.1 and is supported for the duration of the 10.x releases.

Unmarshalling, Marshalling, and Validating Using JAXB

Unmarshalling is defined as moving data from an XML document to the Java generated class objects. Each object is derived from an instance of the schema component in the input document. Because of the inherent weaknesses of DTDs, they are not supported by JAXB, but a DTD can be converted to an XML Schema that is then used by JAXB.

Marshalling is defined as creating an XML document from Java objects by traversing a content tree of instances of Java classes.

Validation is a prerequisite to marshalling if content has changed in the Java representation. Validation is verifying that the content tree satisfies the constraints defined in the schema. The tree is defined as valid when marshalling the tree generates a document that is valid according to the source schema. If unmarshalling includes validation that is error-free then the input document and the content tree are valid. However, validation is not required during unmarshalling.

Validation comes in these forms:

Using JAXB Class Generator

To build a JAXB application, start with an XML Schema file. Build and use a JAXB application by performing these steps:

  1. Generate the Java source files by submitting the XML Schema file to the binding compiler. The binding compiler could be invoked through the command-line utility called orajaxb.

  2. Compile the Java source code using JDK 1.3 or higher.

  3. 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.


      See Also:

      http://java.sun.com/xml/jaxb/faq.html for more information on JAXB

Features Not Supported in JAXB

The Oracle release does not support the following:

JAXB Class Generator Command-Line Interface

The JAXB class generator command-line interface is accessed this way:

oracle.xml.jaxb.orajaxb [-options]

where the options are listed in Table 6-1:

Table 6-1 JAXB Class Generator Command-line Interface

Option Description
-help Prints the help message text
-version Prints the release version
-outputDir OutputDir The directory in which to generate Java source
-schema SchemaFile The input schema file
-targetPkg targetPkg The target package name
-interface Generate only the interfaces

JAXB Compared with JAXP

The following lists summarize the advantages of JAXB.

Use JAXB when you want to:

For more information about JAXB:


See Also:


The Java API for XML Processing (JAXP), that enables applications to parse and transform XML documents using an API that is independent of a particular XML processor implementation, is implemented by Oracle.


See Also:

"Using JAXP"

Use JAXP when you want to: