Class ExecutionVisitor<M extends IResolvableModel<V,​M>,​O extends IResolvableOperation<V>,​V extends VariableDeclaration,​R extends Resolver<M,​O,​?,​V>>

    • Constructor Detail

      • ExecutionVisitor

        protected ExecutionVisitor​(RuntimeEnvironment<V,​M> environment,
                                   ITracer tracer,
                                   java.util.Map<java.lang.String,​java.lang.Object> parameter)
        Creates an execution visitor.
        Parameters:
        environment - the runtime environment
        tracer - the execution tracer instance (for testing)
        parameter - the parameter given from outside for the execution of the model
    • Method Detail

      • replaceParameter

        protected java.util.Map<java.lang.String,​java.lang.Object> replaceParameter​(java.util.Map<java.lang.String,​java.lang.Object> parameter)
        Exchanges the current script parameter in case of context changes. [better - assign to context]
        Parameters:
        parameter - the new parameter set
        Returns:
        the old parameter set
      • getParameter

        protected java.lang.Object getParameter​(java.lang.String name)
        Returns the specified parameter.
        Parameters:
        name - the name of the parameter
        Returns:
        the value of the parameter
      • enableArtifactAutoStoreOnParameters

        protected void enableArtifactAutoStoreOnParameters​(boolean autoStore)
        Enables/disables auto storing parameters upon variables becoming unavailable.
        Parameters:
        autoStore - do auto store or not
      • release

        public void release​(boolean releaseDefault)
        Releases the resources allocated by this execution.
        Parameters:
        releaseDefault - shall also default artifacts, i.e., artifacts that cannot be assigned to a source / target artifact model be released? May affect execution of other VIL models.
      • hasParameter

        protected boolean hasParameter​(java.lang.String name)
        Returns whether the specified parameter is defined.
        Parameters:
        name - the name of the parameter
        Returns:
        true if the parameter is defined, false else
      • getParameterCount

        protected int getParameterCount()
        Returns the number of parameters.
        Returns:
        the number of parameters
      • getTracer

        protected ITracer getTracer()
        Returns the tracer instance..
        Returns:
        the tracer instance
      • visitVariableDeclaration

        public java.lang.Object visitVariableDeclaration​(VariableDeclaration var)
                                                  throws VilException
        Description copied from interface: IVisitor
        Visits a variable declaration.
        Specified by:
        visitVariableDeclaration in interface IVisitor
        Parameters:
        var - the variable declaration
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • doAssignmentConversions

        protected java.lang.Object doAssignmentConversions​(VariableDeclaration var,
                                                           java.lang.Object value)
        Performs special conversions prior to an assignment.
        Parameters:
        var - the target variable
        value - the value to be assigned
        Returns:
        the converted value or value
      • visitAdvice

        public java.lang.Object visitAdvice​(Advice advice)
                                     throws VilException
        Description copied from interface: IVisitor
        Visits an advice.
        Specified by:
        visitAdvice in interface IVisitor
        Parameters:
        advice - the advice to be visited
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • visitExpressionStatement

        public java.lang.Object visitExpressionStatement​(ExpressionStatement statement)
                                                  throws VilException
        Description copied from interface: IVisitor
        Visits a statement.
        Specified by:
        visitExpressionStatement in interface IVisitor
        Parameters:
        statement - the statement
        Returns:
        the result of visiting the given statement (may be null)
        Throws:
        VilException - in case that visiting fails (e.g., execution)
      • checkConditionResult

        protected boolean checkConditionResult​(java.lang.Object value,
                                               java.lang.Object element,
                                               ExecutionVisitor.ConditionTest test)
        Checks the results of an evaluation of a condition.
        Parameters:
        value - the evaluation result
        element - the element to check on
        test - how to test individual artifacts
        Returns:
        true if the condition is fulfilled, false else
      • visitModelHeader

        public void visitModelHeader​(IResolvableModel<V,​M> model)
                              throws VilException
        Visits the related model headers.
        Parameters:
        model - the model to be visited
        Throws:
        VilException - in case that visiting fails (cyclic inclusion)
      • visitModelHeader

        private void visitModelHeader​(IResolvableModel<V,​M> model,
                                      java.util.Set<IResolvableModel<V,​M>> visited)
                               throws VilException
        Visits the related model headers.
        Parameters:
        model - the model to be visited
        visited - the already visited models
        Throws:
        VilException - in case that visiting fails for some reason
      • initializeImplicitVariables

        protected void initializeImplicitVariables​(IResolvableModel<V,​M> model)
                                            throws VilException
        Initializes implicit variables of a model (before explicitly defined variables).
        Parameters:
        model - the model being initialized
        Throws:
        VilException - in case that the initialization fails, e.g., assigning values
      • setModelArgument

        protected void setModelArgument​(V param,
                                        java.lang.Object value)
                                 throws VilException
        Defines the value of a given model/main argument and allows (by overriding) implicit (programmed) conversion of main arguments.
        Parameters:
        param - the model/main parameter corresponding to the argument
        value - the actual value of the argument
        Throws:
        VilException - in case that setting the value fails due to type conflicts or as a constant shall be modified
      • handleParameterInSequence

        protected void handleParameterInSequence​(IResolvableModel<V,​M> model,
                                                 java.util.Map<java.lang.String,​V> varMap)
                                          throws VilException
        Handles model parameters in sequence if appropriate. If and only if mapping is possible, this method shall modify varMap by removing assigned parameters. Otherwise, no error shall be emitted by this method. Implemented empty in this class as intended for overriding.
        Parameters:
        model - the model to be processed
        varMap - a mapping of parameter names to implementing variable declarations, to be modified as a side effect if parameters are bound
        Throws:
        VilException - in case of execution errors
      • determineScriptParam

        protected java.util.Map<java.lang.String,​java.lang.Object> determineScriptParam​(ModelCallExpression<V,​M,​O> call)
                                                                                       throws VilException
        Determines script parameters from a call, i.e., takes over arguments and fixes them.
        Parameters:
        call - the call to be executed
        Returns:
        the script parameter (may be null)
        Throws:
        VilException - in case of evaluation problems
      • visitModelCallExpression

        protected java.lang.Object visitModelCallExpression​(ModelCallExpression<V,​M,​O> call)
                                                     throws VilException
        Visits a model call expression. Currently, this method is intended to facilitate reuse and not declared in the visitor in order to avoid further template parameters etc. This method calls executeModelCall(IResolvableOperation).
        Parameters:
        call - the call to be visited
        Returns:
        the result of the execution
        Throws:
        VilException - in case that the execution fails
      • proceedModelCall

        protected java.lang.Object proceedModelCall​(O resolved,
                                                    M model,
                                                    IArgumentProvider arguments,
                                                    boolean isPlaceholder,
                                                    boolean enableParentScope)
                                             throws VilException
        Performs a model call. Currently, this method is intended to facilitate reuse, in particular for VTL. This method calls executeModelCall(IResolvableOperation).
        Parameters:
        resolved - the resolved operation
        model - the containing model
        arguments - the call arguments
        isPlaceholder - whether resolved shall be treated as a placeholder operation
        enableParentScope - enable the parent declaration scopes for dynamic dispatch, shall not be done in case of explicit super calls due to potential endless recursion
        Returns:
        the result of the execution
        Throws:
        VilException - in case that the execution fails
      • evaluateDefault

        private java.lang.Object evaluateDefault​(VariableDeclaration decl)
                                          throws VilException
        Evaluates the default value of decl.
        Parameters:
        decl - the declaration to evaluate the default value for
        Returns:
        the default value or null if none was defined
        Throws:
        VilException - if evaluating the default value (if defined) fails
      • assignModelParameter

        protected abstract void assignModelParameter​(IResolvableModel<V,​M> targetModel,
                                                     IResolvableModel<V,​M> srcModel)
                                              throws VilException
        Assigns the model parameters. Allows to use model-specific code.
        Parameters:
        targetModel - the target model to be executed
        srcModel - the source model to take the (named, optional) parameters from
        Throws:
        VilException - if accessing parameters / assigning values fails
      • evaluateModelParameter

        protected void evaluateModelParameter​(IResolvableModel<V,​M> targetModel,
                                              IResolvableModel<V,​M> srcModel,
                                              int startIndex)
                                       throws VilException
        Assigns the model parameters.
        Parameters:
        targetModel - the target model to be executed
        srcModel - the source model to take the (named, optional) parameters from
        startIndex - which parameter to start from
        Throws:
        VilException - if accessing parameters / assigning values fails
      • dynamicDispatch

        protected abstract O dynamicDispatch​(O operation,
                                             java.lang.Object[] args,
                                             IArgumentProvider argumentProvider,
                                             boolean enableParentScope)
        Performs the dynamic dispatch on the operation type.
        Parameters:
        operation - the operation to be dispatched
        args - the actual arguments
        argumentProvider - access to the argument expressions
        enableParentScope - enable the parent declaration scopes for dynamic dispatch, shall not be done in case of explicit super calls due to potential endless recursion
        Returns:
        operation or the more actual operation
      • executeModelCall

        protected abstract java.lang.Object executeModelCall​(O operation)
                                                      throws VilException
        Actually executes a model call. Basically, a subclassing visitor shall call the related visit method. Currently, this method is intended to facilitate reuse and not declared in the visitor in order to avoid further template parameters etc.
        Parameters:
        operation - the operation to be executed
        Returns:
        the execution result
        Throws:
        VilException - in case that execution fails
      • executeMain

        protected java.lang.Object executeMain​(M model,
                                               O operation)
                                        throws VilException
        Executes the main operation. Prerequisite is that (at least the leading) parameters of model are assignable to the parameters of the operation. This must be ensured by the caller. More parameters in model ("varargs" passed from the instantiator) are ignored.
        Parameters:
        model - the model to execute the operation on
        operation - the operation
        Returns:
        the result of the execution
        Throws:
        VilException - if execution fails
      • createModelCall

        protected abstract ModelCallExpression<V,​M,​O> createModelCall​(M model,
                                                                                  O operation,
                                                                                  CallArgument... arguments)
                                                                           throws VilException
        Creates a model call expression instance.
        Parameters:
        model - the model
        operation - the operation to be called on model
        arguments - the arguments
        Returns:
        the call expression instance
        Throws:
        VilException - in case of an erroneously qualified name
      • mayFail

        protected boolean mayFail​(java.lang.Object elt)
        Returns whether a rule element may fail.
        Parameters:
        elt - the element to be checked
        Returns:
        true if the element may fail (guard expression), false else
      • convertToContainer

        protected java.lang.Object convertToContainer​(Expression expr,
                                                      java.lang.Object value,
                                                      java.lang.String eltName)
                                               throws VilException
        Converts the actual value of expr to a container if required and possible.
        Parameters:
        expr - the expression
        value - the actual value of expression
        eltName - the name of the language element / concept, e.g., "loop" or "map"
        Returns:
        the converted value or value
        Throws:
        VilException - in case of conversion problems
      • getExpressionParser

        protected abstract IExpressionParser<R> getExpressionParser()
        Returns the actual expression parser.
        Returns:
        the actual expression parser