Class RuntimeEnvironment<V extends VariableDeclaration,​M extends IModel>

    • Constructor Detail

      • RuntimeEnvironment

        public RuntimeEnvironment​(java.lang.Class<V> cls)
        Creates a new runtime environment using the default type registry.
        Parameters:
        cls - the variable declaration type
      • RuntimeEnvironment

        public RuntimeEnvironment​(java.lang.Class<V> cls,
                                  TypeRegistry typeRegistry)
        Creates a new runtime environment with a given type registry instance.
        Parameters:
        cls - the variable declaration type
        typeRegistry - the type registry to use
    • Method Detail

      • switchContext

        public IResolvableModel<V,​M> switchContext​(IResolvableModel<V,​M> model)
        Switches the context.
        Parameters:
        model - the model the context is assigned to
        Returns:
        the old context for switching back
      • deleteContext

        public void deleteContext​(ITypedModel model)
        Explicitly deletes a context if it is not the current context.
        Parameters:
        model - the model to delete the context for
      • setContextPaths

        public void setContextPaths​(java.util.List<java.io.File> paths)
        Defines the (sub-script) search paths of the current context.
        Parameters:
        paths - the search paths
      • getContextPaths

        public java.lang.String[] getContextPaths()
        Description copied from interface: IRuntimeEnvironment
        Returns the search paths of the current context.
        Specified by:
        getContextPaths in interface IRuntimeEnvironment
        Returns:
        the (qualified) search paths (may be null)
      • getContextModel

        public IResolvableModel<?,​M> getContextModel()
        Returns the model assigned to the context.
        Returns:
        the model (may be null if #switchContext(IModel) was not called before)
      • getMostSpecificContextModel

        public IResolvableModel<?,​M> getMostSpecificContextModel()
      • getValue

        public java.lang.Object getValue​(IResolvableModel<V,​M> contextModel,
                                         java.lang.String name)
                                  throws VilException
        Returns the value of name within contextModel.
        Parameters:
        contextModel - the model indicating the context
        name - the name of the variable
        Returns:
        the value of name
        Throws:
        VilException - in case that the context/variable is not known
      • getValue

        public java.lang.Object getValue​(V var)
                                  throws VilException
        Returns the value of var.
        Parameters:
        var - the variable to return the value for
        Returns:
        the value of var
        Throws:
        VilException - in case that var was not defined
      • storeArtifacts

        public void storeArtifacts​(boolean force)
                            throws VilException
        Description copied from interface: IRuntimeEnvironment
        Stores the artifacts in the current context.
        Specified by:
        storeArtifacts in interface IRuntimeEnvironment
        Parameters:
        force - forces storing artifacts even over (dynamic) exclusion criteria
        Throws:
        VilException - in case that storing artifacts fails
      • get

        public V get​(java.lang.String name)
        Returns the variable of name name if defined.
        Specified by:
        get in interface IRuntimeEnvironment
        Parameters:
        name - the name of the variable
        Returns:
        the variable or null if not found
      • isDefined

        public boolean isDefined​(V var)
        Returns whether var is defined (a value was assigned).
        Parameters:
        var - the variable to look for
        Returns:
        true if var is defined, false else
      • setValue

        public void setValue​(IResolvable var,
                             java.lang.Object object)
                      throws VilException
        Changes the value of var where it is defined.
        Specified by:
        setValue in interface IRuntimeEnvironment
        Parameters:
        var - the variable to be modified
        object - the value of var
        Throws:
        VilException - in case of an attempt of modifying a constant
      • setValue

        public void setValue​(V var,
                             java.lang.Object object)
                      throws VilException
        Changes the value of var where it is defined.
        Parameters:
        var - the variable to be modified
        object - the value of var
        Throws:
        VilException - in case of an attempt of modifying a constant
      • checkInitialCollectionValue

        private static java.lang.Object checkInitialCollectionValue​(TypeDescriptor<?> type,
                                                                    java.lang.Object object)
        Checks initial collection values for type compliance. Actually, the parser is not able to create the right type for all "{}", so we correct this here.
        Parameters:
        type - the type
        object - the object value
        Returns:
        object or a more specific / better matching type
      • pushLevel

        public void pushLevel()
        Pushes a new level.
      • popLevel

        public void popLevel()
                      throws VilException
        Removes the topmost level.
        Throws:
        VilException - in case that storing artifacts fails, the level will be popped anyway
      • addValue

        public void addValue​(V var,
                             java.lang.Object object)
                      throws VilException
        Changes the value of var to the top level.
        Parameters:
        var - the variable to be modified
        object - the value of var
        Throws:
        VilException - in case of an attempt of modifying a constant
      • removeValue

        public void removeValue​(V var)
        Removes the variable binding for var if it exists.
        Parameters:
        var - the variable to be removed
      • checkType

        private java.lang.Object checkType​(V var,
                                           java.lang.Object object)
                                    throws VilException
        Checks whether object can be assigned to var.
        Parameters:
        var - the variable to assign object to
        object - the object to be assigned (may be null)
        Returns:
        object or null if object is NullValue.
        Throws:
        VilException - in case of type incompatibilities
      • checkType

        public static java.lang.Object checkType​(java.lang.String name,
                                                 TypeDescriptor<?> type,
                                                 java.lang.Object object,
                                                 TypeRegistry registry,
                                                 java.util.function.Supplier<java.lang.String> modelName)
                                          throws VilException
        Checks whether object can be assigned to some form of variable/field with name name and type type.
        Parameters:
        name - the name of the variable/field to assign object to
        type - the type of the variable/field to assign object to
        object - the object to be assigned (may be null)
        registry - the type registry to use
        modelName - optional model name supplier called in error cases, may be null for none, may return null
        Returns:
        object or null if object is NullValue.
        Throws:
        VilException - in case of type incompatibilities
      • appendModelName

        private static java.lang.String appendModelName​(java.lang.String msg,
                                                        java.util.function.Supplier<java.lang.String> modelName)
        Appends the model name from modelName supplier if feasible.
        Parameters:
        msg - the message to append
        modelName - the model name supplier, may be null or return null (ignored then)
        Returns:
        the message (with appended) model name
      • evaluatePrimitives

        private static java.lang.Object evaluatePrimitives​(java.lang.Object object,
                                                           DecisionVariable decVar,
                                                           TypeDescriptor<?> varType)
        Evaluates decVar to its primitive value according to varType. Late evaluation.
        Parameters:
        object - the evaluated value so far
        decVar - the decision variable
        varType - the variable type
        Returns:
        object or the evaluated value
      • getIndentationConfiguration

        public IndentationConfiguration getIndentationConfiguration()
        Returns the indentation information for the underlying model.
        Returns:
        the indentation information
      • getIndentation

        public int getIndentation()
        Returns the current indentation.
        Returns:
        the current indentation (in single whitespaces)
      • setIndentationSteps

        public void setIndentationSteps​(int steps)
        Changes the current indentation (in steps).
        Parameters:
        steps - the number of indentation steps
      • setIndentation

        public void setIndentation​(int indentation)
        Changes the current indentation.
        Parameters:
        indentation - the new indentation (in single whitespaces)
      • increaseIndentation

        public void increaseIndentation()
        Increases the indentation by one step.
      • decreaseIndentation

        public void decreaseIndentation()
        Decreases the indentation by one step.
      • getIvmlValue

        public java.lang.Object getIvmlValue​(java.lang.String name)
                                      throws VilException
        Description copied from interface: IRuntimeEnvironment
        Returns the value of the IVML element denoted by name in the closest scope defining an IVML configuration.
        Specified by:
        getIvmlValue in interface IRuntimeEnvironment
        Parameters:
        name - the name
        Returns:
        the value
        Throws:
        VilException - in case that name was not defined
      • createEvaluationProcessor

        protected abstract IExpressionVisitor createEvaluationProcessor()
        Creates the expression visitor for this environment.
        Returns:
        the expression visitor
      • releaseEvaluationProcessor

        protected abstract void releaseEvaluationProcessor​(IExpressionVisitor processor)
        Releases the expression visitor for this environment.
        Parameters:
        processor - the expression visitor
      • getTopLevelConfiguration

        public Configuration getTopLevelConfiguration()
        Returns the top-level configuration based on defining global VIL/VTL script parameters.
        Returns:
        the top-level configuration (may be null if unknown)
      • markNoAutoStore

        public void markNoAutoStore​(IArtifact artifact)
        Marks artifacts as excluded from auto-storing when related variabeles become unavailable.
        Parameters:
        artifact - the artifact
      • unmarkNoAutoStore

        public void unmarkNoAutoStore​(IArtifact artifact)
        Marks artifacts as again included from auto-storing when related variabeles become unavailable.
        Parameters:
        artifact - the artifact