Class AbstractIvmlModifier

  • All Implemented Interfaces:
    DecisionVariableProvider
    Direct Known Subclasses:
    AasIvmlMapper

    public abstract class AbstractIvmlModifier
    extends java.lang.Object
    implements DecisionVariableProvider
    Maps an IVML configuration generically into an AAS without referencing to IIP-Ecosphere.
    Author:
    Holger Eichelberger, SSE
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected net.ssehub.easy.varModel.model.Project adaptTarget​(net.ssehub.easy.varModel.model.Project root, net.ssehub.easy.varModel.model.Project project)
      Allows to adapt a target IVML project, e.g., in testing context.
      void addGraphFormat​(GraphFormat format)
      Adds a graph format.
      protected static void addImport​(net.ssehub.easy.varModel.model.Project target, java.lang.String imp, net.ssehub.easy.varModel.model.Project root, net.ssehub.easy.varModel.model.Project res)
      Adds an import statement, if needed, temporarily resolved to be able to create expressions and constraints.
      void changeValues​(java.util.Map<java.lang.String,​java.lang.String> values)
      Changes a given set of values and performs reasoning before committing the values into the actual configuration.
      protected static AbstractIvmlModifier.CopiedFile copyToTmp​(java.io.File file)
      Copies file to temp if file exists.
      protected net.ssehub.easy.varModel.model.Constraint createAssignment​(net.ssehub.easy.varModel.model.AbstractVariable varDecl, java.lang.String valueEx, net.ssehub.easy.varModel.model.Project prj)
      Creates an assignment of valueEx to varDecl and adds it to prj.
      protected net.ssehub.easy.varModel.cst.ConstraintSyntaxTree createExpression​(java.lang.String expression, net.ssehub.easy.varModel.model.Project scope)
      Creates an IVML expression syntax tree for expression.
      protected abstract java.io.File createIvmlConfigPath​(java.lang.String subpath, net.ssehub.easy.varModel.model.Project project)
      Creates an IVML configuration (not meta-model) model path with subpath and for project p.
      void createVariable​(java.lang.String varName, java.lang.String type, java.lang.String valueEx)
      Creates an IVML variable.
      void deleteVariable​(java.lang.String varName)
      Deletes an IVML variable.
      java.lang.String getGraph​(java.lang.String varName, java.lang.String format)
      Returns a graph structure in IVML.
      GraphFactory getGraphFactory()
      Returns the factory to use to crate graphs.
      protected GraphFormat getGraphFormat​(java.lang.String format)
      Returns a graph format instance.
      protected abstract net.ssehub.easy.varModel.confModel.Configuration getIvmlConfiguration()
      Returns the actual IVML configuration.
      protected java.io.File getIvmlFile​(net.ssehub.easy.varModel.model.Project project)
      Returns the filename/path for project.
      protected abstract java.lang.String getIvmlSubpath​(net.ssehub.easy.varModel.model.Project project)
      Returns the IVML subpath for the given project.
      protected IvmlGraphMapper getMapper()
      Returns the graph mapper.
      static java.lang.String getType​(net.ssehub.easy.varModel.confModel.IDecisionVariable var)
      Returns the type of var as string.
      net.ssehub.easy.varModel.confModel.IDecisionVariable getVariable​(java.lang.String qualifiedVarName)
      Returns a decision variable for a given variable name.
      protected net.ssehub.easy.varModel.confModel.IDecisionVariable getVariable​(net.ssehub.easy.instantiation.core.model.vilTypes.configuration.Configuration cfg, java.lang.String qualifiedVarName)
      Returns an IVML variable.
      protected net.ssehub.easy.varModel.model.Project getVariableTarget​(net.ssehub.easy.varModel.model.Project root, net.ssehub.easy.varModel.model.datatypes.IDatatype type)
      Returns the target for a variable to be created.
      protected abstract net.ssehub.easy.instantiation.core.model.vilTypes.configuration.Configuration getVilConfiguration()
      Returns the actual VIL configuration.
      protected boolean isAllowedForModification​(net.ssehub.easy.varModel.model.Project prj)
      Returns whether the given project is allowed for modification (other than root).
      (package private) static boolean isValidIdentifier​(java.lang.String name)
      Limits valid identifiers.
      protected void notifyChange​(net.ssehub.easy.varModel.confModel.IDecisionVariable var, AbstractIvmlModifier.ConfigurationChangeType type)
      Notifies a potential change listener about a configuration change.
      protected void notifyChange​(net.ssehub.easy.varModel.model.Project prj, AbstractIvmlModifier.ConfigurationChangeType type)
      Notifies a potential change listener about changing a whole project the same way.
      protected void reloadAndValidate​(java.util.Map<net.ssehub.easy.varModel.model.Project,​AbstractIvmlModifier.CopiedFile> copies)
      Reloads the and validates the model, in case of problems, restore changed files from copies.
      protected abstract void reloadConfiguration()
      Reloads the configuration model.
      protected void removeConstraintsForVariable​(net.ssehub.easy.varModel.model.Project prj, net.ssehub.easy.varModel.model.AbstractVariable var)
      Removes assignment constraints for a given var.
      protected static void saveTo​(net.ssehub.easy.varModel.model.Project prj, java.io.File file)
      Saving model project prj to file.
      protected void setValue​(net.ssehub.easy.varModel.confModel.IDecisionVariable var, java.lang.String expression, net.ssehub.easy.varModel.cstEvaluation.EvaluationVisitor eval, net.ssehub.easy.varModel.confModel.AssignmentState state)
      Changes the value of the decision variable var by parsing expression and evaluating it through eval.
      protected void setValue​(net.ssehub.easy.varModel.model.AbstractVariable var, java.lang.String expression)
      Changes the value of the variable declaration var by parsing expression.
      protected void throwIfFails​(net.ssehub.easy.reasoning.core.reasoner.ReasoningResult res, boolean reloadIfFail)
      Throws an ExecutionException if the reasoning result res indicates a problem.
      protected static java.lang.String toIdentifier​(java.lang.String str)
      Helper to turn str into a Java identifier.
      protected static java.lang.String toIdentifierFirstUpper​(java.lang.String str)
      Helper to turn the first char of str into upper case and str into an identifier..
      protected abstract net.ssehub.easy.reasoning.core.reasoner.ReasoningResult validateAndPropagate()
      Validates the model and propagates values within the model.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractIvmlModifier

        public AbstractIvmlModifier​(IvmlGraphMapper graphMapper,
                                    AbstractIvmlModifier.ConfigurationChangeListener changeListener)
        Creates a mapper with default settings.
        Parameters:
        graphMapper - maps a graph from IVML to an internal structure
        changeListener - optional configuration change listener, may be null
        Throws:
        java.lang.IllegalArgumentException - if cfgSupplier is null
    • Method Detail

      • addGraphFormat

        public void addGraphFormat​(GraphFormat format)
        Adds a graph format.
        Parameters:
        format - the format
      • getGraphFactory

        public GraphFactory getGraphFactory()
        Returns the factory to use to crate graphs.
        Returns:
        the factory
      • saveTo

        protected static void saveTo​(net.ssehub.easy.varModel.model.Project prj,
                                     java.io.File file)
                              throws java.util.concurrent.ExecutionException
        Saving model project prj to file.
        Parameters:
        prj - the project
        file - the file to write to
        Throws:
        java.util.concurrent.ExecutionException - if writing fails
      • getIvmlSubpath

        protected abstract java.lang.String getIvmlSubpath​(net.ssehub.easy.varModel.model.Project project)
        Returns the IVML subpath for the given project.
        Parameters:
        project - the project
        Returns:
        the subpath, may be null for a top-level or a non-writable project, may be empty for the top-level folder or a sub-folder
      • createIvmlConfigPath

        protected abstract java.io.File createIvmlConfigPath​(java.lang.String subpath,
                                                             net.ssehub.easy.varModel.model.Project project)
        Creates an IVML configuration (not meta-model) model path with subpath and for project p.
        Parameters:
        subpath - the subpath, may be null for none
        project - the project to create the path for
        Returns:
        the file name/path
        See Also:
        getIvmlSubpath(Project)
      • isAllowedForModification

        protected boolean isAllowedForModification​(net.ssehub.easy.varModel.model.Project prj)
        Returns whether the given project is allowed for modification (other than root).
        Parameters:
        prj - the project
        Returns:
        true allowed, false else
        See Also:
        getVariableTarget(Project, IDatatype)
      • deleteVariable

        public void deleteVariable​(java.lang.String varName)
                            throws java.util.concurrent.ExecutionException
        Deletes an IVML variable. In case of a graph, this may subsequently delete further variables. IVML reference to a variable shall be cleaned up before. Left-over references shall lead to a syntax error and to no modification of the model. [public for testing]
        Parameters:
        varName - the qualified IVML variable name to delete
        Throws:
        java.util.concurrent.ExecutionException - if creating the variable fails
      • throwIfFails

        protected void throwIfFails​(net.ssehub.easy.reasoning.core.reasoner.ReasoningResult res,
                                    boolean reloadIfFail)
                             throws java.util.concurrent.ExecutionException
        Throws an ExecutionException if the reasoning result res indicates a problem.
        Parameters:
        res - the reasoning result
        reloadIfFail - reload the model if there is a failure
        Throws:
        java.util.concurrent.ExecutionException - the exception if reasoning failed
      • removeConstraintsForVariable

        protected void removeConstraintsForVariable​(net.ssehub.easy.varModel.model.Project prj,
                                                    net.ssehub.easy.varModel.model.AbstractVariable var)
        Removes assignment constraints for a given var.
        Parameters:
        prj - the project to start searching for constraints within
        var - the variable to remove constraints for
      • getVariableTarget

        protected net.ssehub.easy.varModel.model.Project getVariableTarget​(net.ssehub.easy.varModel.model.Project root,
                                                                           net.ssehub.easy.varModel.model.datatypes.IDatatype type)
        Returns the target for a variable to be created.
        Parameters:
        root - the root project (may be used as default)
        type - the actual type of the variable to be created, may be null then anyway no variable will be created
        Returns:
        the target project
        See Also:
        isAllowedForModification(Project prj)
      • adaptTarget

        protected net.ssehub.easy.varModel.model.Project adaptTarget​(net.ssehub.easy.varModel.model.Project root,
                                                                     net.ssehub.easy.varModel.model.Project project)
                                                              throws java.util.concurrent.ExecutionException
        Allows to adapt a target IVML project, e.g., in testing context.
        Parameters:
        root - the root project (for type resolution)
        project - the project to be adapted
        Returns:
        the adapted project
        Throws:
        java.util.concurrent.ExecutionException - if adapting fails
      • isValidIdentifier

        static boolean isValidIdentifier​(java.lang.String name)
        Limits valid identifiers.
        Parameters:
        name - the name
        Returns:
        true for valid identifier, false else
      • createVariable

        public void createVariable​(java.lang.String varName,
                                   java.lang.String type,
                                   java.lang.String valueEx)
                            throws java.util.concurrent.ExecutionException
        Creates an IVML variable. [public for testing]
        Parameters:
        varName - the IVML variable name
        type - the (qualified) IVML type
        valueEx - the value as IVML expression
        Throws:
        java.util.concurrent.ExecutionException - if creating the variable fails
      • changeValues

        public void changeValues​(java.util.Map<java.lang.String,​java.lang.String> values)
                          throws java.util.concurrent.ExecutionException
        Changes a given set of values and performs reasoning before committing the values into the actual configuration. For compounds/containers it is advisable to assign complete values to avoid illegal re-assignments. [public for testing]
        Parameters:
        values - the values, given as qualified IVML variables names mapped to serialized values
        Throws:
        java.util.concurrent.ExecutionException - if changing values fails
      • setValue

        protected void setValue​(net.ssehub.easy.varModel.confModel.IDecisionVariable var,
                                java.lang.String expression,
                                net.ssehub.easy.varModel.cstEvaluation.EvaluationVisitor eval,
                                net.ssehub.easy.varModel.confModel.AssignmentState state)
                         throws java.util.concurrent.ExecutionException
        Changes the value of the decision variable var by parsing expression and evaluating it through eval.
        Parameters:
        var - the variable to change, may be a top-level variable and expression may be a compound value expression
        expression - the IVML expression
        eval - the expression evaluator to reuse, may be null to create a temporary one within
        state - the assignment state to apply
        Throws:
        java.util.concurrent.ExecutionException - if parsing, evaluating or assigning fails
      • createExpression

        protected net.ssehub.easy.varModel.cst.ConstraintSyntaxTree createExpression​(java.lang.String expression,
                                                                                     net.ssehub.easy.varModel.model.Project scope)
                                                                              throws java.util.concurrent.ExecutionException
        Creates an IVML expression syntax tree for expression.
        Parameters:
        expression - the expression
        scope - the resolution scope, may be null for the root project
        Returns:
        the syntax tree
        Throws:
        java.util.concurrent.ExecutionException - if the expression cannot be created, e.g., due to syntactic or semantic errors
      • createAssignment

        protected net.ssehub.easy.varModel.model.Constraint createAssignment​(net.ssehub.easy.varModel.model.AbstractVariable varDecl,
                                                                             java.lang.String valueEx,
                                                                             net.ssehub.easy.varModel.model.Project prj)
                                                                      throws java.util.concurrent.ExecutionException
        Creates an assignment of valueEx to varDecl and adds it to prj.
        Parameters:
        varDecl - the variable declaration
        valueEx - the IVML value expression
        prj - the project to add the constraint to
        Returns:
        the created constraint
        Throws:
        java.util.concurrent.ExecutionException - if creating the constraint fails
      • setValue

        protected void setValue​(net.ssehub.easy.varModel.model.AbstractVariable var,
                                java.lang.String expression)
                         throws java.util.concurrent.ExecutionException
        Changes the value of the variable declaration var by parsing expression.
        Parameters:
        var - the variable to change, may be a top-level variable and expression may be a compound value expression
        expression - the IVML expression
        Throws:
        java.util.concurrent.ExecutionException - if parsing, evaluating or assigning fails
      • copyToTmp

        protected static AbstractIvmlModifier.CopiedFile copyToTmp​(java.io.File file)
                                                            throws java.util.concurrent.ExecutionException
        Copies file to temp if file exists.
        Parameters:
        file - the file to copy
        Returns:
        the copied file, else null
        Throws:
        java.util.concurrent.ExecutionException - if copying failed
      • reloadAndValidate

        protected void reloadAndValidate​(java.util.Map<net.ssehub.easy.varModel.model.Project,​AbstractIvmlModifier.CopiedFile> copies)
                                  throws java.util.concurrent.ExecutionException
        Reloads the and validates the model, in case of problems, restore changed files from copies.
        Parameters:
        copies - copied files to be restored
        Throws:
        java.util.concurrent.ExecutionException - if reasoning/restoring fails
      • getGraph

        public java.lang.String getGraph​(java.lang.String varName,
                                         java.lang.String format)
                                  throws java.util.concurrent.ExecutionException
        Returns a graph structure in IVML. [public for testing]
        Parameters:
        varName - the IVML variable holding the graph
        format - the format of the graph to return
        Returns:
        the graph in the specified format
        Throws:
        java.util.concurrent.ExecutionException - if reading the graph structure fails
      • getGraphFormat

        protected GraphFormat getGraphFormat​(java.lang.String format)
                                      throws java.util.concurrent.ExecutionException
        Returns a graph format instance.
        Parameters:
        format - the unique name of the graph format
        Returns:
        the graph format instance
        Throws:
        java.util.concurrent.ExecutionException - if the format instance cannot be found
      • getMapper

        protected IvmlGraphMapper getMapper()
        Returns the graph mapper.
        Returns:
        the graph mapper
      • getVariable

        public net.ssehub.easy.varModel.confModel.IDecisionVariable getVariable​(java.lang.String qualifiedVarName)
                                                                         throws java.util.concurrent.ExecutionException
        Description copied from interface: DecisionVariableProvider
        Returns a decision variable for a given variable name.
        Specified by:
        getVariable in interface DecisionVariableProvider
        Parameters:
        qualifiedVarName - the variable name
        Returns:
        the associated decision variable, may be null for node
        Throws:
        java.util.concurrent.ExecutionException - if retrieving the node fails
      • getVariable

        protected net.ssehub.easy.varModel.confModel.IDecisionVariable getVariable​(net.ssehub.easy.instantiation.core.model.vilTypes.configuration.Configuration cfg,
                                                                                   java.lang.String qualifiedVarName)
                                                                            throws java.util.concurrent.ExecutionException
        Returns an IVML variable.
        Parameters:
        cfg - the configuration to take the variable from
        qualifiedVarName - the (qualified) variable name
        Returns:
        the variable
        Throws:
        java.util.concurrent.ExecutionException - if querying the variable fails
      • addImport

        protected static void addImport​(net.ssehub.easy.varModel.model.Project target,
                                        java.lang.String imp,
                                        net.ssehub.easy.varModel.model.Project root,
                                        net.ssehub.easy.varModel.model.Project res)
                                 throws net.ssehub.easy.basics.modelManagement.ModelManagementException
        Adds an import statement, if needed, temporarily resolved to be able to create expressions and constraints.
        Parameters:
        target - the target project where to add the import to
        imp - the imported name, may be a wildcard
        root - the root project where to resolve projects from
        res - already resolved project, takes precedence over resolving imp from root; use to temporarily resolve wildcard imports with one concrete project
        Throws:
        net.ssehub.easy.basics.modelManagement.ModelManagementException - if resolving/setting the resolved project fails
      • toIdentifierFirstUpper

        protected static java.lang.String toIdentifierFirstUpper​(java.lang.String str)
        Helper to turn the first char of str into upper case and str into an identifier..
        Parameters:
        str - the string
        Returns:
        the identifier
      • toIdentifier

        protected static java.lang.String toIdentifier​(java.lang.String str)
        Helper to turn str into a Java identifier.
        Parameters:
        str - the text
        Returns:
        the identifier
      • getVilConfiguration

        protected abstract net.ssehub.easy.instantiation.core.model.vilTypes.configuration.Configuration getVilConfiguration()
        Returns the actual VIL configuration. Shall be consistent with getIvmlConfiguration().
        Returns:
        the configuration
      • getIvmlConfiguration

        protected abstract net.ssehub.easy.varModel.confModel.Configuration getIvmlConfiguration()
        Returns the actual IVML configuration. Shall be consistent with getVilConfiguration().
        Returns:
        the configuration
      • validateAndPropagate

        protected abstract net.ssehub.easy.reasoning.core.reasoner.ReasoningResult validateAndPropagate()
        Validates the model and propagates values within the model.
        Returns:
        the reasoning result
      • reloadConfiguration

        protected abstract void reloadConfiguration()
        Reloads the configuration model.
      • notifyChange

        protected void notifyChange​(net.ssehub.easy.varModel.confModel.IDecisionVariable var,
                                    AbstractIvmlModifier.ConfigurationChangeType type)
        Notifies a potential change listener about a configuration change.
        Parameters:
        var - the variable (may not be part of any configuration anymore)
        type - the change type
      • notifyChange

        protected void notifyChange​(net.ssehub.easy.varModel.model.Project prj,
                                    AbstractIvmlModifier.ConfigurationChangeType type)
        Notifies a potential change listener about changing a whole project the same way.
        Parameters:
        prj - the project
        type - the change type
      • getType

        public static java.lang.String getType​(net.ssehub.easy.varModel.confModel.IDecisionVariable var)
        Returns the type of var as string.
        Parameters:
        var - the variable
        Returns:
        the type