Java Reference
In-Depth Information
Based on this type definition, JAXB will generate a Book.javafile. The complexType is
matched with a Java class, and the children of the type sequence are each matched with prop-
erties in the order in which they were declared in the sequence. Because none of your elements
indicated nillable="true" , each field is annotated with @XmlElement(required = true) .
This acts as a hint to the marshaler that a Java object instance that does not define values for
each field should fail validation. See Example 2-13 .
Example2-13.Book.java class generated by JAXB
package com.soacookbook.ns.catalog;
import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Book", propOrder = {
"isbn",
"author",
"title",
"category"
})
public class Book {
@XmlElement(required = true)
protected String isbn;
@XmlElement(required = true)
protected Author author;
@XmlElement(required = true)
protected String title;
@XmlElement(required = true)
protected Category category;
//... getters and setters ommitted
There are a few more things to look at here. Note that the generated package is named after the
namespace from your Book.xsd, and the fields are themselves represented by classes match-
ing their complexType definitions. For example, the Book type is composed in part by a Cat-
egory object:
<xsd:simpleType name="Category">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="COOKING" />
<xsd:enumeration value="LITERATURE" />
<xsd:enumeration value="PHILOSOPHY" />
<xsd:enumeration value="PROGRAMMING" />
</xsd:restriction>
</xsd:simpleType>
Search WWH ::




Custom Search