lundi 15 avril 2019

How to use Telosys code generation without entities


In some cases you may need to use templates to generate only a few files unrelated to the notion of model and entities.

This can be useful for generating configuration files or isolated files for which the variables defined in the project are sufficient.

In its current version Telosys can launch a generation only if there is a "model". But there is a simple way to use code generation without entities : just create a void model.

To do that create a "DSL model" (you can name it "void-model" for example )
Once the "void model" is created select this model as the current model (in Eclipse just open it).



Then select a bundle containing your templates and execute them...



NB: all the templates present in the bundle must respect the following rules:
  • in the "templates.cfg" file they must have a  cardinality of "1" so that each template is executed just once regardless of the number of entities
  • in the ".vm" file they must not refer to entity ( ${entity}, ${attribute}, etc )

Example of template definition in "templates.cfg" :



So you can generate files from templates that only use project variables and no entity.

vendredi 12 avril 2019

How to manipulate strings in a Telosys template


All Java objects methods can be used in a template (".vm" file),
hence it’s possible to use all the methods defined in the Java class “String”.



For all information about 'String' methods see the Java doc :
 https://docs.oracle.com/javase/7/docs/api/java/lang/String.html



Examples :


length is $STR.length()

#set($STR = $STR.replaceFirst("def", "xy" )

#if ( $STR.endsWith("ef") )
YES, it ends with "ef"
#else
NO
#end

charAt(2) : $STR.charAt(2)

#if ( $STR.equalsIgnoreCase($STR2) )
YES
#else
NO
#end


$STR.toUpperCase()
$STR.toLowerCase()