JAXB Code Generation in OmegaT Development¶
In this section, we explain how JAXB-based XML schema to Java code generation is handled in OmegaT, aiming to help developers understand its setup and configuration.
Schema Files in the Repository¶
The XML schema files used for JAXB code generation are located in the repository under the src/schema directory.
Below is a list of the schema definitions included:
filters.xsd
srx20.xsd
tmx11.dtd
tmx14.xjb
xml.xsd
project_properties.xsd
tbx.xsd
tmx14.dtd
tmx14.xsd
Purpose of Each Schema Definition:¶
filters.xsd: Defines the schema forfilters.xml, found in.omegat/in the user preference folder.srx20.xsd: Defines segmentation rules forsegmentation.srxused in the.omegat/folder and project preferences.tmx*.dtd/xsd: Used for handlingtmxexports at levels 1 and 2, and forproject-save.tmxfiles (situated in theproject/omegat/folder).project_properties.xsd: Describesomegat.projectfiles, located in the project’s root folder.tbx.xsd: Defines the TBX glossary file format.Other Schemas: Support various XML structures used internally within OmegaT.
Code Generation Workflow¶
JAXB reads the XML definitions provided in the src/schema directory and generates corresponding Java classes.
These generated classes are stored under: build/generated/sources/jaxb/
The build/generated/sources/jaxb/ directory contains Java code under the package: gen.core.
These classes are dynamically generated during the build process, ensuring code stays synchronized with the XML schema descriptions.
Gradle Build Configuration for JAXB Code Generation¶
The Gradle build file is configured to include the generated JAXB sources in the build process. The key sourceSets configuration is as follows:
sourceSets {
main {
java {
srcDir 'src'
srcDir tasks.genJAXB.outputs
}
resources {
srcDir 'src'
}
}
}
What This Does:¶
srcDir 'src': Includes the main source directory.srcDir tasks.genJAXB.outputs: Includes the generated Java sources from JAXB as part of the build process.
This configuration allows Gradle and the Java compiler to recognize the generated sources, ensuring they are compiled
and included in the final OmegaT.jar artifact.
Verifying the Generated Code¶
When in doubt about the generated code, you can inspect the files found in the build directory: build/generated/sources/jaxb/
This folder contains the auto-generated classes. Generated code can be reviewed if there are concerns about mismatches with the XML definitions.
Summary¶
The JAXB-based code generation process ensures that OmegaT remains consistent with its XML schema definitions. Developers can rely on the Gradle build system to correctly integrate generated sources into the build process. If necessary, they can manually inspect the build directory to verify the output. This setup supports robust XML processing and reduces redundancy in maintaining corresponding Java classes.