O'Reilly logo

Java & XML Data Binding by Brett McLaughlin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Additional Features

Castor offers several additional features that are not present in JAXB (or any other open source data binding package); these features are centered around mapping between other data formats and Java. For example, Castor allows you to map database objects and LDAP queries—in addition to XML documents—to Java. This is obviously a book on XML data binding, so I’ll touch on these topics only briefly here; however, you may find that you need a package that provides APIs for SQL, LDAP, and XML. If that is the case, Castor is an excellent choice.

Database and Directory Server Mappings

Castor allows mapping between databases and directory servers to Java, as well as the standard XML-to-Java mappings discussed in this chapter and the rest of this book. This obviously makes it easier to work with these non-Java structures, particularly when a similar API can be used for XML, LDAP, and databases. The result is data source transparency, which allows your code to switch easily from an XML store to a database or from a database to a directory server.

These mappings are accomplished through simple XML mapping files, like the one shown here:

<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN" "http://castor.exolab.org/mapping.dtd"> <mapping> <!-- Mapping for Employees --> <class name="javajaxb.generated.Employee" identity="id"> <description>A Company Employee</description> <map-to table="EMPLOYEES" xml="employee" /> <field name="id" type="integer" > <sql ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required