- torque-gen directory (e.g. src/main/torque-gen for maven 2) - conf - control.xml - options.properties (not always present, name can differ) - outlets - outlet_config_example.xml (name not fixed) - ... (other outlet definition files) - templates (only if template generators are used) - template_example.vm (name not fixed) - ... (other templates) - resources (only if xsd schema validation is used for sources) - schema_example.xsd (name not fixed) - ... (other xsd schemata)
<?xml version="1.0" encoding="UTF-8"?> <control loglevel="info" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://db.apache.org/torque/4.0/generator/configuration http://db.apache.org/torque/4.0/generator/configuration.xsd" xmlns="http://db.apache.org/torque/4.0/generator/configuration"> <options xsi:type="propertiesOptions" path="options.properties"/> <entityReference systemId="http://foo.org/bar.xsd" resource="bar.xsd" /> <output name="torque.om.dbObject" existingTargetStrategy="skip" outputDirKey="modifiable"> <filenameOutlet xsi:type="javaOutlet" class="org.apache.torque.generator.outlet.java.JavaFilenameOutlet"> <mergepoint name="package"> <action xsi:type="sourceElementAttributeAction" element="." attribute="dbObjectPackage" acceptNotSet="false"/> </mergepoint> <mergepoint name="classname"> <action xsi:type="sourceElementAttributeAction" element="." attribute="dbObjectClassName" acceptNotSet="false"/> </mergepoint> </filenameOutlet> <source xsi:type="fileSource" elements="database/table" skipDecider="org.apache.torque.templates.sourcefilter.OmSkipDecider"> <transformer class="org.apache.torque.templates.transformer.om.OMTransformer"/> <include>*schema.xml</include> <exclude>id-table-schema.xml</exclude> </source> <outlet name="torque.om.dbObject"/> </output> </control>
The outlets can be defined and wired together in the outlets subdirectory (recommended) or in the control.xml file (should only be used when overriding settings in existing template sets). Each file in this directory defines one or more outlets. Each outlet must have an unique name; it is recommended to use namespaces for avoiding name conflicts if more than one template set is used. Also, the type of the outlet must be given (currently supported are "velocity" and "java"). Depending on the type, further informations need to be given: The velocity outlets need the path to the template (relative to the templates subdirectory), the java outlets need the class of the outlet class. For example, this defines a java and a velocity outlet:
<?xml version="1.0" encoding="UTF-8"?> <outlets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://db.apache.org/torque/4.0/generator/configuration http://db.apache.org/torque/4.0/generator/configuration.xsd" xmlns="http://db.apache.org/torque/4.0/generator/configuration"> <outlet name="org.apache.torque.generator.javaOutlet" xsi:type="javaOutlet" class="org.apache.torque.generator.JavaGenerator"> </generator> <outlet name="torque.om.bean.baseBean" xsi:type="velocityOutlet" path="bean/base/baseBean.vm"/> </outlets>
In each outlet, mergepoints can be defined. Into each mergepoint, external content may be inserted (e.g. the value of an option or a variable or the output of another template). To keep your templates flexible, it makes sense to define mergepoints where you do not need them now but may need them in the future (you do not have to assign content to a mergepoint, it can also stay empty). The mergepoint inside the outlet is referenced by its name. For example, the following configuration defines three outlets, and the output of the last two outlet is used in mergepoints of the first outlet:
<?xml version="1.0" encoding="UTF-8"?> <outlets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://db.apache.org/torque/4.0/generator/configuration http://db.apache.org/torque/4.0/generator/configuration.xsd" xmlns="http://db.apache.org/torque/4.0/generator/configuration"> <outlet name="torque.om.bean.base.getterSetter" xsi:type="velocityOutlet" path="general/getterSetter.vm"> <mergepoint name="getter"> <action xsi:type="applyAction" outlet="torque.om.bean.base.getter"/> </mergepoint> <mergepoint name="setter"> <action xsi:type="applyAction" outlet="torque.om.bean.base.setter"/> </mergepoint> </outlet> <outlet name="torque.om.bean.base.getter" xsi:type="velocityOutlet" path="bean/base/getter.vm"> </outlet> <outlet name="torque.om.bean.base.setter" xsi:type="velocityOutlet" path="bean/base/setter.vm"> </outlet> </outlets>
A more exotic case is the definition of mergepoints outside an outlet tag. This is useful when overriding a mergepoint definition in a child project. The mergepoint can be accessed by ${outletName}.${mergepointName}. For example, if we want to override the setter mergepoint in the torque.om.bean.base.getterSetter to use a custom velocity template named setter2.vm, we could use the following configuration in the child project:
<?xml version="1.0" encoding="UTF-8"?> <outlets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://db.apache.org/torque/4.0/generator/configuration http://db.apache.org/torque/4.0/generator/configuration.xsd" xmlns="http://db.apache.org/torque/4.0/generator/configuration"> <mergepoint name="torque.om.bean.base.getterSetter.setter"> <action xsi:type="applyAction" outlet="torque.om.bean.base.setter2"/> </mergepoint> <outlet name="torque.om.bean.base.setter2" xsi:type="velocityOutlet" path="bean/base/setter2.vm"> </outlet> </outlets>
Note that by virtue of the standalone mergepoint definition, we need not override the whole definition for the outlet torque.om.bean.base.getterSetter, but can override a single mergepoint definition.