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 ...

Get Java & XML Data Binding now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.