Advertisment

JAXB: JAVA architecture for XML binding

author-image
CIOL Bureau
Updated On
New Update

By: Sahana Hussain

Advertisment

The Java Architecture for XML Binding (JAXB) is a new Java technology in the Java Web Services Developer Pack (JWSDP) that enables you to generate Java classes from XML schemas. JAXB provides a free, fast and convenient way to bind XML schemas to Java representations making it easier for Java developer to incorporate XML data and processing functions in Java without having to know much about XML itself.





The Extensible Markup Language (XML) and Java technology are natural partners in helping developers exchange data and programs across the Internet. That's because XML has emerged as the standard for exchanging data across disparate systems and Java technology provides a platform for building portable applications. This partnership is particularly important for Web services, which promise users and application developers program functionality on demand from anywhere to anywhere on the Web. XML and Java technology are recognized as ideal building blocks for developing Web services and applications that access Web services.





The JAXB binding framework provides methods for unmarshalling XML instance documents into Java content trees -- a hierarchy of Java data objects that represent the source XML data -- and for marshalling Java content trees back into XML instance documents. The JAXB binding framework also provides methods for validating XML content as it is unmarshalled and marshalled.





What this means is that your Java applications can work with schema-compliant XML data as Java objects, leveraging native Java security models and programming methods. Moreover, Java developers do not need to be well versed in the intricacies of SAX or DOM processing models, or even in the arcane language of XML schema, to take advantage of ubiquitous, platform-neutral XML technologies





General JAXB Overview:

Implementing JAXB in your Java applications is typically a two-step process:





  1. One or more schemas are defined as needed, and then the JAXB binding compiler is run against these schemas to generate JAXB packages, classes, and interfaces.


  2. Java application developers use the generated JAXB packages and the JAXB utility packages in a binding framework to unmarshal, marshal, and validate XML content.
  3. Advertisment

    In addition to the general goals of XML-to-Java data binding, JAXB provides features to meet several important additional goals:





    • Ease of use-
    • JAXB makes it easy to access and modify XML documents within Java programs without having to deal with the complexities of SAX or DOM. Even if you don't know much about XML, you can compile an XML schema and immediately compile and start using the classes generated by JAXB.



    • Customization-
    • JAXB provides a standard way to customize the binding of existing schema components to Java representations. Sophisticated applications sometimes require fine control over the structure and content of schema-derived classes, both for their own purposes and for keeping pace with schema evolution.

    Advertisment



     



    • Portability-
    • You can write applications implementing JAXB in such a way that the JAXB components can be replaced without having to make significant changes to the rest of the source code.

    Advertisment



    • Support for on-demand validation -
    • When working with a content tree corresponding to an XML document, it is often necessary to validate the tree against the constraints in the source schema. With JAXB, it is possible to do this at any time, without the user having to first marshal the tree into XML



     



    • Provide clean "round-tripping"-
    • Transforming a Java content tree to XML content and back to Java content again results in equivalent Java content trees before and after the transformation.

    Advertisment



    How can you get JAXB?





    A JAXB Reference Implementation (JAXB RI) is included in the latest version (1.1) of the Java Web Services Developer Pack (JAVA WSDP 1.1). The Java WSDP is a free, integrated toolkit that allows Java developers to build, test and deploy XML applications, Web services, and Web applications.





    The JAXB RI includes binary code, a user's guide, the JAXB specification, and a rich set of sample applications and sample source code. In addition to the JAXB RI, you may want to download the Java Web Service Tutorial, which contains detailed instructions for using JAXB and all the other technologies in the Java WSDP. Finally, please visit the JAXB home page for the latest JAXB project information and specifications.

    Reference:

    www.sun.com



    tech-news