Castor (framework) explained

Castor
Latest Release Version:1.4.1
Operating System:Cross-platform (JVM)
Platform:Java Virtual Machine
Programming Language:Java
Genre:Data binding
License:Apache 2.0

Castor is a data binding framework for Java with some features like Java to Java-to-XML binding, Java-to-SQL persistence, paths between Java objects, XML documents, relational tables, etc.[1] [2] [3] Castor is one of the oldest data binding projects.[3]

Process flow

Basic process flows include class generation, marshalling, unmarshalling, etc.[2] Marshalling framework includes a set of ClassDescriptors and FieldDescription to describe objects.[3]

Class generation

Class generation is similar to JAXB and Zeus. Castor supports XML Schema instead of DTDs (DTDs are not supported by Castor).[2] [3] [4]

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.[2]

Additional features

Castor offers some additional features which are not present in JAXB. Additional features include:

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;// Castorimport org.exolab.castor.xml.MarshalException;import org.exolab.castor.xml.ValidationException;// Generated hr.xml classesimport javajaxb.generated.hr.*;public class EmployeeLister [2]

Code for unmarshalling may look like as follows: package javajaxb;import java.io.File;import java.io.FileReader;import java.io.IOException;// Castorimport org.exolab.castor.xml.MarshalException;import org.exolab.castor.xml.ValidationException;// Generated hr.xml classesimport javajaxb.generated.hr.*;public class EmployeeLister [2]

Sample mapping file may look like as follows: [2]

See also

External links

Notes and References

  1. Web site: About. 11 February 2016. Castor. Github.
  2. Book: McLaughin, B. Java and XML Data Binding. O'Reilly & Associates, Inc.. 2002. Sebastopol. 143–165.
  3. Book: XML Developer's Guide. Borland Software Corporation. 2002. Scotts Valley, USA. (2–29)–(2–31).
  4. Web site: The Source Code Generator. 11 February 2016. Castor. Github.