ITWissen.info - Tech know how online

Java emitter template (JET)

Java Emitter Templates (JET) is part of the Eclipse Modeling Framework( EMF). JET is particularly suitable for generative code generation. The central approach of JET is the use of templates. This is particularly advantageous in terms of readability, which is often not the case with more complex tools. The template technique of JET is closely based on the syntax of Java Server Pages( JSP), which in turn makes JET an easy-to-learn as well as an easy-to-use tool.

JET allows the generation of various types of output, including Java, XML, text or SQL. A disadvantage of JET is that there is no editor for the JET templates and no associated validation of the templates in Eclipse, which can lead to difficulties, especially when developing complex templates. When troubleshooting, it is therefore necessary to refer to the implementation class in order to draw possible conclusions about the template. Likewise, the complete EMF environment must be installed in order to use JET at all.

Error reduction in the source code

In many places of software development it is common today to have parts of the source code generated automatically. With JET - a subproject integrated in EMF-Framework - time-consuming writing and related errors can be reduced. With JET it is possible to generate text artifacts based on templates. The output of JET is not limited to a certain format - JET can generate any output like SQL, Java, XML, HTML, text etc.. To do this, JET uses a language to create the templates, which are very similar in the constructs used to the language constructs of Java Server Pages (JSP). The use of JET requires the prior installation of an Eclipse version of the Software Development Kit( SDK) with a compatible EMF version of the EMF SDK. Like EMF, the JET engine is only executable within Eclipse. Thus, the use of JET without Eclipse and EMF is excluded.

The process of code generation, for which the JET engine is responsible, is divided into two steps - translation and generation. The process starts on the basis of a template created by the user, which corresponds to the final output. The JET engine translates this template into a so-called implementation class. In order to obtain the desired result in a string, which can then be further processed, this class must be instantiated in the next step. The comparison with JSP makes here clear - also from the JSP template in a first step a class (the Servlet) is generated. Only when the class is called, an output for the browser is generated. The JET syntax supports three different types of expressions for this purpose:

  • Directives, define the environment parameters before translating a template for the JET engine,
  • Expressions, are used to output values of a variable or method,
  • Scriplets, are fragments of Java program code, usually containing business logic.

The central element of JET is the implementation class, which is generated by the JET engine from the template. With the call of a special method - generate() - of this class, a string is produced, which supplies the output, as this is given by the template.

Informations:
Englisch: Java emitter template - JET
Updated at: 01.11.2013
#Words: 519
Links: Java, Eclipse, enhanced metafile (WMF) (EMF), code, template
Translations: DE
Sharing:    

All rights reserved DATACOM Buchverlag GmbH © 2024