Class ConfigurationSaver
java.lang.Object
net.ssehub.easy.varModel.confModel.ConfigurationSaver
This method is part of the configuration and responsible for saving the values of the configuration
inside the
Configuration.toProject(boolean) method. The visibility of this class has been relaxed
in order to serve as basis for refinements.- Author:
- El-Sharkawy, Holger Eichelberger
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ProjectThe destination project where the information of the configuration should be stored to.private static final net.ssehub.easy.basics.logger.EASyLoggerFactory.EASyLoggerprivate booleanSpecifies whether only user Input should be stored:true: Assignments in stateAssignmentState.ASSIGNEDandAssignmentState.FROZENwill be saved.false: Assignments in stateAssignmentState.ASSIGNED,AssignmentState.FROZEN, andAssignmentState.DERIVEDwill be saved (i.e.private Configurationthis configuration, which should be saved. -
Constructor Summary
ConstructorsModifierConstructorDescription(package private)ConfigurationSaver(Configuration srcConfiguration, boolean ownProject) Default constructor for this class.protectedConfigurationSaver(Configuration srcConfiguration, boolean ownProject, boolean onlyUserInput) Constructor for this class for saving the configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddAttributes(Project destProject, Configuration srcConfiguration) Adds attributes todestProject.protected voidaddImports(Project destProject, Configuration srcConfiguration) Adds the imports todestProject.protected voidaddLocalVariables(Project destProject, Configuration srcConfiguration) Adds local variables todestProject.protected voidaddVersion(Project destProject, Configuration srcConfiguration) Adds the current version todestProject.private booleancheckState(IAssignmentState state) Checks whether the sate (of a variable) should be saved.protected ConstraintSyntaxTreecreateAssignmentConstraint(Project dstProject, AbstractVariable decl, IDecisionVariable var, Value value) Creates an assignment constraint.protected FreezeBlockcreateFreezeBlock(IFreezable[] freezables, Project parent) Creates a freeze block, allowing customization (factory method).protected ProjectcreateProject(Configuration srcConfiguration) Creates the project to store the configuration into.protected ConstraintSyntaxTreederiveOperand(AbstractVariable decl, IDecisionVariable var) Derives the operand expression for turning a configuration into a project.protected ConfigurationReturns theConfiguration, which will currently saved by this saver.Returns the project where the values and frozen states are saved to.protected booleanisSavingEnabled(Project destProject, IDecisionVariable var) Returns whether saving this variable (for the destination projectdestProject) is enabled.private intprocessAssignment(Project confProject, StringBuilder errors, AbstractVariable decl, IDecisionVariable var, Value value) Processes an assignment.private voidPart of theConfiguration.toProject(boolean)method.protected voidsaveFreezeStates(Project confProject) Part of theConfiguration.toProject(boolean)method.protected ValuetoSaveableValue(IDecisionVariable var, Value value) This method escapes special characters for saving them into a file.
-
Field Details
-
LOGGER
private static final net.ssehub.easy.basics.logger.EASyLoggerFactory.EASyLogger LOGGER -
srcConfiguration
this configuration, which should be saved. -
destProject
The destination project where the information of the configuration should be stored to. -
onlyUserInput
private boolean onlyUserInputSpecifies whether only user Input should be stored:true: Assignments in stateAssignmentState.ASSIGNEDandAssignmentState.FROZENwill be saved.false: Assignments in stateAssignmentState.ASSIGNED,AssignmentState.FROZEN, andAssignmentState.DERIVEDwill be saved (i.e. also computed values).
-
-
Constructor Details
-
ConfigurationSaver
ConfigurationSaver(Configuration srcConfiguration, boolean ownProject) throws ConfigurationException Default constructor for this class. This Constructor will save only user input.- Parameters:
srcConfiguration- The configuration which should be saved.ownProject- return an own project (true) or add the configuration toConfiguration.getProject()(false)- Throws:
ConfigurationException- in case of any configuration errors- See Also:
-
ConfigurationSaver
protected ConfigurationSaver(Configuration srcConfiguration, boolean ownProject, boolean onlyUserInput) throws ConfigurationException Constructor for this class for saving the configuration. With this constructor it is possible to decide whether only user input should be saved or all configured values.- Parameters:
srcConfiguration- The configuration which should be saved.ownProject- return an own project (true) or add the configuration toConfiguration.getProject()(false)onlyUserInput- Specifies whether only user Input should be stored:true: Assignments in stateAssignmentState.ASSIGNEDandAssignmentState.FROZENwill be saved.false: Assignments in stateAssignmentState.ASSIGNED,AssignmentState.FROZEN, andAssignmentState.DERIVEDwill be saved (i.e. also computed values).
- Throws:
ConfigurationException- in case of any configuration errors- See Also:
-
-
Method Details
-
getSavedConfiguration
Returns the project where the values and frozen states are saved to.- Returns:
Configuration.getProject()if the constructor was called withownProject = false, otherwise a new project which importsConfiguration.getProject().
-
getConfiguration
Returns theConfiguration, which will currently saved by this saver.- Returns:
- The configuration to be saved.
-
createProject
Creates the project to store the configuration into.- Parameters:
srcConfiguration- the configuration to be stored- Returns:
- the project to store the configuration into
-
addVersion
Adds the current version todestProject.- Parameters:
destProject- the destination project being set upsrcConfiguration- the source configuration
-
addImports
Adds the imports todestProject.- Parameters:
destProject- the destination project being set upsrcConfiguration- the source configuration
-
addLocalVariables
Adds local variables todestProject.- Parameters:
destProject- the destination project being set upsrcConfiguration- the source configuration
-
addAttributes
Adds attributes todestProject.- Parameters:
destProject- the destination project being set upsrcConfiguration- the source configuration
-
createAssignmentConstraint
protected ConstraintSyntaxTree createAssignmentConstraint(Project dstProject, AbstractVariable decl, IDecisionVariable var, Value value) Creates an assignment constraint.- Parameters:
dstProject- the destination projectdecl- the variable declarationvar- the configuration variable itselfvalue- the value assigned todecl- Returns:
- the created constraint
-
isSavingEnabled
Returns whether saving this variable (for the destination projectdestProject) is enabled.- Parameters:
destProject- the project being savedvar- the variable to be checked- Returns:
trueif saving forvaris enabled,falseelse
-
removedLocalConfigChanges
private void removedLocalConfigChanges()Part of theConfiguration.toProject(boolean)method. Removes all local configuration settings of the current project, before current configuration can be merged into the project. -
processAssignment
private int processAssignment(Project confProject, StringBuilder errors, AbstractVariable decl, IDecisionVariable var, Value value) Processes an assignment.- Parameters:
confProject- the project to be modified as a side effecterrors- the errors collected so fardecl- the variable declarationvar- the configuration variable itselfvalue- the value assigned todecl- Returns:
- the new value of
code
-
deriveOperand
Derives the operand expression for turning a configuration into a project.- Parameters:
decl- the variable declaration to start atvar- the related decision variable- Returns:
- the constraint syntax tree representing the operand for an assignment
-
toSaveableValue
This method escapes special characters for saving them into a file. Should only be called inside theprocessAssignment(Project, StringBuilder, AbstractVariable, IDecisionVariable, Value)method.- Parameters:
var- The variable which belongs to the corresponding value (as t holds the states, which are needed for filtering irrelevant values).value- The value which should be saved.- Returns:
- the value where all problematic characters are escaped.
-
checkState
Checks whether the sate (of a variable) should be saved.- Parameters:
state- The sate of the current variable to be saved.- Returns:
trueif the sate should be saved,falseotherwise.
-
saveFreezeStates
Part of theConfiguration.toProject(boolean)method. This method saves the frozen state of frozen variables.- Parameters:
confProject- The project where the states should be saved to.- See Also:
-
createFreezeBlock
Creates a freeze block, allowing customization (factory method).- Parameters:
freezables- the freezablesparent- the parent of the freeze block- Returns:
- the freeze block
-