Java Reference
In-Depth Information
to find files with a .xjbextension, or, if you're using a different extension, the name of the
file. Here I've called the schemalet dateTime.xjband put it in the same directory as my
LibraryBook.xsd.
Now let's run it, indicating -d for the directory to which you want your generated classes to
be written, the name of the schema to read, and -b for the binding switch, which here tells
XJC to look for all .xjbfiles in the current directory:
> xjc -d . LibraryBook.xsd -b .
Here is the result of the compilation:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"title",
"dueDate"
})
@XmlRootElement(name = "book")
public class Book {
@XmlElement(required = true)
protected String title;
@XmlElement(required = true, type = String.class)
@XmlJavaTypeAdapter(Adapter2 .class)
@XmlSchemaType(name = "date")
protected Date dueDate;
public Date getDueDate() {
return dueDate;
}
public void setDueDate(Date value) {
this.dueDate = value;
}
/...etc
}
I removed the comments in the generated code. You might have noticed the XmlTypeAdapter
annotation indicating that the type is modified using the Adapter2.classfile. What JAXB does
here is create a set of Adapter classes that match your customizations. These customizations
extend the XML adapter class, parameterized on two values: a type that JAXB knows how to
work with already and the bound type. It defines two methods: marshal and unmarshal, each
of which performs the actual translation at runtime.
Search WWH ::




Custom Search