# Using other template languages inside the Torque generator

If you want to extend the Torque generator in order to use another template language, the following steps need to be done:

## Define a new outlet type in the configuration XML schema

The outlets which use the new template engine need to be distinguished from the existing outlets. This is done by defining a new outlet type for the new template language. The outlet type is a simple string, e.g. if the new template language is groovy, a good name for the outlet type would be `groovy`.

Before the new outlet type can be used in the configuration XML, the configuration XML schema must be extended in order to make the new template type definition known to the schema validator. To do this, create a new schema where the standard generator XML schema is included. In this schema, define a new type named ${type}Outlet which extends the type baseOutlet. This type should have all necessary attributes which are needed to configure the new template engine.

An example for extending the configuration XML schema can be found in the file `src/test/otherTemplateLanguages/groovyOutlet.xsd` in the torque generator project.

## Write a SAX handler for configuration

A SAX Handler needs to be written which can create and configure the outlet implementation containing the new template engine. The SAX handler gets called on each snippet containing an outlet definition of the newly defined type.

The new SAX Handler must have the package `org.apache.torque.generator.configuration.outlet` and its name must be ${Type}OutletSaxHandler, where ${Type} is the new outlet type with the first letter capitalized. For example, if the new outlet type is `groovy`, then the SAX Handler's class qualified name must be `org.apache.torque.generator.configuration.outlet.GroovyOutletSaxHandler`. You can use the class `org.apache.torque.generator.configuration.outlet.GroovyOutletSaxHandler` in the generator's test classes as a starting point for your own Sax Handler.

Conditions for the new SAX Handler are that it must not be abstract, it must inherit from `org.apache.torque.generator.configuration.outlet.OutletSaxHandler`. The new SAX Handler must have a public constructor with four arguments and the argument types `org.apache.torque.generator.qname.QualifiedName`, `org.apache.torque.generator.configuration.ConfigurationProvider`, `org.apache.torque.generator.configuration.paths.ProjectPaths`, `org.apache.torque.generator.configuration.ConfigurationHandlers` which should simply be passed to the constructor of the parent class.

It is the SAX Handler's job to create an instance of an outlet which can handle the new template language ( in the method `createOutlet` which needs to be implemented). The outlet class itself (which then can handle templates of the new type) must also be implemented. See the class `org.apache.torque.generator.template.groovy.GroovyOutlet.java` in the generator's test sources as an example.

## Referencing the extended schema

You must reference your own schema for the `http://db.apache.org/torque/4.0/generator/configuration` XML namespace wherever you use the new template type definion. As an example, see the file `src/test/otherTemplateLanguages/src/main/torque-gen/outlets/outlets.xml` in the torque generator project.

## Using the new template type

And then, of course, you need to define and use the outlets with your new template type. See the directory `src/test/otherTemplateLanguages` and its subdirectories in the torque generator project for a simple example using groovy.