encyclopegia.org

Castor (framework)

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. Castor is one of the oldest data binding projects.

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. 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 org.wikipedia.examples; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import org.exolab.castor.xml.MarshalException; import org.exolab.castor.xml.ValidationException; import org.wikipedia.examples.generated.hr.*; public class EmployeeLister { // Existing methods public void modify() throws IOException, MarshalException, ValidationException { // Add a new employee Employee employee = new Employee(); employee.setName("Ben Rochester"); Address address = new Address(); address.setStreet1("708 Teakwood Drive"); address.setCity("Flower Mound"); address.setState("TX"); address.setZipCode("75028"); employee.addAddress(address); Organization organization = new Organization(); organization.setId(43); organization.setName("Technical Services"); employee.setOrganization(organization); Office office = new Office(); office.setId(241); Address officeAddress = new Address(); officeAddress.setStreet1("1202 Business Square"); officeAddress.setStreet2("Suite 302"); officeAddress.setCity("Dallas"); officeAddress.setState("TX"); officeAddress.setZipCode("75218-8921"); office.setAddress(officeAddress); employee.setOffice(office); // Add employee to list employees.addEmployee(employee); // marshal employees.marshal(new FileWriter(outputFile)); } public static void main(String[] args) { try { if (args.length != 2) { System.err.println("Usage: java org.wikipedia.examples.EmployeeLister[web.xml filename] [output.xml filename]"); return; } EmployeeLister lister = new EmployeeLister(new File(args[0]), new File(args[1])); lister.list(true); lister.modify(); } catch (Exception e) { e.printStackTrace(); } } } Code for unmarshalling may look like as follows: package org.wikipeda.examples; import java.io.File; import java.io.FileReader; import java.io.IOException; import org.exolab.castor.xml.MarshalException; import org.exolab.castor.xml.ValidationException; import org.wikipedia.examples.generated.hr.*; public class EmployeeLister { /** The descriptor to read in */ private File descriptor; /** The output file to write to */ 150 private File outputFile; /** The object tree read in */ private Employees employees; public EmployeeLister(File descriptor, File outputFile) { employees = null; this.descriptor = descriptor; this.outputFile = outputFile; } public void list(boolean validate) throws IOException, MarshalException, ValidationException { // Unmarshall employees = Employees.unmarshal(new FileReader(descriptor)); // Do some basic printing System.out.println("--- Employee Listing ---\n"); Employee[] employeeList = employees.getEmployee(); for (int i=0; i Sample mapping file may look like as follows: ==References== ==External links== Website Maven repository

References

No reference rows published for this article.

Cite this article

MLA

"Castor (framework)." encyclopegia.org, 2026, https://encyclopegia.org/wiki/castor-framework. Accessed 24 November 2026.

Chicago

"Castor (framework)." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/castor-framework.

APA

encyclopegia.org. (2026). Castor (framework). Retrieved November 24, 2026, from https://encyclopegia.org/wiki/castor-framework

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1335338177 · 0.5 · snapshot enwiki-001335338177

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.