Welcome to Java4u

A Single Place for all Java Resources

Looking for something?

Subscribe to this blog!

Receive the latest posts by email.

.Just enter your email below if you want to subscribe!


Thursday, July 3, 2014

JAXB : Architecture & Binding Process

XML Schema : An XML schema is a definition file for a XML document & uses XML syntax to describe the relationships among elements, attributes and entities in an XML document. It maintains the rule/syntax for a XML document. An XML document need not always have a schema. While using JAXB XML schema is not a mandatory requirement. Process can start with java pojo classes. But it is convenient to have associated XML schema so that we can use a binding compiler and generate the java classes.

Binding Customizations : By default, the JAXB binding compiler binds Java classes and packages to a source XML schema based on rules. In most cases, the default binding rules are sufficient to generate a robust set of schema-derived classes from a wide range of schemas.

Binding Compiler : The JAXB binding compiler is the core of the JAXB processing model. Its function is to transform, or bind, a source XML schema to a set of JAXB content classes in the Java programming language.

Implementation of javax.xml.bind
: The JAXB binding framework implementation is a runtime API that provides interfaces for unmarshalling, marshalling, and validating XML content in a Java application. The binding framework comprises interfaces in the javax.xml.bind package.

Schema-Derived Classes: These are the schema-derived classes generated by the binding JAXB compiler. The specific classes will vary depending on the input schema.

Java Application : In the context of JAXB, a Java application is a client application that uses the JAXB binding framework to unmarshal XML data, validate and modify Java content objects, and marshal Java content back to XML data.

XML Input Documents: XML content that is unmarshalled as input to the JAXB binding framework -- that is, an XML instance document, from which a Java representation in the form of a content tree is generated.

XML Output Documents : XML content that is marshalled out to an XML document. In JAXB, marshalling involves parsing an XML content object tree and writing out an XML document that is an accurate representation of the original XML document, and is valid with respect the source schema.

Binding Process :
Generate classes: An XML schema is used as input to the JAXB binding compiler to generate JAXB classes based on that schema.

Compile classes
: All of the generated classes, source files, and application code must be compiled.

UnMarshal: XML documents written according to the constraints in the source schema are unmarshalled by the JAXB binding framework.

Note : JAXB also supports unmarshalling XML data from sources other than files/documents, such as DOM nodes, string buffers, SAX Sources, and so forth.

Generate content tree: The unmarshalling process generates a content tree of data objects instantiated from the generated JAXB classes; this content tree represents the structure and content of the source XML documents.

Validate (optional) : The unmarshalling process optionally involves validation of the source XML documents before generating the content tree. Note that if you modify the content tree in Step 6, below, you can also use the JAXB Validate operation to validate the changes before marshalling the content back to an XML document.

Process content : The client application can modify the XML data represented by the Java content tree by means of interfaces generated by the binding compiler.

Marshal : The processed content tree is marshalled out to one or more XML output documents. The content may be validated before marshalling.