SlideShare a Scribd company logo
1 of 27
Download to read offline
JIOWA
EFFICIENCY SIMPLICITY FLEXIBILITY RELIABILITY
J© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
AutomaticValue Propagation in
Code Generator Templates
More Examples on the AutomaticValue Propagation Mechanism in the
Template Engine of the JIOWA Code Generation Framework
Dr. Robert Mencl
Freelance IT Consultant / www.mencl.de
JIOWA Business Solutions GmbH
Bettinastraße 30
D-60325 Frankfurt am Main
Germany
Version 2.1.6, May 3rd, 2017
www.jiowa.de/download.html
codegen@jiowa.de
www.jiowa.de
1
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
Automatic Value Propagation in
Code Generator Templates
1. Email Template
2. Multilingual Templates
3. Java Class Template
4. Java Class with Inline Templates
5. Summary
2
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
1. Email Template
Email Template
3
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
1. Email Template
Dear <<Salutation --> Mr: {Mr.} | Mrs: {Mrs.}>> <<Name>>,
we hereby want to inform you...
bla bla bla .
Best regards,
<<ContactPerson>>
Template file: Letter.jgt
Plain text enriched with
template notation elements
which are enclosed by
<< ... >>
4
Automatic value propagation which is explained in this presentation, is a feature of
the template engine of the JIOWA Code Generation Framework!
If you are not familiar with the framework you should check the tutorial here:
Slides and quick introduction: www.jiowa.de/products/#jiowa-codegen
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
1. Email Template (2)
Dear <<Salutation -->
Mr: {Mr.} | Mrs: {Mrs.}>> <<Name>>,
we hereby want to inform you...
bla bla bla .
Best regards,
<<ContactPerson>>
Template file: Letter.jgt
Output
Using the template bean in your program:
Dear Mr. Smith,
we hereby want to inform you...
bla bla bla .
Best regards,
Jenny Jones
Letter_jgt template = new Letter_jgt();
template.Salutation.set_Mr();
template.setName("Smith")
.setContactPerson("Jenny Jones");
System.out.println(template);
5
Automatic Build
TemplateBean Class: Letter_jgt
How can we write email templates for different languages
but insert the data only once? ➠ The solution is on the next slide!
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
2. Multilingual Templates
Multilingual
Templates
6
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
2. Multilingual Templates
Sehr <<Salutation --> Mr: {geehrter Herr} |
Mrs: {geehrte Frau}>> <<Name>>,
wir möchten Sie hiermit darauf hinweisen...
bla bla bla ...
Mit freundlichen Grüßen
<<ContactPerson>>
Template file: GermanLetter.jgt
7
<<Salutation --> Mr: {Cher Monsieur} |
Mrs: {Chère Madame}>> <<Name>>,
nous aimerions vous signaler...
bla bla bla...
Avec nous meilleurs sentiments,
<<ContactPerson>>
Template file: FrenchLetter.jgt
Automatic
Build
Automatic
Build
What if we have multiple templates with the same logical
structure but just different visual appearence?
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
2. Multilingual Templates (2)
Letter_jgt letter = new Letter_jgt();
letter.Salutation.set_Mr();
letter.setName("Bean").setContactPerson("Mary Moneypenny");
// two examples for automatic value propagation
// via 'parent constructor' initialization:
GermanLetter_jgt brief = new GermanLetter_jgt(letter);
FrenchLetter_jgt lettre = new FrenchLetter_jgt(letter);
System.out.println(letter);
System.out.println(brief);
System.out.println(lettre);
Using letter templates in different languages at the same time:
8
What if we have multiple templates with the same logical
structure but just different visual appearence?
Sehr geehrter Herr Bean,
wir möchten Sie hiermit darauf
hinweisen...
bla bla bla .
Mit freundlichen Grüßen
Mary Moneypenny
Cher Monsieur Bean,
nous aimerions vous signaler...
bla bla bla .
Avec nous meilleurs sentiments,
Mary MoneypennyThis is called automatic value propagation!
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
2. Multilingual Templates (3)
Sehr <<Salutation --> Mr: {geehrter Herr} |
Mrs: {geehrte Frau}>> <<Name>>,
wir möchten Sie hiermit darauf hinweisen...
bla bla bla ...
Mit freundlichen Grüßen
<<ContactPerson>>
Template file: GermanLetter.jgt
9
Why does this value propagation work?
<<Salutation --> Mr: {Cher Monsieur} |
Mrs: {Chère Madame}>> <<Name>>,
nous aimerions vous signaler...
bla bla bla...
Avec nous meilleurs sentiments,
<<ContactPerson>>
Template file: FrenchLetter.jgt
Same names for inline
subtemplates and variables!
↓
➠
Automatic
Build
Automatic
Build
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
2. Multilingual Templates (4)
Properties of the value propagation mechanism:
! If the value of a variable (like <<Name>> or <<ContactPerson>>)
in the child template bean is null, the value of the parent template
bean is taken.
! If the value of a variable in a template bean is never initialized, an
error is logged during code generation.
! If the list of sub template beans (like Mr, Mrs) of a sub structure
(like Salutation) is null, the list of the parent template bean is used
instead.
! Unlike variables, sub structures are optional elements.
If no sub template beans have been set or added, no text will be
created for this sub structure.
10
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
3. Java Class Template
Java Class
Template
11
© 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
3. Java Class Template
package <<PackageName>>;
public class <<ClassName>>
{
<< foreachAttribute --> Attribute.jgt />>
<< Include <-- Constructor.jgt />>
<< foreachAttribute --> Getter.jgt />>
// {{ProtectedRegionStart::ManuallyWrittenCode}}
// ...
// insert your customized code here!
// ...
// {{ProtectedRegionEnd}}
}
Template file: Class.jgt
12
Java Class Template with
Includes and Sub Templates
Includes & sub templates can be
used to significantly reduce the
visual complexity of templates!
© 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
3. Java Class Template (2)
package <<PackageName>>;
public class <<ClassName>>
{
<< foreachAttribute --> Attribute.jgt />>
<< Include <-- Constructor.jgt />>
<< foreachAttribute --> Getter.jgt />>
// {{ProtectedRegionStart::ManuallyWrittenCode}}
// ...
// insert your customized code here!
// ...
// {{ProtectedRegionEnd}}
}
/**
* Constructor with all attributes.
*/
public <<ClassName>>(<<foreachAttribute --> Argument.jgt /,>>)
{
<< foreachAttribute --> AttributeInit.jgt />>
}
Template file: Class.jgt
Template file: Constructor.jgt
13
include template
Constructor.jgt
Java Class Template with
Includes and Sub Templates
protected << <-- AttributeDeclaration.jgt >>;
Template file: Attribute.jgt
/**
* Returns the value of type <<DataType>> for attribute <<AttributeName>>.
* @return value of <<AttributeName>>
*/
public <<DataType>> get<<+AttributeName>>()
{
return this.<<AttributeName>>;
}
Template file: Getter.jgt
<<DataType>> <<AttributeName>>
Template file: AttributeDeclaration.jgt
include template
AttributeDeclaration.jgt
Includes & sub templates are useful
to keep templates simple & readable!
© 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
3. Java Class Template (3)
/**
* Constructor with all attributes.
*/
public <<ClassName>>(<<foreachAttribute --> Argument.jgt /,>>)
{
<< foreachAttribute --> AttributeInit.jgt />>
}
Template file: Constructor.jgt
14
this.<<AttributeName>> = <<AttributeName>>;
Template file: AttributeInit.jgt
<<DataType>> <<AttributeName>>
Template file: AttributeDeclaration.jgt
include template
AttributeDeclaration.jgt
Includes are quite suitable to re-use
template parts multiple times!
<< <-- AttributeDeclaration.jgt >>,
Template file: Argument.jgt
/, text operator deletes the last comma
which remains after the last argument
© 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
3. Java Class Template (4)
15
Automatic Build
Template Bean: Class_jgt
package <<PackageName>>;
public class <<ClassName>>
{
<< foreachAttribute --> Attribute.jgt />>
<< Include <-- Constructor.jgt />>
<< foreachAttribute --> Getter.jgt />>
// {{ProtectedRegionStart::ManuallyWrittenCode}}
// ...
// insert your customized code here!
// ...
// {{ProtectedRegionEnd}}
}
Template file: Class.jgt
© 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
3. Java Class Template: Code Generator
public void generate()
{
// Class:
Class_jgt t = new Class_jgt();
t.setPackageName("example");
t.setClassName("MyClass");
// Attributes:
Attribute_jgt attr1 = t.foreachAttribute.append_Attribute_jgt().setDataType("Long").setAttributeName("number");
Attribute_jgt attr2 = t.foreachAttribute.append_Attribute_jgt().setDataType("String").setAttributeName("text");
// Constructor arguments:
t.foreachAttribute.append_Argument_jgt(attr1); // 'parent constructor' for variable values
t.foreachAttribute.append_Argument_jgt(attr2); // works via automatic value propagation
// Attribute initializations:
t.foreachAttribute.append_AttributeInit_jgt(attr1); // 'parent constructor' for variable values
t.foreachAttribute.append_AttributeInit_jgt(attr2); // is similar to a copy constructor
// Getter:
t.foreachAttribute.append_Getter_jgt(attr1);
t.foreachAttribute.append_Getter_jgt(attr2);
updateSourceFile("java/" + t.getPackageName().replace('.', '/') + "/" + t.getClassName() + ".java", t.toString());
}
Code Generator:
16
We insert the attribute values only once! For all other structures (Argument.jgt,
AttributeInit.jgt & Getter.jgt) we just use the "parent constructor".
Values will be propagated automatically!
© 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
3. Java Class Template: Output
package example;
public class MyClass
{
protected Long number;
protected String text;
/**
* Constructor with all attributes.
*/
public MyClass(Long number, String text)
{
this.number = number;
this.text = text;
}
/**
* Returns the value of type Long for attribute number.
* @return value of number
*/
public Long getNumber()
{
return this.number;
}
/**
* Returns the value of type String for attribute text.
* @return value of text
*/
public String getText()
{
return this.text;
}
// {{ProtectedRegionStart::ManuallyWrittenCode}}
// ...
// insert your customized code here!
// ...
// {{ProtectedRegionEnd}}
}
Code Generator Output:
17
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
4. Java Class with Inline Templates
Java Class with
Inline Templates
18
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
4. Java Class with Inline Templates
package <<PackageName>>;
public class <<ClassName>>
{
<< foreachAttribute --> Attribute:
{
protected <<DataType>> <<AttributeName>>;
}
/>>
/**
* Constructor with all attributes.
*/
public <<ClassName>>(<<foreachAttribute --> Argument: {<<DataType>> <<AttributeName>>, } /,>>)
{
<< foreachAttribute --> AttributeInit:
{
this.<<AttributeName>> = <<AttributeName>>;
}
/>>
}
<< foreachAttribute --> Getter:
{
/**
* Returns the value of type <<DataType>> for attribute <<AttributeName>>.
* @return result value
*/
public <<DataType>> get<<+AttributeName>>()
{
return this.<<AttributeName>>;
}
}
/>>
// {{ProtectedRegionStart::ManuallyWrittenCode}}
// ...
// insert your customized code here!
// ...
// {{ProtectedRegionEnd}}
}
Template file:
JavaClass.jgt
Automatic
Build
TemplateBean Class:
JavaClass_jgt
Inline templates
are represented by
nested template
beans within the
enclosing template
bean!
19
© 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
4. Java Class with Inline Templates: Code Generator
public void generate()
{
// Java class with includes and external sub templates
Class_jgt t = new Class_jgt();
t.setPackageName("example");
t.setClassName("MyClass");
// Attributes:
Attribute_jgt attr1 = t.foreachAttribute.append_Attribute_jgt().setDataType("Long").setAttributeName("number");
Attribute_jgt attr2 = t.foreachAttribute.append_Attribute_jgt().setDataType("String").setAttributeName("text");
.
. // further data insertions as before
.
// Java class with inline sub templates:
JavaClass_jgt c = new JavaClass_jgt(t); // 'parent constructor' to get data via value propagation
c.setPackageName("example.inline"); // for complete template structure
updateSourceFile("java/" + c.getPackageName().replace('.', '/') + "/" + c.getClassName() + ".java", c );
}
Code Generator:
20
Value propagation from the previous Java class template!
© 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
4. Java Class with Inline Templates: Output
package example.inline;
public class MyClass
{
protected Long number;
protected String text;
/**
* Constructor with all attributes.
*/
public MyClass(Long number, String text)
{
this.number = number;
this.text = text;
}
/**
* Returns the value of type Long for attribute number.
* @return value of number
*/
public Long getNumber()
{
return this.number;
}
/**
* Returns the value of type String for attribute text.
* @return value of text
*/
public String getText()
{
return this.text;
}
// {{ProtectedRegionStart::ManuallyWrittenCode}}
// ...
// insert your customized code here!
// ...
// {{ProtectedRegionEnd}}
}
Code Generator Output:
21
© 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
4. Java Class with Inline Templates:
Data Insertion the other Way around
public void generate()
{
JavaClass_jgt c = new JavaClass_jgt(t);
c.setPackageName("example.inline");
c.setClassName("MyClass");
// Attributes:
Attribute a1 = c.foreachAttribute.append_Attribute().setDataType("Long").setAttributeName("number");
Attribute a2 = c.foreachAttribute.append_Attribute().setDataType("String").setAttributeName("text");
// Constructor arguments:
c.foreachAttribute.append_Argument(a1); // 'parent constructor' for variable values
c.foreachAttribute.append_Argument(a2); // works via automatic value propagation
// Attribute initializations:
c.foreachAttribute.append_AttributeInit(a1); // 'parent constructor' for variable values
c.foreachAttribute.append_AttributeInit(a2); // works via automatic value propagation
// Getter:
c.foreachAttribute.append_Getter(a1); // 'parent constructor' for variable values
c.foreachAttribute.append_Getter(a2); // works via automatic value propagation
updateSourceFile("java/" + c.getPackageName().replace('.', '/') + "/" + c.getClassName() + ".java", c );
// Java class with external sub templates:
Class_jgt t = new Class_jgt(c); // value propagation the other way around!
t.setPackageName("example"); // moving this class into another package
updateSourceFile("java/" + t.getPackageName().replace('.', '/') + "/" + t.getClassName() + ".java", t );
}
Code Generator:
22
Data insertion the other way around!
The code generator output is identical to the previous slide(s)!
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
5. AutomaticValue Propagation: Summary
Summary: value propagation for sub templates
! Value propagation for sub templates only takes place if the list in the child
template bean has not been set, i.e. if it is null.
! For each sub template bean a of the parent bean, an instance of the associated
sub template bean b of the child bean is created with a as its parent.
! Mapping between sub template beans of different types (but similar names) is
performed via their name prefix.
! An external sub template Attribute.jgt (prefix "Attribute") of the parent
bean is mapped to another external sub template, like Attribute.cgt, for
example (where .cgt might have been chosen as suffix for C++ templates).
! If there is no appropriate external sub template it will be mapped to an inline
sub template (Attribute, for example) with same prefix (if there is one).
! The reverse mapping approach is taken, if the sub template bean to be mapped
is an inline sub template bean ( ➠ first inline, then external).
23
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
APPENDIX
APPENDIX
24
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
Multilingual Templates: Three Languages at Once
Sehr <<Salutation --> Mr: {geehrter Herr} | Mrs: {geehrte Frau}>> <<Name>>,
wir möchten Sie hiermit darauf hinweisen...
bla bla bla ...
Mit freundlichen Grüßen
<<ContactPerson>>
Template file: GermanLetter.jgt
25
<<Salutation --> Mr: {Cher Monsieur} | Mrs: {Chère Madame}>> <<Name>>,
nous aimerions vous signaler...
bla bla bla...
Avec nous meilleurs sentiments,
<<ContactPerson>>
Template file: FrenchLetter.jgt
Automatic
Build
Automatic
Build
Dear <<Salutation --> Mr: {Mr.} | Mrs: {Mrs.}>> <<Name>>,
we hereby want to inform you...
bla bla bla .
Best regards,
<<ContactPerson>>
Template file: Letter.jgt
TemplateBean Class:
Letter_jgt
Automatic
Build
TemplateBean Class:
GermanLetter_jgt
TemplateBean Class:
FrenchLetter_jgt
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
Multilingual Templates: Three Languages at Once (2)
Letter_jgt letter = new Letter_jgt();
letter.Salutation.set_Mr();
letter.setName("Bean").setContactPerson("Mary Moneypenny");
// two examples for automatic value propagation
// via 'parent constructor' initialization:
GermanLetter_jgt brief = new GermanLetter_jgt(letter);
FrenchLetter_jgt lettre = new FrenchLetter_jgt(letter);
System.out.println(letter);
System.out.println(brief);
System.out.println(lettre);
26
Sehr geehrter Herr Bean,
wir möchten Sie hiermit darauf hinweisen...
bla bla bla .
Mit freundlichen Grüßen
Mary Moneypenny
Cher Monsieur Bean,
nous aimerions vous signaler...
bla bla bla .
Avec nous meilleurs sentiments,
Mary Moneypenny
This is called automatic value propagation!
It works for variable values as well as for
sub template instances!
Dear Mr. Bean,
we hereby want to inform you...
bla bla bla .
Best regards,
Mary Moneypenny
© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de
JIOWA
AutomaticValue Propagation in Code Generator Templates
Questions ?
Feedback ?
codegen@jiowa.de
Java Doc: www.jiowa.de/jiowa-codegen/doc/api/
PDF: www.jiowa.de/jiowa-codegen/doc/Jiowa-Value-Propagation-in-Code-Generator-Templates.pdf
27

More Related Content

Similar to Automatic Value Propagation in Code Generator Templates

Camunda BPM 7.2: Connectors, Data, Scripting (English)
Camunda BPM 7.2: Connectors, Data, Scripting (English)Camunda BPM 7.2: Connectors, Data, Scripting (English)
Camunda BPM 7.2: Connectors, Data, Scripting (English)camunda services GmbH
 
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Edureka!
 
AngularJS: What's the Big Deal?
AngularJS: What's the Big Deal?AngularJS: What's the Big Deal?
AngularJS: What's the Big Deal?Jim Duffy
 
WebSphere Portlet Factory: Davalen’s Practical Advice from the Field
WebSphere Portlet Factory: Davalen’s Practical Advice from the Field WebSphere Portlet Factory: Davalen’s Practical Advice from the Field
WebSphere Portlet Factory: Davalen’s Practical Advice from the Field Davalen LLC
 
Django tutorial
Django tutorialDjango tutorial
Django tutorialKsd Che
 
Architecture and Analytical Study of Magento
Architecture and Analytical Study of MagentoArchitecture and Analytical Study of Magento
Architecture and Analytical Study of MagentoIRJET Journal
 
#6 - Template Engine: Mustache.js
#6 - Template Engine: Mustache.js#6 - Template Engine: Mustache.js
#6 - Template Engine: Mustache.jsiloveigloo
 
Lessons learned from upgrading Thymeleaf
Lessons learned from upgrading ThymeleafLessons learned from upgrading Thymeleaf
Lessons learned from upgrading ThymeleafVMware Tanzu
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep DiveGabriel Walt
 
MongoDB.local Dallas 2019: MongoDB Stitch Tutorial
MongoDB.local Dallas 2019: MongoDB Stitch TutorialMongoDB.local Dallas 2019: MongoDB Stitch Tutorial
MongoDB.local Dallas 2019: MongoDB Stitch TutorialMongoDB
 
A Successful Magento Project From Design to Deployment
A Successful Magento Project From Design to DeploymentA Successful Magento Project From Design to Deployment
A Successful Magento Project From Design to DeploymentJoshua Warren
 
Struts 2 Overview
Struts 2 OverviewStruts 2 Overview
Struts 2 Overviewskill-guru
 
AEM Sightly Template Language
AEM Sightly Template LanguageAEM Sightly Template Language
AEM Sightly Template LanguageGabriel Walt
 
Does DITA need XML? Lightweight DITA and HTML5
Does DITA need XML? Lightweight DITA and HTML5Does DITA need XML? Lightweight DITA and HTML5
Does DITA need XML? Lightweight DITA and HTML5Michael Priestley
 
Build Your Own Instagram Filters
Build Your Own Instagram FiltersBuild Your Own Instagram Filters
Build Your Own Instagram FiltersTJ Stalcup
 

Similar to Automatic Value Propagation in Code Generator Templates (20)

Camunda BPM 7.2: Connectors, Data, Scripting (English)
Camunda BPM 7.2: Connectors, Data, Scripting (English)Camunda BPM 7.2: Connectors, Data, Scripting (English)
Camunda BPM 7.2: Connectors, Data, Scripting (English)
 
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...
 
AngularJS: What's the Big Deal?
AngularJS: What's the Big Deal?AngularJS: What's the Big Deal?
AngularJS: What's the Big Deal?
 
WebSphere Portlet Factory: Davalen’s Practical Advice from the Field
WebSphere Portlet Factory: Davalen’s Practical Advice from the Field WebSphere Portlet Factory: Davalen’s Practical Advice from the Field
WebSphere Portlet Factory: Davalen’s Practical Advice from the Field
 
Django tutorial
Django tutorialDjango tutorial
Django tutorial
 
Architecture and Analytical Study of Magento
Architecture and Analytical Study of MagentoArchitecture and Analytical Study of Magento
Architecture and Analytical Study of Magento
 
Sightly_techInsight
Sightly_techInsightSightly_techInsight
Sightly_techInsight
 
#6 - Template Engine: Mustache.js
#6 - Template Engine: Mustache.js#6 - Template Engine: Mustache.js
#6 - Template Engine: Mustache.js
 
Lessons learned from upgrading Thymeleaf
Lessons learned from upgrading ThymeleafLessons learned from upgrading Thymeleaf
Lessons learned from upgrading Thymeleaf
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
 
Does DITA need XML?
Does DITA need XML?Does DITA need XML?
Does DITA need XML?
 
Bootstrap 3.0
Bootstrap 3.0Bootstrap 3.0
Bootstrap 3.0
 
MongoDB.local Dallas 2019: MongoDB Stitch Tutorial
MongoDB.local Dallas 2019: MongoDB Stitch TutorialMongoDB.local Dallas 2019: MongoDB Stitch Tutorial
MongoDB.local Dallas 2019: MongoDB Stitch Tutorial
 
A Successful Magento Project From Design to Deployment
A Successful Magento Project From Design to DeploymentA Successful Magento Project From Design to Deployment
A Successful Magento Project From Design to Deployment
 
Struts 2 Overview
Struts 2 OverviewStruts 2 Overview
Struts 2 Overview
 
AEM Sightly Template Language
AEM Sightly Template LanguageAEM Sightly Template Language
AEM Sightly Template Language
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
 
FLossEd-BK Tequila Framework3.2.1
FLossEd-BK Tequila Framework3.2.1FLossEd-BK Tequila Framework3.2.1
FLossEd-BK Tequila Framework3.2.1
 
Does DITA need XML? Lightweight DITA and HTML5
Does DITA need XML? Lightweight DITA and HTML5Does DITA need XML? Lightweight DITA and HTML5
Does DITA need XML? Lightweight DITA and HTML5
 
Build Your Own Instagram Filters
Build Your Own Instagram FiltersBuild Your Own Instagram Filters
Build Your Own Instagram Filters
 

Recently uploaded

Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 

Recently uploaded (20)

Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 

Automatic Value Propagation in Code Generator Templates

  • 1. JIOWA EFFICIENCY SIMPLICITY FLEXIBILITY RELIABILITY J© 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de AutomaticValue Propagation in Code Generator Templates More Examples on the AutomaticValue Propagation Mechanism in the Template Engine of the JIOWA Code Generation Framework Dr. Robert Mencl Freelance IT Consultant / www.mencl.de JIOWA Business Solutions GmbH Bettinastraße 30 D-60325 Frankfurt am Main Germany Version 2.1.6, May 3rd, 2017 www.jiowa.de/download.html codegen@jiowa.de www.jiowa.de 1
  • 2. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA Automatic Value Propagation in Code Generator Templates 1. Email Template 2. Multilingual Templates 3. Java Class Template 4. Java Class with Inline Templates 5. Summary 2
  • 3. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 1. Email Template Email Template 3
  • 4. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 1. Email Template Dear <<Salutation --> Mr: {Mr.} | Mrs: {Mrs.}>> <<Name>>, we hereby want to inform you... bla bla bla . Best regards, <<ContactPerson>> Template file: Letter.jgt Plain text enriched with template notation elements which are enclosed by << ... >> 4 Automatic value propagation which is explained in this presentation, is a feature of the template engine of the JIOWA Code Generation Framework! If you are not familiar with the framework you should check the tutorial here: Slides and quick introduction: www.jiowa.de/products/#jiowa-codegen
  • 5. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 1. Email Template (2) Dear <<Salutation --> Mr: {Mr.} | Mrs: {Mrs.}>> <<Name>>, we hereby want to inform you... bla bla bla . Best regards, <<ContactPerson>> Template file: Letter.jgt Output Using the template bean in your program: Dear Mr. Smith, we hereby want to inform you... bla bla bla . Best regards, Jenny Jones Letter_jgt template = new Letter_jgt(); template.Salutation.set_Mr(); template.setName("Smith") .setContactPerson("Jenny Jones"); System.out.println(template); 5 Automatic Build TemplateBean Class: Letter_jgt How can we write email templates for different languages but insert the data only once? ➠ The solution is on the next slide!
  • 6. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 2. Multilingual Templates Multilingual Templates 6
  • 7. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 2. Multilingual Templates Sehr <<Salutation --> Mr: {geehrter Herr} | Mrs: {geehrte Frau}>> <<Name>>, wir möchten Sie hiermit darauf hinweisen... bla bla bla ... Mit freundlichen Grüßen <<ContactPerson>> Template file: GermanLetter.jgt 7 <<Salutation --> Mr: {Cher Monsieur} | Mrs: {Chère Madame}>> <<Name>>, nous aimerions vous signaler... bla bla bla... Avec nous meilleurs sentiments, <<ContactPerson>> Template file: FrenchLetter.jgt Automatic Build Automatic Build What if we have multiple templates with the same logical structure but just different visual appearence?
  • 8. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 2. Multilingual Templates (2) Letter_jgt letter = new Letter_jgt(); letter.Salutation.set_Mr(); letter.setName("Bean").setContactPerson("Mary Moneypenny"); // two examples for automatic value propagation // via 'parent constructor' initialization: GermanLetter_jgt brief = new GermanLetter_jgt(letter); FrenchLetter_jgt lettre = new FrenchLetter_jgt(letter); System.out.println(letter); System.out.println(brief); System.out.println(lettre); Using letter templates in different languages at the same time: 8 What if we have multiple templates with the same logical structure but just different visual appearence? Sehr geehrter Herr Bean, wir möchten Sie hiermit darauf hinweisen... bla bla bla . Mit freundlichen Grüßen Mary Moneypenny Cher Monsieur Bean, nous aimerions vous signaler... bla bla bla . Avec nous meilleurs sentiments, Mary MoneypennyThis is called automatic value propagation!
  • 9. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 2. Multilingual Templates (3) Sehr <<Salutation --> Mr: {geehrter Herr} | Mrs: {geehrte Frau}>> <<Name>>, wir möchten Sie hiermit darauf hinweisen... bla bla bla ... Mit freundlichen Grüßen <<ContactPerson>> Template file: GermanLetter.jgt 9 Why does this value propagation work? <<Salutation --> Mr: {Cher Monsieur} | Mrs: {Chère Madame}>> <<Name>>, nous aimerions vous signaler... bla bla bla... Avec nous meilleurs sentiments, <<ContactPerson>> Template file: FrenchLetter.jgt Same names for inline subtemplates and variables! ↓ ➠ Automatic Build Automatic Build
  • 10. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 2. Multilingual Templates (4) Properties of the value propagation mechanism: ! If the value of a variable (like <<Name>> or <<ContactPerson>>) in the child template bean is null, the value of the parent template bean is taken. ! If the value of a variable in a template bean is never initialized, an error is logged during code generation. ! If the list of sub template beans (like Mr, Mrs) of a sub structure (like Salutation) is null, the list of the parent template bean is used instead. ! Unlike variables, sub structures are optional elements. If no sub template beans have been set or added, no text will be created for this sub structure. 10
  • 11. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 3. Java Class Template Java Class Template 11
  • 12. © 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 3. Java Class Template package <<PackageName>>; public class <<ClassName>> { << foreachAttribute --> Attribute.jgt />> << Include <-- Constructor.jgt />> << foreachAttribute --> Getter.jgt />> // {{ProtectedRegionStart::ManuallyWrittenCode}} // ... // insert your customized code here! // ... // {{ProtectedRegionEnd}} } Template file: Class.jgt 12 Java Class Template with Includes and Sub Templates Includes & sub templates can be used to significantly reduce the visual complexity of templates!
  • 13. © 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 3. Java Class Template (2) package <<PackageName>>; public class <<ClassName>> { << foreachAttribute --> Attribute.jgt />> << Include <-- Constructor.jgt />> << foreachAttribute --> Getter.jgt />> // {{ProtectedRegionStart::ManuallyWrittenCode}} // ... // insert your customized code here! // ... // {{ProtectedRegionEnd}} } /** * Constructor with all attributes. */ public <<ClassName>>(<<foreachAttribute --> Argument.jgt /,>>) { << foreachAttribute --> AttributeInit.jgt />> } Template file: Class.jgt Template file: Constructor.jgt 13 include template Constructor.jgt Java Class Template with Includes and Sub Templates protected << <-- AttributeDeclaration.jgt >>; Template file: Attribute.jgt /** * Returns the value of type <<DataType>> for attribute <<AttributeName>>. * @return value of <<AttributeName>> */ public <<DataType>> get<<+AttributeName>>() { return this.<<AttributeName>>; } Template file: Getter.jgt <<DataType>> <<AttributeName>> Template file: AttributeDeclaration.jgt include template AttributeDeclaration.jgt Includes & sub templates are useful to keep templates simple & readable!
  • 14. © 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 3. Java Class Template (3) /** * Constructor with all attributes. */ public <<ClassName>>(<<foreachAttribute --> Argument.jgt /,>>) { << foreachAttribute --> AttributeInit.jgt />> } Template file: Constructor.jgt 14 this.<<AttributeName>> = <<AttributeName>>; Template file: AttributeInit.jgt <<DataType>> <<AttributeName>> Template file: AttributeDeclaration.jgt include template AttributeDeclaration.jgt Includes are quite suitable to re-use template parts multiple times! << <-- AttributeDeclaration.jgt >>, Template file: Argument.jgt /, text operator deletes the last comma which remains after the last argument
  • 15. © 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 3. Java Class Template (4) 15 Automatic Build Template Bean: Class_jgt package <<PackageName>>; public class <<ClassName>> { << foreachAttribute --> Attribute.jgt />> << Include <-- Constructor.jgt />> << foreachAttribute --> Getter.jgt />> // {{ProtectedRegionStart::ManuallyWrittenCode}} // ... // insert your customized code here! // ... // {{ProtectedRegionEnd}} } Template file: Class.jgt
  • 16. © 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 3. Java Class Template: Code Generator public void generate() { // Class: Class_jgt t = new Class_jgt(); t.setPackageName("example"); t.setClassName("MyClass"); // Attributes: Attribute_jgt attr1 = t.foreachAttribute.append_Attribute_jgt().setDataType("Long").setAttributeName("number"); Attribute_jgt attr2 = t.foreachAttribute.append_Attribute_jgt().setDataType("String").setAttributeName("text"); // Constructor arguments: t.foreachAttribute.append_Argument_jgt(attr1); // 'parent constructor' for variable values t.foreachAttribute.append_Argument_jgt(attr2); // works via automatic value propagation // Attribute initializations: t.foreachAttribute.append_AttributeInit_jgt(attr1); // 'parent constructor' for variable values t.foreachAttribute.append_AttributeInit_jgt(attr2); // is similar to a copy constructor // Getter: t.foreachAttribute.append_Getter_jgt(attr1); t.foreachAttribute.append_Getter_jgt(attr2); updateSourceFile("java/" + t.getPackageName().replace('.', '/') + "/" + t.getClassName() + ".java", t.toString()); } Code Generator: 16 We insert the attribute values only once! For all other structures (Argument.jgt, AttributeInit.jgt & Getter.jgt) we just use the "parent constructor". Values will be propagated automatically!
  • 17. © 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 3. Java Class Template: Output package example; public class MyClass { protected Long number; protected String text; /** * Constructor with all attributes. */ public MyClass(Long number, String text) { this.number = number; this.text = text; } /** * Returns the value of type Long for attribute number. * @return value of number */ public Long getNumber() { return this.number; } /** * Returns the value of type String for attribute text. * @return value of text */ public String getText() { return this.text; } // {{ProtectedRegionStart::ManuallyWrittenCode}} // ... // insert your customized code here! // ... // {{ProtectedRegionEnd}} } Code Generator Output: 17
  • 18. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 4. Java Class with Inline Templates Java Class with Inline Templates 18
  • 19. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 4. Java Class with Inline Templates package <<PackageName>>; public class <<ClassName>> { << foreachAttribute --> Attribute: { protected <<DataType>> <<AttributeName>>; } />> /** * Constructor with all attributes. */ public <<ClassName>>(<<foreachAttribute --> Argument: {<<DataType>> <<AttributeName>>, } /,>>) { << foreachAttribute --> AttributeInit: { this.<<AttributeName>> = <<AttributeName>>; } />> } << foreachAttribute --> Getter: { /** * Returns the value of type <<DataType>> for attribute <<AttributeName>>. * @return result value */ public <<DataType>> get<<+AttributeName>>() { return this.<<AttributeName>>; } } />> // {{ProtectedRegionStart::ManuallyWrittenCode}} // ... // insert your customized code here! // ... // {{ProtectedRegionEnd}} } Template file: JavaClass.jgt Automatic Build TemplateBean Class: JavaClass_jgt Inline templates are represented by nested template beans within the enclosing template bean! 19
  • 20. © 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 4. Java Class with Inline Templates: Code Generator public void generate() { // Java class with includes and external sub templates Class_jgt t = new Class_jgt(); t.setPackageName("example"); t.setClassName("MyClass"); // Attributes: Attribute_jgt attr1 = t.foreachAttribute.append_Attribute_jgt().setDataType("Long").setAttributeName("number"); Attribute_jgt attr2 = t.foreachAttribute.append_Attribute_jgt().setDataType("String").setAttributeName("text"); . . // further data insertions as before . // Java class with inline sub templates: JavaClass_jgt c = new JavaClass_jgt(t); // 'parent constructor' to get data via value propagation c.setPackageName("example.inline"); // for complete template structure updateSourceFile("java/" + c.getPackageName().replace('.', '/') + "/" + c.getClassName() + ".java", c ); } Code Generator: 20 Value propagation from the previous Java class template!
  • 21. © 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 4. Java Class with Inline Templates: Output package example.inline; public class MyClass { protected Long number; protected String text; /** * Constructor with all attributes. */ public MyClass(Long number, String text) { this.number = number; this.text = text; } /** * Returns the value of type Long for attribute number. * @return value of number */ public Long getNumber() { return this.number; } /** * Returns the value of type String for attribute text. * @return value of text */ public String getText() { return this.text; } // {{ProtectedRegionStart::ManuallyWrittenCode}} // ... // insert your customized code here! // ... // {{ProtectedRegionEnd}} } Code Generator Output: 21
  • 22. © 2012-2016 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 4. Java Class with Inline Templates: Data Insertion the other Way around public void generate() { JavaClass_jgt c = new JavaClass_jgt(t); c.setPackageName("example.inline"); c.setClassName("MyClass"); // Attributes: Attribute a1 = c.foreachAttribute.append_Attribute().setDataType("Long").setAttributeName("number"); Attribute a2 = c.foreachAttribute.append_Attribute().setDataType("String").setAttributeName("text"); // Constructor arguments: c.foreachAttribute.append_Argument(a1); // 'parent constructor' for variable values c.foreachAttribute.append_Argument(a2); // works via automatic value propagation // Attribute initializations: c.foreachAttribute.append_AttributeInit(a1); // 'parent constructor' for variable values c.foreachAttribute.append_AttributeInit(a2); // works via automatic value propagation // Getter: c.foreachAttribute.append_Getter(a1); // 'parent constructor' for variable values c.foreachAttribute.append_Getter(a2); // works via automatic value propagation updateSourceFile("java/" + c.getPackageName().replace('.', '/') + "/" + c.getClassName() + ".java", c ); // Java class with external sub templates: Class_jgt t = new Class_jgt(c); // value propagation the other way around! t.setPackageName("example"); // moving this class into another package updateSourceFile("java/" + t.getPackageName().replace('.', '/') + "/" + t.getClassName() + ".java", t ); } Code Generator: 22 Data insertion the other way around! The code generator output is identical to the previous slide(s)!
  • 23. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA 5. AutomaticValue Propagation: Summary Summary: value propagation for sub templates ! Value propagation for sub templates only takes place if the list in the child template bean has not been set, i.e. if it is null. ! For each sub template bean a of the parent bean, an instance of the associated sub template bean b of the child bean is created with a as its parent. ! Mapping between sub template beans of different types (but similar names) is performed via their name prefix. ! An external sub template Attribute.jgt (prefix "Attribute") of the parent bean is mapped to another external sub template, like Attribute.cgt, for example (where .cgt might have been chosen as suffix for C++ templates). ! If there is no appropriate external sub template it will be mapped to an inline sub template (Attribute, for example) with same prefix (if there is one). ! The reverse mapping approach is taken, if the sub template bean to be mapped is an inline sub template bean ( ➠ first inline, then external). 23
  • 24. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA APPENDIX APPENDIX 24
  • 25. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA Multilingual Templates: Three Languages at Once Sehr <<Salutation --> Mr: {geehrter Herr} | Mrs: {geehrte Frau}>> <<Name>>, wir möchten Sie hiermit darauf hinweisen... bla bla bla ... Mit freundlichen Grüßen <<ContactPerson>> Template file: GermanLetter.jgt 25 <<Salutation --> Mr: {Cher Monsieur} | Mrs: {Chère Madame}>> <<Name>>, nous aimerions vous signaler... bla bla bla... Avec nous meilleurs sentiments, <<ContactPerson>> Template file: FrenchLetter.jgt Automatic Build Automatic Build Dear <<Salutation --> Mr: {Mr.} | Mrs: {Mrs.}>> <<Name>>, we hereby want to inform you... bla bla bla . Best regards, <<ContactPerson>> Template file: Letter.jgt TemplateBean Class: Letter_jgt Automatic Build TemplateBean Class: GermanLetter_jgt TemplateBean Class: FrenchLetter_jgt
  • 26. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA Multilingual Templates: Three Languages at Once (2) Letter_jgt letter = new Letter_jgt(); letter.Salutation.set_Mr(); letter.setName("Bean").setContactPerson("Mary Moneypenny"); // two examples for automatic value propagation // via 'parent constructor' initialization: GermanLetter_jgt brief = new GermanLetter_jgt(letter); FrenchLetter_jgt lettre = new FrenchLetter_jgt(letter); System.out.println(letter); System.out.println(brief); System.out.println(lettre); 26 Sehr geehrter Herr Bean, wir möchten Sie hiermit darauf hinweisen... bla bla bla . Mit freundlichen Grüßen Mary Moneypenny Cher Monsieur Bean, nous aimerions vous signaler... bla bla bla . Avec nous meilleurs sentiments, Mary Moneypenny This is called automatic value propagation! It works for variable values as well as for sub template instances! Dear Mr. Bean, we hereby want to inform you... bla bla bla . Best regards, Mary Moneypenny
  • 27. © 2012 - 2017 by JIOWA Business Solutions GmbH - www.jiowa.de JIOWA AutomaticValue Propagation in Code Generator Templates Questions ? Feedback ? codegen@jiowa.de Java Doc: www.jiowa.de/jiowa-codegen/doc/api/ PDF: www.jiowa.de/jiowa-codegen/doc/Jiowa-Value-Propagation-in-Code-Generator-Templates.pdf 27