Class GlobalExtensionManagement
- java.lang.Object
-
- de.monticore.generating.templateengine.GlobalExtensionManagement
-
public class GlobalExtensionManagement extends java.lang.Object
Class for managing hook points, features and (global) variables in templates. Order of template replacement: - specific before hook points - general before hook points - specific replacement or general replacement - specific after hook points - general after hook points
-
-
Field Summary
Fields Modifier and Type Field Description protected com.google.common.collect.Multimap<java.lang.String,HookPoint>
after
protected com.google.common.collect.Multimap<java.lang.String,HookPoint>
before
protected freemarker.template.SimpleHash
globalData
protected java.util.Map<java.lang.String,HookPoint>
hookPoints
Map of all hook points for explicitely define hook points (which are internally managed to be disjoint from the template hook points) This also means explicitely define hook points cannot be decorated with "before" or "after" and they also do not contain a list, but only a single realization.protected com.google.common.collect.Multimap<java.lang.String,HookPoint>
replace
protected com.google.common.collect.Table<java.lang.String,ASTNode,java.util.List<HookPoint>>
specificAfter
protected com.google.common.collect.Table<java.lang.String,ASTNode,java.util.List<HookPoint>>
specificBefore
protected java.util.Map<java.lang.String,java.util.Map<ASTNode,HookPoint>>
specificReplacement
-
Constructor Summary
Constructors Constructor Description GlobalExtensionManagement()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAfterTemplate(java.lang.String template, ASTNode ast, HookPoint afterHp)
Everytime 'template' is included directly for node 'ast' (e.g.void
addAfterTemplate(java.lang.String template, HookPoint afterHp)
Everytime 'template' is included directly (e.g.void
addBeforeTemplate(java.lang.String template, ASTNode ast, HookPoint beforeHp)
Everytime 'template' is included directly for node 'ast' (e.g.void
addBeforeTemplate(java.lang.String template, HookPoint beforeHp)
Everytime 'template' is included directly (e.g.void
addToGlobalVar(java.lang.String name, java.lang.Object value)
Adds a new value to the given name.void
bindHookPoint(java.lang.String hookName, HookPoint hp)
void
bindStringHookPoint(java.lang.String hookName, java.lang.String content)
void
bindTemplateHookPoint(java.lang.String hookName, java.lang.String tpl)
void
bindTemplateStringHookPoint(java.lang.String hookName, java.lang.String content)
void
changeGlobalVar(java.lang.String name, java.lang.Object value)
Changes the value of an existing global variable.protected boolean
containsTemplateForwarding(java.lang.String templateName)
void
defineGlobalVar(java.lang.String name, java.lang.Object value)
Defines a new value which can be accessed with the given name in the templates.java.lang.String
defineHookPoint(TemplateController controller, java.lang.String hookName)
java.lang.String
defineHookPoint(TemplateController controller, java.lang.String hookName, ASTNode ast)
java.lang.String
defineHookPoint(TemplateController controller, java.lang.String hookName, ASTNode ast, java.lang.Object... args)
java.lang.String
defineHookPoint(TemplateController controller, java.lang.String hookName, java.lang.Object... args)
java.lang.String
defineHookPointWithDefault(TemplateController controller, java.lang.String hookName, ASTNode ast, java.lang.String defStr)
java.lang.String
defineHookPointWithDefault(TemplateController controller, java.lang.String hookName, ASTNode ast, java.lang.String defStr, java.lang.Object... args)
java.lang.String
defineHookPointWithDefault(TemplateController controller, java.lang.String hookName, java.lang.String defStr)
java.lang.String
defineHookPointWithDefault(TemplateController controller, java.lang.String hookName, java.lang.String defStr, java.lang.Object... args)
boolean
existsHookPoint(java.lang.String hookName)
protected java.util.List<HookPoint>
getAfterTemplates(java.lang.String templateName, ASTNode ast)
protected java.util.List<HookPoint>
getBeforeTemplates(java.lang.String templateName, ASTNode ast)
java.lang.Object
getGlobalVar(java.lang.String name)
Returns the value of the given variable.java.lang.Object
getGlobalVar(java.lang.String name, java.lang.Object defaultObject)
Returns the value of the given variable.protected java.util.List<HookPoint>
getSpecificReplacement(java.lang.String templateName, ASTNode ast, java.util.Map<java.lang.String,java.util.Map<ASTNode,HookPoint>> specific)
protected java.util.List<HookPoint>
getTemplateForwardings(java.lang.String templateName, ASTNode ast)
Returns a set of templates that have been defined to replace the templatetemplateName
.protected java.util.List<HookPoint>
getTemplateForwardingsX(java.lang.String templateName, ASTNode ast)
Returns a set of templates that have been defined to replace the 'templateName' template.boolean
hasGlobalVar(java.lang.String name)
Checks whether a value with the given name is defined and is not nullvoid
replaceTemplate(java.lang.String oldTemplate, ASTNode node, HookPoint newHp)
void
replaceTemplate(java.lang.String oldTemplate, HookPoint hp)
Future inclusion of 'oldTemplate' will be replaced by 'newTemplate'.void
replaceTemplate(java.lang.String oldTemplate, java.util.List<? extends HookPoint> newHps)
Future inclusion of 'oldTemplate' will be replaced by list of 'newTemplates'.void
requiredGlobalVar(java.lang.String name)
check whether the variable name (parameter) is defined: if not issue an error and continuevoid
requiredGlobalVars(java.lang.String... names)
check whether the list of variable names (parameter) is defined: if not issue an error and continuevoid
setAfterTemplate(java.lang.String template, ASTNode ast, HookPoint afterHp)
Everytime 'template' is included directly for node 'ast' (e.g.void
setAfterTemplate(java.lang.String template, ASTNode ast, java.util.List<HookPoint> afterHps)
Everytime 'template' is included directly for node 'ast' (e.g.void
setAfterTemplate(java.lang.String template, HookPoint afterHp)
Everytime 'template' is included directly (e.g.void
setAfterTemplate(java.lang.String template, java.util.List<? extends HookPoint> afterHps)
Everytime 'template' is included directly (e.g.void
setBeforeTemplate(java.lang.String template, ASTNode ast, HookPoint beforeHp)
Everytime 'template' is included directly for node 'ast' (e.g.void
setBeforeTemplate(java.lang.String template, ASTNode ast, java.util.List<HookPoint> beforeHps)
Everytime 'template' is included directly for node 'ast' (e.g.void
setBeforeTemplate(java.lang.String template, HookPoint beforeHp)
Everytime 'template' is included directly (e.g.void
setBeforeTemplate(java.lang.String template, java.util.List<? extends HookPoint> beforeHps)
Everytime 'template' is included directly (e.g.void
setGlobalData(freemarker.template.SimpleHash data)
Set a list of global data.void
setGlobalValue(java.lang.String name, java.lang.Object value)
Sets a new value which can be accessed with the given name in the templates.StringHookPoint
stringHP(java.lang.String value)
Returns a new string hook point.TemplateHookPoint
templateHP(java.lang.String template)
Returns a new template hook point.TemplateStringHookPoint
templateStringHP(java.lang.String statement)
Returns a new template string hook point.protected void
warnIfHookPointExists(java.lang.String hookName)
-
-
-
Field Detail
-
globalData
protected freemarker.template.SimpleHash globalData
-
before
protected final com.google.common.collect.Multimap<java.lang.String,HookPoint> before
-
replace
protected final com.google.common.collect.Multimap<java.lang.String,HookPoint> replace
-
after
protected final com.google.common.collect.Multimap<java.lang.String,HookPoint> after
-
specificReplacement
protected final java.util.Map<java.lang.String,java.util.Map<ASTNode,HookPoint>> specificReplacement
-
specificBefore
protected final com.google.common.collect.Table<java.lang.String,ASTNode,java.util.List<HookPoint>> specificBefore
-
specificAfter
protected final com.google.common.collect.Table<java.lang.String,ASTNode,java.util.List<HookPoint>> specificAfter
-
hookPoints
protected final java.util.Map<java.lang.String,HookPoint> hookPoints
Map of all hook points for explicitely define hook points (which are internally managed to be disjoint from the template hook points) This also means explicitely define hook points cannot be decorated with "before" or "after" and they also do not contain a list, but only a single realization. This could be harmonized with the replace hook points (by simple integration with replacements, before and after structure)
-
-
Method Detail
-
setGlobalData
public void setGlobalData(freemarker.template.SimpleHash data)
Set a list of global data. The parameter should not be null.- Parameters:
data
- list of global data
-
hasGlobalVar
public boolean hasGlobalVar(java.lang.String name)
Checks whether a value with the given name is defined and is not null- Parameters:
name
- of the value to check- Returns:
- true if a variable exists and its value is not null
-
setGlobalValue
public void setGlobalValue(java.lang.String name, java.lang.Object value)
Sets a new value which can be accessed with the given name in the templates. If the name is already in use an error is reported the previous value is overridden.- Parameters:
name
- of the value to setvalue
- the actual content
-
defineGlobalVar
public void defineGlobalVar(java.lang.String name, java.lang.Object value)
Defines a new value which can be accessed with the given name in the templates. If the name is already in use an error is reported.- Parameters:
name
- of the value to setvalue
- the actual content
-
changeGlobalVar
public void changeGlobalVar(java.lang.String name, java.lang.Object value)
Changes the value of an existing global variable. If the name is not in use an error is reported.- Parameters:
name
- of the value to setvalue
- the actual content
-
addToGlobalVar
public void addToGlobalVar(java.lang.String name, java.lang.Object value)
Adds a new value to the given name. It converts a single value into a list if necessary.- Parameters:
name
- of the value to setvalue
- the actual content
-
getGlobalVar
public java.lang.Object getGlobalVar(java.lang.String name)
Returns the value of the given variable.- Parameters:
name
- of the variable- Returns:
- the value
-
getGlobalVar
public java.lang.Object getGlobalVar(java.lang.String name, java.lang.Object defaultObject)
Returns the value of the given variable.- Parameters:
name
- of the variabledefaultObject
- replaces if the variable is not present- Returns:
- the value or the default
-
requiredGlobalVar
public void requiredGlobalVar(java.lang.String name)
check whether the variable name (parameter) is defined: if not issue an error and continue- Parameters:
name
- variable name
-
requiredGlobalVars
public void requiredGlobalVars(java.lang.String... names)
check whether the list of variable names (parameter) is defined: if not issue an error and continue- Parameters:
names
- list of variable names
-
bindStringHookPoint
public void bindStringHookPoint(java.lang.String hookName, java.lang.String content)
- Parameters:
hookName
- name of the hook pointcontent
- String to be used as hook point
-
bindTemplateStringHookPoint
public void bindTemplateStringHookPoint(java.lang.String hookName, java.lang.String content)
- Parameters:
hookName
- name of the hook pointcontent
- Template-content to be used as hook point
-
bindTemplateHookPoint
public void bindTemplateHookPoint(java.lang.String hookName, java.lang.String tpl)
- Parameters:
hookName
- name of the hook pointtpl
- Template to be used as hook point
-
bindHookPoint
public void bindHookPoint(java.lang.String hookName, HookPoint hp)
- Parameters:
hookName
- name of the hook pointhp
-
-
defineHookPoint
public java.lang.String defineHookPoint(TemplateController controller, java.lang.String hookName, ASTNode ast)
- Parameters:
hookName
- name of the hook point- Returns:
- the (processed) value of the hook point
-
defineHookPointWithDefault
public java.lang.String defineHookPointWithDefault(TemplateController controller, java.lang.String hookName, ASTNode ast, java.lang.String defStr)
- Parameters:
hookName
- name of the hook point- Returns:
- the (processed) value of the hook point
-
defineHookPoint
public java.lang.String defineHookPoint(TemplateController controller, java.lang.String hookName, ASTNode ast, java.lang.Object... args)
- Parameters:
hookName
- name of the hook point- Returns:
- the (processed) value of the hook point
-
defineHookPointWithDefault
public java.lang.String defineHookPointWithDefault(TemplateController controller, java.lang.String hookName, ASTNode ast, java.lang.String defStr, java.lang.Object... args)
- Parameters:
hookName
- name of the hook point- Returns:
- the (processed) value of the hook point
-
defineHookPoint
public java.lang.String defineHookPoint(TemplateController controller, java.lang.String hookName, java.lang.Object... args)
- Parameters:
hookName
- name of the hook point- Returns:
- the (processed) value of the hook point
-
defineHookPointWithDefault
public java.lang.String defineHookPointWithDefault(TemplateController controller, java.lang.String hookName, java.lang.String defStr, java.lang.Object... args)
- Parameters:
hookName
- name of the hook point- Returns:
- the (processed) value of the hook point
-
defineHookPoint
public java.lang.String defineHookPoint(TemplateController controller, java.lang.String hookName)
- Parameters:
hookName
- name of the hook point- Returns:
- the (processed) value of the hook point
-
defineHookPointWithDefault
public java.lang.String defineHookPointWithDefault(TemplateController controller, java.lang.String hookName, java.lang.String defStr)
- Parameters:
hookName
- name of the hook point- Returns:
- the (processed) value of the hook point
-
existsHookPoint
public boolean existsHookPoint(java.lang.String hookName)
- Parameters:
hookName
- name of the hook point- Returns:
- the (processed) value of the hook point
-
getTemplateForwardings
protected java.util.List<HookPoint> getTemplateForwardings(java.lang.String templateName, ASTNode ast)
Returns a set of templates that have been defined to replace the templatetemplateName
. If no template forwardings have been defined, thentemplateName
is returned.- Parameters:
templateName
- The name of the template- Returns:
- A list of templates that have been defined to replace the 'templateNames' templates
-
getSpecificReplacement
protected java.util.List<HookPoint> getSpecificReplacement(java.lang.String templateName, ASTNode ast, java.util.Map<java.lang.String,java.util.Map<ASTNode,HookPoint>> specific)
-
getTemplateForwardingsX
protected java.util.List<HookPoint> getTemplateForwardingsX(java.lang.String templateName, ASTNode ast)
Returns a set of templates that have been defined to replace the 'templateName' template. If no template forwardings have been defined, then the 'templateName' template is returned.- Parameters:
templateName
- The name of the template- Returns:
- A list of templats that have been defined to replace the 'templateName' template
-
containsTemplateForwarding
protected boolean containsTemplateForwarding(java.lang.String templateName)
-
replaceTemplate
public void replaceTemplate(java.lang.String oldTemplate, HookPoint hp)
Future inclusion of 'oldTemplate' will be replaced by 'newTemplate'. NOTE: This replacement has only an effect if 'oldTemplate' is included directly.- Parameters:
oldTemplate
- qualified name of template to be replacedhp
- the new hookpoint
-
replaceTemplate
public void replaceTemplate(java.lang.String oldTemplate, java.util.List<? extends HookPoint> newHps)
Future inclusion of 'oldTemplate' will be replaced by list of 'newTemplates'. NOTE: This replacement has only an effect if 'oldTemplate' is included directly.- Parameters:
oldTemplate
- qualified name of template to be replacednewHps
- List of new hookpoints
-
replaceTemplate
public void replaceTemplate(java.lang.String oldTemplate, ASTNode node, HookPoint newHp)
-
setBeforeTemplate
public void setBeforeTemplate(java.lang.String template, HookPoint beforeHp)
Everytime 'template' is included directly (e.g. byTemplateController.include(String, ASTNode)
), 'beforeTemplate' will be included before it.- Parameters:
template
- qualified name of the templatebeforeHp
- hookpoint to be included before
-
setBeforeTemplate
public void setBeforeTemplate(java.lang.String template, ASTNode ast, HookPoint beforeHp)
Everytime 'template' is included directly for node 'ast' (e.g. byTemplateController.include(String, ASTNode)
), 'beforeTemplate' will be included before it.- Parameters:
template
- qualified name of the templateast
-beforeHp
- hookpoint to be included before
-
setBeforeTemplate
public void setBeforeTemplate(java.lang.String template, java.util.List<? extends HookPoint> beforeHps)
Everytime 'template' is included directly (e.g. byTemplateController.include(String, ASTNode)
), the templates in 'beforeTemplate' will be included before it.- Parameters:
template
- qualified name of the templatebeforeHps
- List of hookpoints to be included before
-
setBeforeTemplate
public void setBeforeTemplate(java.lang.String template, ASTNode ast, java.util.List<HookPoint> beforeHps)
Everytime 'template' is included directly for node 'ast' (e.g. byTemplateController.include(String, ASTNode)
), 'beforeTemplate' will be included before it.- Parameters:
template
- qualified name of the templateast
-beforeHps
- list of hookpoints to be included before
-
setAfterTemplate
public void setAfterTemplate(java.lang.String template, HookPoint afterHp)
Everytime 'template' is included directly (e.g. byTemplateController.include(String, ASTNode)
), the 'HookPoint' 'afterHp' will be included after it. Care: This overrides any effect that previous calls of 'addAfterTemplate' and 'setAfterTemplate' on the same template have.- Parameters:
template
- qualified name of the templateafterHp
- hookpoint to be included after
-
setAfterTemplate
public void setAfterTemplate(java.lang.String template, java.util.List<? extends HookPoint> afterHps)
Everytime 'template' is included directly (e.g. byTemplateController.include(String, ASTNode)
), the 'HookPoints' in 'afterHps' will be included after it. Care: This overrides any effect that previous calls of 'addAfterTemplate' and 'setAfterTemplate' on the same template have.- Parameters:
template
- qualified name of the templateafterHps
- list of hookpoints to be included after
-
setAfterTemplate
public void setAfterTemplate(java.lang.String template, ASTNode ast, HookPoint afterHp)
Everytime 'template' is included directly for node 'ast' (e.g. byTemplateController.include(String, ASTNode)
), the 'HookPoint' 'afterHp' will be included after it. Care: This overrides any effect that previous calls of 'addAfterTemplate' and 'setAfterTemplate' on the same template have.- Parameters:
template
- qualified name of the templateast
-afterHp
- hookpoint to be included after
-
setAfterTemplate
public void setAfterTemplate(java.lang.String template, ASTNode ast, java.util.List<HookPoint> afterHps)
Everytime 'template' is included directly for node 'ast' (e.g. byTemplateController.include(String, ASTNode)
), the 'HookPoint' 'afterHp' will be included after it. Care: This overrides any effect that previous calls of 'addAfterTemplate' and 'setAfterTemplate' on the same template have.- Parameters:
template
- qualified name of the templateast
-afterHps
- list of hookpoints to be included after
-
addAfterTemplate
public void addAfterTemplate(java.lang.String template, HookPoint afterHp)
Everytime 'template' is included directly (e.g. byTemplateController.include(String, ASTNode)
), the template in 'afterHp' will be included after it. Multiple additions are possible. 'setAfterTemplate' overrides all additions.- Parameters:
template
- qualified name of the templateafterHp
- hookpoint to be included after
-
addAfterTemplate
public void addAfterTemplate(java.lang.String template, ASTNode ast, HookPoint afterHp)
Everytime 'template' is included directly for node 'ast' (e.g. byTemplateController.include(String, ASTNode)
), the template in 'afterHp' will be included after it. Multiple additions are possible. 'setAfterTemplate' overrides all additions.- Parameters:
template
- qualified name of the templateast
-afterHp
- hookpoint to be included after
-
addBeforeTemplate
public void addBeforeTemplate(java.lang.String template, HookPoint beforeHp)
Everytime 'template' is included directly (e.g. byTemplateController.include(String, ASTNode)
), the template in 'beforHp' will be included before it. The points are added in the order in which they are called up, i.e. hookpoint 1 comes first, then hookpoint 2 and so on. Multiple additions are possible. 'setBeforeTemplate' overrides all additions.- Parameters:
template
- qualified name of the templatebeforeHp
- hookpoint to be included before
-
addBeforeTemplate
public void addBeforeTemplate(java.lang.String template, ASTNode ast, HookPoint beforeHp)
Everytime 'template' is included directly for node 'ast' (e.g. byTemplateController.include(String, ASTNode)
), the template in 'beforeHp' will be included before it. The points are added in the order in which they are called up, i.e. hookpoint 1 comes first, then hookpoint 2 and so on. Multiple additions are possible. 'setBeforeTemplate' overrides all additions.- Parameters:
template
- qualified name of the templateast
-beforeHp
- hookpoint to be included before
-
warnIfHookPointExists
protected void warnIfHookPointExists(java.lang.String hookName)
-
templateHP
public TemplateHookPoint templateHP(java.lang.String template)
Returns a new template hook point. It executes a template and injects the result at the hook point.- Parameters:
template
- qualified name of the template- Returns:
- the TemplateHookPoint
- See Also:
TemplateHookPoint(String)
-
stringHP
public StringHookPoint stringHP(java.lang.String value)
Returns a new string hook point. It injects the uninterpreted string value at the hook point.- Parameters:
value
- the uninterpreted string value- Returns:
- the StringHookPoint
- See Also:
StringHookPoint(String)
-
templateStringHP
public TemplateStringHookPoint templateStringHP(java.lang.String statement) throws java.io.IOException
Returns a new template string hook point. It executes the statement as template content and injects the result at the hook point.- Parameters:
statement
- the inlined template text- Returns:
- the TemplateStringHookPoint
- Throws:
java.io.IOException
- See Also:
TemplateStringHookPoint(String)
-
getBeforeTemplates
protected java.util.List<HookPoint> getBeforeTemplates(java.lang.String templateName, ASTNode ast)
-
-