Castor is a
data binding framework for
Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mo ...
with some features like Java to Java-to-XML binding, Java-to-SQL persistence, paths between Java objects,
XML documents, relational tables, etc.
Castor is one of the oldest data binding projects.
Process flow
Basic process flows include class generation,
marshalling, unmarshalling, etc.
Marshalling framework includes a set of ClassDescriptors and FieldDescription to describe objects.
Class generation
Class generation is similar to
JAXB and Zeus. Castor supports XML Schema instead of DTDs (DTDs are not supported by Castor).
Unmarshalling and marshalling
Unmarshalling and marshalling are dealt with marshall() and unmarshall() methods respectively. During marshalling, conversion process from Java to XML is carried out, and, during unmarshalling, conversion process from XML to Java is carried out. Mapping files are the equivalent of a binding schema, which allows to transforms names from XML to Java and vice versa.
Additional features
Castor offers some additional features which are not present in JAXB. Additional features include:
* Database and directory server mappings - mapping between databases and directory servers to Java
* JDO - Caster supports
Java Data Objects.
Code samples
Code for marshalling may look like as follows:
package javajaxb;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
// Castor
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.ValidationException;
// Generated hr.xml classes
import javajaxb.generated.hr.*;
public class EmployeeLister
Code for unmarshalling may look like as follows:
package javajaxb;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
// Castor
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.ValidationException;
// Generated hr.xml classes
import javajaxb.generated.hr.*;
public class EmployeeLister
Sample mapping file may look like as follows:
See also
*
XML data binding
XML data binding refers to a means of representing information in an XML document as a business object in computer memory. This allows applications to access the data in the XML from the object rather than using the DOM or SAX to retrieve the ...
*
List of object-relational mapping software
A ''list'' is any set of items in a row. List or lists may also refer to:
People
* List (surname)
Organizations
* List College, an undergraduate division of the Jewish Theological Seminary of America
* SC Germania List, German rugby union ...
*
Serialization
In computing, serialization (or serialisation) is the process of translating a data structure or object state into a format that can be stored (e.g. files in secondary storage devices, data buffers in primary storage devices) or transmitted (e ...
*
Service Data Object
*
Data binding
References
External links
Website*
Maven repository
{{Authority control
Object-relational mapping
Java enterprise platform
Cross-platform software
Persistence frameworks