Java Architecture for XML Binding
Encyclopedia
Java Architecture for XML Binding (JAXB) allows Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

 developers to map Java classes
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...

 to XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

 representations. JAXB provides two main features: the ability to marshal
Serialization
In computer science, in the context of data storage and transmission, serialization is the process of converting a data structure or object state into a format that can be stored and "resurrected" later in the same or another computer environment...

 Java objects
Object (computer science)
In computer science, an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure...

 into XML and the inverse, i.e. to unmarshal XML back into Java objects. In other words, JAXB allows storing and retrieving data in memory in any XML format, without the need to implement a specific set of XML loading and saving routines for the program's class structure. It is similar to xsd.exe and XmlSerializer in the .NET Framework
.NET Framework
The .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...

.

JAXB is particularly useful when the specification is complex and changing. In such a case, regularly changing the XML Schema definitions to keep them synchronised with the Java definitions can be time consuming and error prone.

JAXB is a part of Java SE platform and one of the APIs
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...

 in the Java EE platform
Java Platform, Enterprise Edition
Java Platform, Enterprise Edition or Java EE is widely used platform for server programming in the Java programming language. The Java platform differs from the Java Standard Edition Platform in that it adds libraries which provide functionality to deploy fault-tolerant, distributed, multi-tier...

, and is part of the Java Web Services Development Pack
Java Web Services Development Pack
The Java Web Services Development Pack is a free software development kit for developing Web Services, Web applications and Java applications with the newest technologies for Java....

 (JWSDP). It is also one of the foundations for WSIT
Web Services Interoperability Technology
Web Services Interoperability Technology is an open-source project started by Sun Microsystems to develop the next-generation of Web service technologies...

. JAXB is part of SE version 1.6.

JAXB 1.0 was developed under the Java Community Process
Java Community Process
The Java Community Process or JCP, established in 1998, is a formalized process that allows interested parties to get involved in the definition of future versions and features of the Java platform....

 as JSR 31. , JAXB 2.0 is being developed under JSR 222. Reference implementations for these specifications are available under the CDDL open source license at java.net.

Usage

The tool "xjc" can be used to convert XML Schema and other schema file types (as of Java 1.6, RELAX NG
RELAX NG
In computing, RELAX NG is a schema language for XML, based on Murata Makoto's RELAX and James Clark's TREX. A RELAX NG schema specifies a pattern for the structure and content of an XML document...

, XML DTD
Document Type Definition
Document Type Definition is a set of markup declarations that define a document type for SGML-family markup languages...

, and WSDL
Web Services Description Language
The Web Services Description Language is an XML-based language that is used for describing the functionality offered by a Web service. A WSDL description of a web service provides a machine-readable description of how the service can be called, what parameters it expects and what data structures...

 are supported experimentally) to class representations. Classes are marked up using annotations
Java annotation
An annotation, in the Java computer programming language, is a special form of syntactic metadata that can be added to Java source code. Classes, methods, variables, parameters and packages may be annotated...

 from javax.xml.bind.annotation.* namespace, for example, @XmlRootElement and @XmlElement. XML list sequences are represented by attributes of type java.util.List. Marshallers and Unmarshallers are created through an instance of JAXBContext.

In addition, JAXB includes a "schemagen" tool which can essentially perform the inverse of "xjc", creating an XML Schema from a set of annotated classes.

Default data type bindings

The table below lists the mappings of XML Schema (XSD) data types to Java data types in JAXB.
XML Schema Type Java Data Type
xsd:string java.lang.String
xsd:positiveInteger java.math.BigInteger
xsd:int int
xsd:long long
xsd:short short
xsd:decimal java.math.BigDecimal
xsd:float float
xsd:double double
xsd:boolean boolean
xsd:byte byte
xsd:QName javax.xml.namespace.QName
xsd:dateTime javax.xml.datatype.XMLGregorianCalendar
xsd:base64Binary byte[]
xsd:hexBinary byte[]
xsd:unsignedInt long
xsd:unsignedShort int
xsd:unsignedByte short
xsd:unsignedLong java.math.BigDecimal
xsd:time javax.xml.datatype.XMLGregorianCalendar
xsd:date javax.xml.datatype.XMLGregorianCalendar
xsd:g javax.xml.datatype.XMLGregorianCalendar
xsd:anySimpleType (for xsd:element of this type) java.lang.Object
xsd:anySimpleType (for xsd:attribute of this type) java.lang.String
xsd:duration javax.xml.datatype.Duration
xsd:NOTATION javax.xml.namespace.QName

See also

  • XML data binding
    XML data binding
    XML data binding refers to a means of representing information in an XML document as an object in computer memory. This allows applications to access the data in the XML from the object rather than using the DOM or SAX to retrieve the data from a direct representation of the XML itself.An XML data...

  • JiBX
    JiBX
    JiBX is an open source Java framework for XML data binding. It solves the same problem as JAXB, XMLBeans and JDOM , but works differently. It lets developers work with data from XML documents using Plain Old Java Objects . The JiBX framework uses a binding definition to tell it how the Java...

     – one of the fastest XML data binders
  • XMLBeans
    XMLBeans
    XMLBeans is a Java-to-XML binding framework which is part of the Apache Software Foundation XML project.-Description:XMLBeans is a tool that allows access to the full power of XML in a Java friendly way...

     – a similar and complementary technology to JAXB from Apache Software Foundation
    Apache Software Foundation
    The Apache Software Foundation is a non-profit corporation to support Apache software projects, including the Apache HTTP Server. The ASF was formed from the Apache Group and incorporated in Delaware, U.S., in June 1999.The Apache Software Foundation is a decentralized community of developers...

  • TopLink
    TopLink
    In computing, TopLink is an object-relational mapping package for Java developers. It provides a framework for storing Java objects in a relational database or for converting Java objects to XML documents....

     – an object to relational and object to XML
    XML
    Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

     mapper from Oracle
    Oracle Corporation
    Oracle Corporation is an American multinational computer technology corporation that specializes in developing and marketing hardware systems and enterprise software products – particularly database management systems...

     that supports JAXB 1.0
  • EclipseLink
    EclipseLink
    EclipseLink is the open source Eclipse Persistence Services Project from the Eclipse Foundation. The software provides an extensible framework that allows Java developers to interact with various data services, including databases, web services, Object XML mapping , and Enterprise Information Systems...

     MOXy – Open Source
    Open source
    The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...

     implementation of JAXB and object XML mapping services under the Eclipse Foundation
    Eclipse Foundation
    The Eclipse Foundation is a not-for-profit, member supported corporation that hosts the open-source Eclipse Projects and helps cultivate both an open source community and an ecosystem of complementary products and services...


External links


Articles

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK