Class 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 - see ModelManagement.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
    • Constructor Detail

      • VilTemplateProcessor

        public VilTemplateProcessor()
    • 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
        Instantiates source to target by textual replacement and no implicit advice.
        Parameters:
        template - the input template script
        config - the variability configuration to process
        targets - 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
        Instantiates source to target by textual replacement.
        Parameters:
        template - the input template script
        config - the variability configuration to process
        targets - the target artifacts (may be modified)
        other - named optional parameter
        addAdvice - 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
        Instantiates source to target by textual replacement and no implicit advice.
        Parameters:
        template - the input template script
        config - the variability configuration to process
        target - 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
        Instantiates source to target by textual replacement.
        Parameters:
        template - the input template script
        config - the variability configuration to process
        target - the target artifact (may be modified)
        addAdvice - add an implicit advice to resolve IVML types
        other - 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
        Instantiates source to target.
        Parameters:
        template - the input template script
        config - the variability configuration to process
        target - the target artifact (may be modified)
        other - named optional parameter
        result - 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
        Instantiates source to target.
        Parameters:
        template - the input template script
        config - the variability configuration to process
        targets - 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
        Instantiates source to target.
        Parameters:
        template - the input template script
        config - the variability configuration to process
        target - 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
        Instantiates source to target.
        Parameters:
        template - the input template script (as artifact)
        config - the variability configuration to process
        target - the target artifact (may be modified)
        other - named optional parameter
        result - 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 for
        other - 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 parameter Constants.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 parameter Constants.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
        Instantiates source to target. Versions restrictions may implicitly be specified as implicit parent parameter name in terms of a Script instance.
        Parameters:
        templateName - the name of the template
        config - the variability configuration to process
        targets - 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
        Instantiates source to target. Versions restrictions may implicitly be specified as implicit parent parameter name in terms of a Script instance.
        Parameters:
        templateName - the name of the template
        config - the variability configuration to process
        targets - the target artifacts (may be modified)
        addAdvice - add an implicit advice to resolve IVML types
        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,
                                                          java.util.Map<java.lang.String,​java.lang.Object> other)
                                                   throws VilException
        Instantiates source to target. Versions restrictions may implicitly be specified as implicit parent parameter name in terms of a Script instance. No implicit advice is added.
        Parameters:
        templateName - the name of the template
        config - the variability configuration to process
        target - 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
        Instantiates source to target. Versions restrictions may implicitly be specified as implicit parent parameter name in terms of a Script instance. No implicit advice is added.
        Parameters:
        templateName - the name of the template
        config - the variability configuration to process
        target - the target artifact (may be modified)
        addAdvice - add an implicit advice to resolve IVML types
        other - 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 VilException
        Creates a VIL exception with a detailed/helpful message if the desired template could not be loaded/found.
        Parameters:
        templateName - the name of the template
        possiblePaths - 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)
        Prunes info by removing all information objects that are not in one of the vtlPaths.
        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 for templateName and version.
        Parameters:
        templateName - the name of the template
        restrictions - 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
        Instantiates source to target.
        Parameters:
        template - the input template script (as template instance)
        config - the variability configuration to process
        target - the target artifact (may be modified)
        other - named optional parameter
        result - 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)