Code Templates

Home > Model Transformation > Model-to-Text (M2T) > OOMEGA Generator > Code Templates

Now, as you have created your first template, you need to code the contents. As stated earlier, the syntax of the template language is JSP, Java Server Pages. Thus you can mix static and dynamic content. But how can you obtain the model information which is necessary throughout dynamic content generation?

First of all be aware that OOMEGA offers a general purpose model-driven software engineering solution. Therefore you are able to create your own metamodels and to translate instances of them with the help of templates. Apart from that, there's a meta-metamodel available which captures the concepts described in chapter Metamodelling Concepts. In fact, that meta-metamodel is an instance of itself, hence you can inspect the meta-metamodel either with the help of our modelling tool OOMEGA Incubator or as a set of SDL files included in the OOMEGA Core distribution. As described in chapter Object Persistency API, the meta-metamodel can be accessed with the same set of generated methods as any other meta- or domain-model.

Each template is computed once for a specific model object, like a project, class, package or any other object as defined by the methods CId<EO> getExtentCId() and Predicate predicate() (cp. Create Templates). There are predefined variables available which hold references to certain model objects and can be easily accessed in your template code. The variables c, ec, ac, cs, ecs, acs are dedicated to template programming for the meta-metamodel, whereas the variable obj might be used in the context of a custom metamodel.

  • c, ec, ac
    These variables stand for class, entity class and attribute class respectively. They are used in the case of a template filename starting with "Class", "EntityClass" or "AttributeClass". You get the reference to the currently computed metamodel class.
  • cs, ecs, acs
    These variables stand for a set of entity classes and attribute classes respectively. They are used in the case of a template filename with an empty first part. The sets contain all entity/attribute classes of the currently computed metamodel.
  • obj
    This general purpose variable of type Object stands for the currently computed model object. It is especially useful if you customised the method CId<EO> getExtentCId, e.g. if you are programming templates for a custom metamodel. You might cast that object to the appropriate type at the beginning of the JSP template, e.g.
    <% Person p = (Person)obj;
    %>
    

Please have a look at that template code snippet to gain a first insight in the simplicity of OOMEGA's code generator.

package <%= c.getParentAbstractSyntax().getParentMetapackage().getName() %>;

public<%= c.getAbstractClass() ? " abstract" : "" %> class <%= c.getJName(SN) %>
{
   // The class implementation
}

Next chapter: Link Templates

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.