Class VilTemplateProcessor
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.defaultInstantiators.VilTemplateProcessor
-
- All Implemented Interfaces:
IVilType
public class VilTemplateProcessor extends java.lang.Object implements IVilType
Implements the default VIL template processor. This instantiator handles two types of artifacts, VTL templates and arbitrary file artifacts. In case of VTL templates it tries to obtain the related VTL script (from a registered and scanned VTL location - seeModelManagement.locations()and executes the VTL script. In case of another file, it takes the file contents and instantiates the VTL expressions in it (if there are some).- Author:
- Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringPARAM_CONFIGDenotes the default name of the configuration parameter (TemplateLangExecution.PARAM_CONFIG).static java.lang.StringPARAM_TARGETDenotes the default name of the target artifact parameter (TemplateLangExecution.PARAM_TARGET).
-
Constructor Summary
Constructors Constructor Description VilTemplateProcessor()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static ScriptgetParent(java.util.Map<java.lang.String,java.lang.Object> other)Returns the parent script passed in as implicit parameterConstants.IMPLICIT_PARENT_PARAMETER_NAME.private static java.lang.String[]getVtlPaths(java.util.Map<java.lang.String,java.lang.Object> other)Returns the VTL paths passed in as implicit parameterConstants.IMPLICIT_PATHS_PARAMETER_NAME.private static ModelImport<Template>getVtlRestrictions(java.lang.String templateName, java.util.Map<java.lang.String,java.lang.Object> other)Returns the applicable VTL restrictions.private static TemplateobtainTemplate(java.lang.String templateName, ModelImport<Template> restrictions, java.lang.String[] vtlPaths, Script caller)Obtains the template fortemplateNameandversion.private static voidprocess(FileArtifact template, Configuration config, IArtifact target, java.util.Map<java.lang.String,java.lang.Object> other, java.util.List<IArtifact> result, boolean addAdvice)Instantiatessourcetotarget.private static voidprocess(VtlFileArtifact template, Configuration config, IArtifact target, java.util.Map<java.lang.String,java.lang.Object> other, java.util.List<IArtifact> result)Instantiatessourcetotarget.private static voidprocess(Template template, Configuration config, IArtifact target, java.util.Map<java.lang.String,java.lang.Object> other, java.util.List<IArtifact> result)Instantiatessourcetotarget.private static voidpruneByPaths(java.util.List<ModelInfo<Template>> info, java.lang.String[] vtlPaths)Prunesinfoby removing all information objects that are not in one of thevtlPaths.private static voidthrowMissingTemplateError(java.lang.String templateName, java.lang.String[] possiblePaths)Creates a VIL exception with a detailed/helpful message if the desired template could not be loaded/found.private static voidunregisterTerminatable(ITerminator terminator, ITerminatable terminatable)Clears the terminator from a potential execution instance.static Set<IArtifact>vilTemplateProcessor(java.lang.String templateName, Configuration config, IArtifact target, boolean addAdvice, java.util.Map<java.lang.String,java.lang.Object> other)Instantiatessourcetotarget.static Set<IArtifact>vilTemplateProcessor(java.lang.String templateName, Configuration config, IArtifact target, java.util.Map<java.lang.String,java.lang.Object> other)Instantiatessourcetotarget.static Set<IArtifact>vilTemplateProcessor(java.lang.String templateName, Configuration config, Collection<IArtifact> targets, boolean addAdvice, java.util.Map<java.lang.String,java.lang.Object> other)Instantiatessourcetotarget.static Set<IArtifact>vilTemplateProcessor(java.lang.String templateName, Configuration config, Collection<IArtifact> targets, java.util.Map<java.lang.String,java.lang.Object> other)Instantiatessourcetotarget.static Set<IArtifact>vilTemplateProcessor(FileArtifact template, Configuration config, IArtifact target, boolean addAdvice, java.util.Map<java.lang.String,java.lang.Object> other)Instantiatessourcetotargetby textual replacement.static Set<IArtifact>vilTemplateProcessor(FileArtifact template, Configuration config, IArtifact target, java.util.Map<java.lang.String,java.lang.Object> other)Instantiatessourcetotargetby textual replacement and no implicit advice.static Set<IArtifact>vilTemplateProcessor(FileArtifact template, Configuration config, Collection<IArtifact> targets, boolean addAdvice, java.util.Map<java.lang.String,java.lang.Object> other)Instantiatessourcetotargetby textual replacement.static Set<IArtifact>vilTemplateProcessor(FileArtifact template, Configuration config, Collection<IArtifact> targets, java.util.Map<java.lang.String,java.lang.Object> other)Instantiatessourcetotargetby textual replacement and no implicit advice.static Set<IArtifact>vilTemplateProcessor(VtlFileArtifact template, Configuration config, IArtifact target, java.util.Map<java.lang.String,java.lang.Object> other)Instantiatessourcetotarget.static Set<IArtifact>vilTemplateProcessor(VtlFileArtifact template, Configuration config, Collection<IArtifact> targets, java.util.Map<java.lang.String,java.lang.Object> other)Instantiatessourcetotarget.
-
-
-
Field Detail
-
PARAM_CONFIG
public static final java.lang.String PARAM_CONFIG
Denotes the default name of the configuration parameter (TemplateLangExecution.PARAM_CONFIG).- See Also:
- Constant Field Values
-
PARAM_TARGET
public static final java.lang.String PARAM_TARGET
Denotes the default name of the target artifact parameter (TemplateLangExecution.PARAM_TARGET).- See Also:
- Constant Field Values
-
-
Method Detail
-
vilTemplateProcessor
public static Set<IArtifact> vilTemplateProcessor(FileArtifact template, Configuration config, Collection<IArtifact> targets, java.util.Map<java.lang.String,java.lang.Object> other) throws VilException
Instantiatessourcetotargetby textual replacement and no implicit advice.- Parameters:
template- the input template scriptconfig- the variability configuration to processtargets- the target artifacts (may be modified)other- named optional parameter- Returns:
- the created artifacts
- Throws:
VilException- in case that execution fails
-
vilTemplateProcessor
public static Set<IArtifact> vilTemplateProcessor(FileArtifact template, Configuration config, Collection<IArtifact> targets, boolean addAdvice, java.util.Map<java.lang.String,java.lang.Object> other) throws VilException
Instantiatessourcetotargetby textual replacement.- Parameters:
template- the input template scriptconfig- the variability configuration to processtargets- the target artifacts (may be modified)other- named optional parameteraddAdvice- add an implicit advice to resolve IVML types- Returns:
- the created artifacts
- Throws:
VilException- in case that execution fails
-
vilTemplateProcessor
public static Set<IArtifact> vilTemplateProcessor(FileArtifact template, Configuration config, IArtifact target, java.util.Map<java.lang.String,java.lang.Object> other) throws VilException
Instantiatessourcetotargetby textual replacement and no implicit advice.- Parameters:
template- the input template scriptconfig- the variability configuration to processtarget- the target artifact (may be modified)other- named optional parameter- Returns:
- the created artifacts
- Throws:
VilException- in case that execution fails
-
vilTemplateProcessor
public static Set<IArtifact> vilTemplateProcessor(FileArtifact template, Configuration config, IArtifact target, boolean addAdvice, java.util.Map<java.lang.String,java.lang.Object> other) throws VilException
Instantiatessourcetotargetby textual replacement.- Parameters:
template- the input template scriptconfig- the variability configuration to processtarget- the target artifact (may be modified)addAdvice- add an implicit advice to resolve IVML typesother- named optional parameter- Returns:
- the created artifacts
- Throws:
VilException- in case that execution fails
-
process
private static void process(FileArtifact template, Configuration config, IArtifact target, java.util.Map<java.lang.String,java.lang.Object> other, java.util.List<IArtifact> result, boolean addAdvice) throws VilException
Instantiatessourcetotarget.- Parameters:
template- the input template scriptconfig- the variability configuration to processtarget- the target artifact (may be modified)other- named optional parameterresult- the created artifacts (modified as a side effect)addAdvice- add an implicit advice to resolve IVML types- Throws:
VilException- in case that execution fails
-
vilTemplateProcessor
public static Set<IArtifact> vilTemplateProcessor(VtlFileArtifact template, Configuration config, Collection<IArtifact> targets, java.util.Map<java.lang.String,java.lang.Object> other) throws VilException
Instantiatessourcetotarget.- Parameters:
template- the input template scriptconfig- the variability configuration to processtargets- the target artifacts (may be modified)other- named optional parameter- Returns:
- the created artifacts
- Throws:
VilException- in case that execution fails
-
vilTemplateProcessor
public static Set<IArtifact> vilTemplateProcessor(VtlFileArtifact template, Configuration config, IArtifact target, java.util.Map<java.lang.String,java.lang.Object> other) throws VilException
Instantiatessourcetotarget.- Parameters:
template- the input template scriptconfig- the variability configuration to processtarget- the target artifact (may be modified)other- named optional parameter- Returns:
- the created artifacts
- Throws:
VilException- in case that execution fails
-
process
private static void process(VtlFileArtifact template, Configuration config, IArtifact target, java.util.Map<java.lang.String,java.lang.Object> other, java.util.List<IArtifact> result) throws VilException
Instantiatessourcetotarget.- Parameters:
template- the input template script (as artifact)config- the variability configuration to processtarget- the target artifact (may be modified)other- named optional parameterresult- the created artifacts (modified as a side effect)- Throws:
VilException- in case that execution fails
-
getVtlRestrictions
private static ModelImport<Template> getVtlRestrictions(java.lang.String templateName, java.util.Map<java.lang.String,java.lang.Object> other)
Returns the applicable VTL restrictions.- Parameters:
templateName- the name of the template to search forother- the other (named) parameters- Returns:
- the applicable VTL restrictions or null if there are none
-
getVtlPaths
private static java.lang.String[] getVtlPaths(java.util.Map<java.lang.String,java.lang.Object> other)
Returns the VTL paths passed in as implicit parameterConstants.IMPLICIT_PATHS_PARAMETER_NAME.- Parameters:
other- the other (named) parameters- Returns:
- the VTL paths, null if none were specified
-
getParent
private static Script getParent(java.util.Map<java.lang.String,java.lang.Object> other)
Returns the parent script passed in as implicit parameterConstants.IMPLICIT_PARENT_PARAMETER_NAME.- Parameters:
other- the other (named) parameters- Returns:
- the parent script, null if none was specified
-
vilTemplateProcessor
public static Set<IArtifact> vilTemplateProcessor(java.lang.String templateName, Configuration config, Collection<IArtifact> targets, java.util.Map<java.lang.String,java.lang.Object> other) throws VilException
Instantiatessourcetotarget. Versions restrictions may implicitly be specified asimplicit parent parameter namein terms of a Script instance.- Parameters:
templateName- the name of the templateconfig- the variability configuration to processtargets- the target artifacts (may be modified)other- named optional parameter- Returns:
- the created artifacts
- Throws:
VilException- in case that execution fails
-
vilTemplateProcessor
public static Set<IArtifact> vilTemplateProcessor(java.lang.String templateName, Configuration config, Collection<IArtifact> targets, boolean addAdvice, java.util.Map<java.lang.String,java.lang.Object> other) throws VilException
Instantiatessourcetotarget. Versions restrictions may implicitly be specified asimplicit parent parameter namein terms of a Script instance.- Parameters:
templateName- the name of the templateconfig- the variability configuration to processtargets- the target artifacts (may be modified)addAdvice- add an implicit advice to resolve IVML typesother- named optional parameter- Returns:
- the created artifacts
- Throws:
VilException- in case that execution fails
-
vilTemplateProcessor
public static Set<IArtifact> vilTemplateProcessor(java.lang.String templateName, Configuration config, IArtifact target, java.util.Map<java.lang.String,java.lang.Object> other) throws VilException
Instantiatessourcetotarget. Versions restrictions may implicitly be specified asimplicit parent parameter namein terms of a Script instance. No implicit advice is added.- Parameters:
templateName- the name of the templateconfig- the variability configuration to processtarget- the target artifact (may be modified)other- named optional parameter- Returns:
- the created artifacts
- Throws:
VilException- in case that execution fails
-
vilTemplateProcessor
public static Set<IArtifact> vilTemplateProcessor(java.lang.String templateName, Configuration config, IArtifact target, boolean addAdvice, java.util.Map<java.lang.String,java.lang.Object> other) throws VilException
Instantiatessourcetotarget. Versions restrictions may implicitly be specified asimplicit parent parameter namein terms of a Script instance. No implicit advice is added.- Parameters:
templateName- the name of the templateconfig- the variability configuration to processtarget- the target artifact (may be modified)addAdvice- add an implicit advice to resolve IVML typesother- named optional parameter- Returns:
- the created artifacts
- Throws:
VilException- in case that execution fails
-
throwMissingTemplateError
private static void throwMissingTemplateError(java.lang.String templateName, java.lang.String[] possiblePaths) throws VilExceptionCreates a VIL exception with a detailed/helpful message if the desired template could not be loaded/found.- Parameters:
templateName- the name of the templatepossiblePaths- Used VTL paths to search for the template, maybe null- Throws:
VilException- The helpful exception
-
pruneByPaths
private static void pruneByPaths(java.util.List<ModelInfo<Template>> info, java.lang.String[] vtlPaths)
Prunesinfoby removing all information objects that are not in one of thevtlPaths.- Parameters:
info- the information objects to be pruned (may be null)vtlPaths- the paths to be used for pruning (may be null)
-
obtainTemplate
private static Template obtainTemplate(java.lang.String templateName, ModelImport<Template> restrictions, java.lang.String[] vtlPaths, Script caller) throws VilException
Obtains the template fortemplateNameandversion.- Parameters:
templateName- the name of the templaterestrictions- the VTL resolution restrictions (may be null)vtlPaths- the VTL path(s) of the source project(s) (may be null)caller- the root executing script for URI-based model resolution- Returns:
- the template model
- Throws:
VilException- in case that execution fails
-
process
private static void process(Template template, Configuration config, IArtifact target, java.util.Map<java.lang.String,java.lang.Object> other, java.util.List<IArtifact> result) throws VilException
Instantiatessourcetotarget.- Parameters:
template- the input template script (as template instance)config- the variability configuration to processtarget- the target artifact (may be modified)other- named optional parameterresult- the created artifacts (modified as a side effect)- Throws:
VilException- in case that execution fails
-
unregisterTerminatable
private static void unregisterTerminatable(ITerminator terminator, ITerminatable terminatable)
Clears the terminator from a potential execution instance.- Parameters:
terminator- the terminator (may be null)terminatable- the terminatable (may be null)
-
-