Class GlobalExtensionManagement

java.lang.Object
de.monticore.generating.templateengine.GlobalExtensionManagement

public class GlobalExtensionManagement extends 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 Details

    • globalData

      protected freemarker.template.SimpleHash globalData
    • before

      protected final com.google.common.collect.Multimap<String,HookPoint> before
    • replace

      protected final com.google.common.collect.Multimap<String,HookPoint> replace
    • after

      protected final com.google.common.collect.Multimap<String,HookPoint> after
    • specificReplacement

      protected final Map<String,Map<ASTNode,HookPoint>> specificReplacement
    • specificBefore

      protected final com.google.common.collect.Table<String,ASTNode,List<HookPoint>> specificBefore
    • specificAfter

      protected final com.google.common.collect.Table<String,ASTNode,List<HookPoint>> specificAfter
    • hookPoints

      protected final Map<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)
  • Constructor Details

    • GlobalExtensionManagement

      public GlobalExtensionManagement()
  • Method Details

    • 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(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(String name, 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 set
      value - the actual content
    • defineGlobalVar

      public void defineGlobalVar(String name, 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 set
      value - the actual content
    • changeGlobalVar

      public void changeGlobalVar(String name, 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 set
      value - the actual content
    • addToGlobalVar

      public void addToGlobalVar(String name, 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 set
      value - the actual content
    • getGlobalVar

      public Object getGlobalVar(String name)
      Returns the value of the given variable.
      Parameters:
      name - of the variable
      Returns:
      the value
    • getGlobalVar

      public Object getGlobalVar(String name, Object defaultObject)
      Returns the value of the given variable.
      Parameters:
      name - of the variable
      defaultObject - replaces if the variable is not present
      Returns:
      the value or the default
    • requiredGlobalVar

      public void requiredGlobalVar(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(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(String hookName, String content)
      Parameters:
      hookName - name of the hook point
      content - String to be used as hook point
    • bindTemplateStringHookPoint

      public void bindTemplateStringHookPoint(String hookName, String content)
      Parameters:
      hookName - name of the hook point
      content - Template-content to be used as hook point
    • bindTemplateHookPoint

      public void bindTemplateHookPoint(String hookName, String tpl)
      Parameters:
      hookName - name of the hook point
      tpl - Template to be used as hook point
    • bindHookPoint

      public void bindHookPoint(String hookName, HookPoint hp)
      Parameters:
      hookName - name of the hook point
      hp -
    • defineHookPoint

      public String defineHookPoint(TemplateController controller, String hookName, ASTNode ast)
      Parameters:
      hookName - name of the hook point
      Returns:
      the (processed) value of the hook point
    • defineHookPointWithDefault

      public String defineHookPointWithDefault(TemplateController controller, String hookName, ASTNode ast, String defStr)
      Parameters:
      hookName - name of the hook point
      Returns:
      the (processed) value of the hook point
    • defineHookPoint

      public String defineHookPoint(TemplateController controller, String hookName, ASTNode ast, Object... args)
      Parameters:
      hookName - name of the hook point
      Returns:
      the (processed) value of the hook point
    • defineHookPointWithDefault

      public String defineHookPointWithDefault(TemplateController controller, String hookName, ASTNode ast, String defStr, Object... args)
      Parameters:
      hookName - name of the hook point
      Returns:
      the (processed) value of the hook point
    • defineHookPoint

      public String defineHookPoint(TemplateController controller, String hookName, Object... args)
      Parameters:
      hookName - name of the hook point
      Returns:
      the (processed) value of the hook point
    • defineHookPointWithDefault

      public String defineHookPointWithDefault(TemplateController controller, String hookName, String defStr, Object... args)
      Parameters:
      hookName - name of the hook point
      Returns:
      the (processed) value of the hook point
    • defineHookPoint

      public String defineHookPoint(TemplateController controller, String hookName)
      Parameters:
      hookName - name of the hook point
      Returns:
      the (processed) value of the hook point
    • defineHookPointWithDefault

      public String defineHookPointWithDefault(TemplateController controller, String hookName, String defStr)
      Parameters:
      hookName - name of the hook point
      Returns:
      the (processed) value of the hook point
    • existsHookPoint

      public boolean existsHookPoint(String hookName)
      Parameters:
      hookName - name of the hook point
      Returns:
      the (processed) value of the hook point
    • getTemplateForwardings

      protected List<HookPoint> getTemplateForwardings(String templateName, ASTNode ast)
      Returns a set of templates that have been defined to replace the template templateName. If no template forwardings have been defined, then templateName 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 List<HookPoint> getSpecificReplacement(String templateName, ASTNode ast, Map<String,Map<ASTNode,HookPoint>> specific)
    • getTemplateForwardingsX

      protected List<HookPoint> getTemplateForwardingsX(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(String templateName)
    • replaceTemplate

      public void replaceTemplate(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 replaced
      hp - the new hookpoint
    • replaceTemplate

      public void replaceTemplate(String oldTemplate, 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 replaced
      newHps - List of new hookpoints
    • replaceTemplate

      public void replaceTemplate(String oldTemplate, ASTNode node, HookPoint newHp)
    • setBeforeTemplate

      public void setBeforeTemplate(String template, HookPoint beforeHp)
      Everytime 'template' is included directly (e.g. by TemplateController.include(String, ASTNode)), 'beforeTemplate' will be included before it.
      Parameters:
      template - qualified name of the template
      beforeHp - hookpoint to be included before
    • setBeforeTemplate

      public void setBeforeTemplate(String template, ASTNode ast, HookPoint beforeHp)
      Everytime 'template' is included directly for node 'ast' (e.g. by TemplateController.include(String, ASTNode)), 'beforeTemplate' will be included before it.
      Parameters:
      template - qualified name of the template
      ast -
      beforeHp - hookpoint to be included before
    • setBeforeTemplate

      public void setBeforeTemplate(String template, List<? extends HookPoint> beforeHps)
      Everytime 'template' is included directly (e.g. by TemplateController.include(String, ASTNode)), the templates in 'beforeTemplate' will be included before it.
      Parameters:
      template - qualified name of the template
      beforeHps - List of hookpoints to be included before
    • setBeforeTemplate

      public void setBeforeTemplate(String template, ASTNode ast, List<HookPoint> beforeHps)
      Everytime 'template' is included directly for node 'ast' (e.g. by TemplateController.include(String, ASTNode)), 'beforeTemplate' will be included before it.
      Parameters:
      template - qualified name of the template
      ast -
      beforeHps - list of hookpoints to be included before
    • setAfterTemplate

      public void setAfterTemplate(String template, HookPoint afterHp)
      Everytime 'template' is included directly (e.g. by TemplateController.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 template
      afterHp - hookpoint to be included after
    • setAfterTemplate

      public void setAfterTemplate(String template, List<? extends HookPoint> afterHps)
      Everytime 'template' is included directly (e.g. by TemplateController.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 template
      afterHps - list of hookpoints to be included after
    • setAfterTemplate

      public void setAfterTemplate(String template, ASTNode ast, HookPoint afterHp)
      Everytime 'template' is included directly for node 'ast' (e.g. by TemplateController.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 template
      ast -
      afterHp - hookpoint to be included after
    • setAfterTemplate

      public void setAfterTemplate(String template, ASTNode ast, List<HookPoint> afterHps)
      Everytime 'template' is included directly for node 'ast' (e.g. by TemplateController.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 template
      ast -
      afterHps - list of hookpoints to be included after
    • addAfterTemplate

      public void addAfterTemplate(String template, HookPoint afterHp)
      Everytime 'template' is included directly (e.g. by TemplateController.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 template
      afterHp - hookpoint to be included after
    • addAfterTemplate

      public void addAfterTemplate(String template, ASTNode ast, HookPoint afterHp)
      Everytime 'template' is included directly for node 'ast' (e.g. by TemplateController.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 template
      ast -
      afterHp - hookpoint to be included after
    • addBeforeTemplate

      public void addBeforeTemplate(String template, HookPoint beforeHp)
      Everytime 'template' is included directly (e.g. by TemplateController.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 template
      beforeHp - hookpoint to be included before
    • addBeforeTemplate

      public void addBeforeTemplate(String template, ASTNode ast, HookPoint beforeHp)
      Everytime 'template' is included directly for node 'ast' (e.g. by TemplateController.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 template
      ast -
      beforeHp - hookpoint to be included before
    • warnIfHookPointExists

      protected void warnIfHookPointExists(String hookName)
    • templateHP

      public TemplateHookPoint templateHP(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:
    • stringHP

      public StringHookPoint stringHP(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:
    • templateStringHP

      public TemplateStringHookPoint templateStringHP(String statement) throws 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:
      IOException
      See Also:
    • getBeforeTemplates

      protected List<HookPoint> getBeforeTemplates(String templateName, ASTNode ast)
    • getAfterTemplates

      protected List<HookPoint> getAfterTemplates(String templateName, ASTNode ast)