"Unmarshalling is the process of converting an XML document into a corresponding set of Java objects. Unmarshalling in JAXB 2.0 is easy. First, you create a JAXBContext context object. The context object is the starting point for marshalling, unmarshalling, and validation operations. Here you specify the Java package containing your JAXB-mapped classes:"
"Of the solutions available in Java, the Java Architecture for XML Binding, better known as JAXB, seems to have finally turned the corner and is now part of the Java Web Services Developer Pack. For those watching the Java-XML binding over the last few years, a nagging question has been, "What is the current state of JAXB and how well does it represent the java-XML binding space?" This being a "state of ..." article, the audience will be senior architects that want to get a bird's-eye view of JAXB as well as a critical analysis of the strengths and weaknesses of the tool. Additional references to get into the introductory and development details of JAXB are provided at the end of the article."
"In the first article in this two-part series, we looked at some advanced uses of Jakarta Ant's build tool to handle automatically executing xjc, the code-from-XML generation tool from the Java API for XML Binding (JAXB). We discovered that Ant has some minor flaws in handling one-to-many file dependencies, and that the only way to guarantee that Ant calls the code generator is to make sure that Ant calls the code generator on every build. In addition, we found that Ant could also be used to solve a smaller (but more common) problem, in which you must explicity provide Javadoc with a list of packages being documented. Both of these problems can be solved, but only by writing our own Ant Task objects to handle them, as we'll see in this article."
"Java Architecture for XML Binding (JAXB) is a specification (or standard) that automates the mapping between XML documents and Java objects and vice versa. One of the primary components of JAXB is the schema compiler. The schema compiler is the tool used to generate Java bindings from an XML schema document. If used in its default mode (for non-trivial applications), the compiler usually generates bindings that are awkward to work with. This article will look at various methods you can use to customize the generated bindings."
"Ant is the build tool developed and used by the Jakarta project, a group under the Apache banner, who have been developing a number of open source Java tools and libraries for client-server development (including Tomcat, the Servlet/JSP reference implementation). Though the example here uses JAXB, the technique is also workable for other code-generation tools, such as IDL or RMI. We'll work with refactoring the checkbook example from the JAXB distribution to use packages."
"This article introduces you to the basics of Java Architecture for XML Binding (JAXB) Early Access Implementation v 1.0. You will learn a few basic uses of the API and tools that the EA v 1.0 provides. This paper provides brief explanations on how to create simple binding codes using the API and tools. In addition, this paper also discusses a few situations where JAXB shows its strengths, and is intended for developers who have working understanding of the Java programming language, are familiar with XML, and interested in getting a brief introduction to JAXB."
"XML and Java technology are recognized as ideal building blocks for developing Web services and applications that access Web services. A new Java API called Java Architecture for XML Binding (JAXB) can make it easier to access XML documents from applications written in the Java programming language."
"The latter solution is called mapping, binding, or translation, and it is the solution JAXB utilizes. In the mapping process, a developer usually uses a parser (SAX or DOM) to get at the data in an XML file and then uses the data to populate a domain object model. Often, the developer creates one class per element of the document, assigning values to attributes from either the data contained within the tag or the tag attributes. If a tag contains further elements, then the developer creates relationships from the class that represent the outer tag to the class representing the inner tag. Of course, before the developer populates an object with data, he or she has to first instantiate it. So the developer also writes code that manages both the creation and collection of objects."
"Java Architecture for XML Binding Java Architecture for XML Binding (JAXB) was developed in Java Specification Request (JSR) 31. It was written by an industry expert group under the auspices of the Java Community Process. By standardizing the XML data binding interface and providing a conformance test, JAXB allows you to choose among different XML binding implementations without having to rewrite your application. JAXB also comes with a standard implementation, which we'll use to show you how to bind the UBL schema to Java objects."
"With the proliferation of an XML-based information exchange, the industry is bound to write lots of Java code to consume XML Schema-based documents. Java Architecture for XML Binding (JAXB) provides a convenient way to bind an XML Schema to a representation in Java code, making it easy for developers to incorporate XML data and processing functions in applications based on Java technology without having to know much about the details of XML parsing."
"Final Thoughts By this time, hopefully, we have come to terms with how JAXB can be used in a J2EE-based enterprise application. Even in a simple example like the one described in this article, where can we see this being used? Say, for example, there is a book search capability that allows nearby libraries to search for a list of books in CityLibrary that matches a specific criterion (for example, books by a certain author). The results of the search can be easily returned in an XML format using code that is similar to the marshallIt method in our example. In more sophisticated examples, a J2EE application can accept XML documents (conforming to the XML Schema from which Java artifacts have been generated a priori) and then use JAXB to create Java objects that can then be easily used in order to perform application-specific processing."
"It's nice to see properly handled whitespace. Even though the CDATA section is removed, the whitespace is properly preserved. In addition, the lengthy space in the middle of the description of the Martin OM-28VR guitar is kept as is, a properly handled issue."
"Last year, I wrote an article showing how to use the Castor framework for mapped data binding of Java objects to XML documents. I promised a follow-up that would look at code generation approaches including coverage of JAXB, the standard API for data binding in the Java language under development through the Java Community Process (JCP). Right after that earlier article went to publication Sun announced a major change in direction on JAXB (see JAXB rearchitecture). Given this change, I felt it was better to wait until something closer to the final JAXB code was available before writing the follow-up, and I'm happy to finally be able to do so now!"
"Before you can do much with JAXB, generate some Java classes to represent your XML data. You'll work with a fairly simply XML document in these samples, shown in Listing 1. This is a simple listing of one of my favorite things, guitars."
"You need to create a Java application to marshal an XML document. Select File>New>General>Java Class to add a Java class. In the Create Java class frame, specify class name (JAXBMarshaller) and package name (jaxb) and click OK. Java class JAXBMarshaller.java gets added to package jaxb. In the marshaller application, import the JAXB API package."