Class AbstractIvmlModifier
- java.lang.Object
-
- de.iip_ecosphere.platform.configuration.ivml.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAbstractIvmlModifier.ConfigurationChangeListenerSome part listening on configuration changes.static classAbstractIvmlModifier.ConfigurationChangeTypeConfiguration change types.protected static classAbstractIvmlModifier.CopiedFileStores original and copied file.
-
Field Summary
Fields Modifier and Type Field Description private AbstractIvmlModifier.ConfigurationChangeListenerchangeListenerprivate java.util.Map<java.lang.String,GraphFormat>graphFormatsprivate IvmlGraphMappergraphMapper
-
Constructor Summary
Constructors Constructor Description AbstractIvmlModifier(IvmlGraphMapper graphMapper, AbstractIvmlModifier.ConfigurationChangeListener changeListener)Creates a mapper with default settings.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected net.ssehub.easy.varModel.model.ProjectadaptTarget(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.voidaddGraphFormat(GraphFormat format)Adds a graph format.protected static voidaddImport(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.voidchangeValues(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.CopiedFilecopyToTmp(java.io.File file)Copiesfileto temp iffileexists.protected net.ssehub.easy.varModel.model.ConstraintcreateAssignment(net.ssehub.easy.varModel.model.AbstractVariable varDecl, java.lang.String valueEx, net.ssehub.easy.varModel.model.Project prj)Creates an assignment ofvalueExtovarDecland adds it toprj.protected net.ssehub.easy.varModel.cst.ConstraintSyntaxTreecreateExpression(java.lang.String expression, net.ssehub.easy.varModel.model.Project scope)Creates an IVML expression syntax tree forexpression.protected abstract java.io.FilecreateIvmlConfigPath(java.lang.String subpath, net.ssehub.easy.varModel.model.Project project)Creates an IVML configuration (not meta-model) model path withsubpathand for projectp.voidcreateVariable(java.lang.String varName, java.lang.String type, java.lang.String valueEx)Creates an IVML variable.voiddeleteVariable(java.lang.String varName)Deletes an IVML variable.java.lang.StringgetGraph(java.lang.String varName, java.lang.String format)Returns a graph structure in IVML.GraphFactorygetGraphFactory()Returns the factory to use to crate graphs.protected GraphFormatgetGraphFormat(java.lang.String format)Returns a graph format instance.protected abstract net.ssehub.easy.varModel.confModel.ConfigurationgetIvmlConfiguration()Returns the actual IVML configuration.protected java.io.FilegetIvmlFile(net.ssehub.easy.varModel.model.Project project)Returns the filename/path forproject.protected abstract java.lang.StringgetIvmlSubpath(net.ssehub.easy.varModel.model.Project project)Returns the IVML subpath for the given project.protected IvmlGraphMappergetMapper()Returns the graph mapper.static java.lang.StringgetType(net.ssehub.easy.varModel.confModel.IDecisionVariable var)Returns the type ofvaras string.net.ssehub.easy.varModel.confModel.IDecisionVariablegetVariable(java.lang.String qualifiedVarName)Returns a decision variable for a given variable name.protected net.ssehub.easy.varModel.confModel.IDecisionVariablegetVariable(net.ssehub.easy.instantiation.core.model.vilTypes.configuration.Configuration cfg, java.lang.String qualifiedVarName)Returns an IVML variable.protected net.ssehub.easy.varModel.model.ProjectgetVariableTarget(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.ConfigurationgetVilConfiguration()Returns the actual VIL configuration.protected booleanisAllowedForModification(net.ssehub.easy.varModel.model.Project prj)Returns whether the given project is allowed for modification (other than root).(package private) static booleanisValidIdentifier(java.lang.String name)Limits valid identifiers.protected voidnotifyChange(net.ssehub.easy.varModel.confModel.IDecisionVariable var, AbstractIvmlModifier.ConfigurationChangeType type)Notifies a potential change listener about a configuration change.protected voidnotifyChange(net.ssehub.easy.varModel.model.Project prj, AbstractIvmlModifier.ConfigurationChangeType type)Notifies a potential change listener about changing a whole project the same way.protected voidreloadAndValidate(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 fromcopies.protected abstract voidreloadConfiguration()Reloads the configuration model.protected voidremoveConstraintsForVariable(net.ssehub.easy.varModel.model.Project prj, net.ssehub.easy.varModel.model.AbstractVariable var)Removes assignment constraints for a givenvar.protected static voidsaveTo(net.ssehub.easy.varModel.model.Project prj, java.io.File file)Saving model projectprjtofile.protected voidsetValue(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 variablevarby parsingexpressionand evaluating it througheval.protected voidsetValue(net.ssehub.easy.varModel.model.AbstractVariable var, java.lang.String expression)Changes the value of the variable declarationvarby parsingexpression.protected voidthrowIfFails(net.ssehub.easy.reasoning.core.reasoner.ReasoningResult res, boolean reloadIfFail)Throws anExecutionExceptionif the reasoning resultresindicates a problem.protected static java.lang.StringtoIdentifier(java.lang.String str)Helper to turnstrinto a Java identifier.protected static java.lang.StringtoIdentifierFirstUpper(java.lang.String str)Helper to turn the first char ofstrinto upper case andstrinto an identifier..protected abstract net.ssehub.easy.reasoning.core.reasoner.ReasoningResultvalidateAndPropagate()Validates the model and propagates values within the model.
-
-
-
Field Detail
-
graphMapper
private IvmlGraphMapper graphMapper
-
graphFormats
private java.util.Map<java.lang.String,GraphFormat> graphFormats
-
changeListener
private AbstractIvmlModifier.ConfigurationChangeListener changeListener
-
-
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 structurechangeListener- optional configuration change listener, may be null- Throws:
java.lang.IllegalArgumentException- ifcfgSupplieris 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.ExecutionExceptionSaving model projectprjtofile.- Parameters:
prj- the projectfile- 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 withsubpathand for projectp.- Parameters:
subpath- the subpath, may be null for noneproject- the project to create the path for- Returns:
- the file name/path
- See Also:
getIvmlSubpath(Project)
-
getIvmlFile
protected java.io.File getIvmlFile(net.ssehub.easy.varModel.model.Project project)
Returns the filename/path forproject.- Parameters:
project- the project- Returns:
- the filename/path
- See Also:
getIvmlSubpath(Project),createIvmlConfigPath(String, 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:
trueallowed,falseelse- See Also:
getVariableTarget(Project, IDatatype)
-
deleteVariable
public void deleteVariable(java.lang.String varName) throws java.util.concurrent.ExecutionExceptionDeletes 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.ExecutionExceptionThrows anExecutionExceptionif the reasoning resultresindicates a problem.- Parameters:
res- the reasoning resultreloadIfFail- 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 givenvar.- Parameters:
prj- the project to start searching for constraints withinvar- 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.ExecutionExceptionAllows 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:
truefor valid identifier,falseelse
-
createVariable
public void createVariable(java.lang.String varName, java.lang.String type, java.lang.String valueEx) throws java.util.concurrent.ExecutionExceptionCreates an IVML variable. [public for testing]- Parameters:
varName- the IVML variable nametype- the (qualified) IVML typevalueEx- 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.ExecutionExceptionChanges 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.ExecutionExceptionChanges the value of the decision variablevarby parsingexpressionand evaluating it througheval.- Parameters:
var- the variable to change, may be a top-level variable andexpressionmay be a compound value expressionexpression- the IVML expressioneval- the expression evaluator to reuse, may be null to create a temporary one withinstate- 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.ExecutionExceptionCreates an IVML expression syntax tree forexpression.- Parameters:
expression- the expressionscope- 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.ExecutionExceptionCreates an assignment ofvalueExtovarDecland adds it toprj.- Parameters:
varDecl- the variable declarationvalueEx- the IVML value expressionprj- 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.ExecutionExceptionChanges the value of the variable declarationvarby parsingexpression.- Parameters:
var- the variable to change, may be a top-level variable andexpressionmay be a compound value expressionexpression- 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
Copiesfileto temp iffileexists.- 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 fromcopies.- 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.ExecutionExceptionReturns a graph structure in IVML. [public for testing]- Parameters:
varName- the IVML variable holding the graphformat- 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.ExecutionExceptionDescription copied from interface:DecisionVariableProviderReturns a decision variable for a given variable name.- Specified by:
getVariablein interfaceDecisionVariableProvider- 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.ExecutionExceptionReturns an IVML variable.- Parameters:
cfg- the configuration to take the variable fromqualifiedVarName- 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.ModelManagementExceptionAdds 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 toimp- the imported name, may be a wildcardroot- the root project where to resolve projects fromres- already resolved project, takes precedence over resolvingimpfromroot; 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 ofstrinto upper case andstrinto an identifier..- Parameters:
str- the string- Returns:
- the identifier
-
toIdentifier
protected static java.lang.String toIdentifier(java.lang.String str)
Helper to turnstrinto 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 withgetIvmlConfiguration().- Returns:
- the configuration
-
getIvmlConfiguration
protected abstract net.ssehub.easy.varModel.confModel.Configuration getIvmlConfiguration()
Returns the actual IVML configuration. Shall be consistent withgetVilConfiguration().- 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 projecttype- the change type
-
getType
public static java.lang.String getType(net.ssehub.easy.varModel.confModel.IDecisionVariable var)
Returns the type ofvaras string.- Parameters:
var- the variable- Returns:
- the type
-
-