Class ConfigurationSaver
- java.lang.Object
-
- net.ssehub.easy.varModel.confModel.ConfigurationSaver
-
public class ConfigurationSaver extends java.lang.ObjectThis method is part of the configuration and responsible for saving the values of the configuration inside theConfiguration.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
Fields Modifier and Type Field Description private ProjectdestProjectThe destination project where the information of the configuration should be stored to.private static EASyLoggerFactory.EASyLoggerLOGGERprivate booleanonlyUserInputSpecifies 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 ConfigurationsrcConfigurationthis configuration, which should be saved.
-
Constructor Summary
Constructors Modifier Constructor Description (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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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 ConfigurationgetConfiguration()Returns theConfiguration, which will currently saved by this saver.ProjectgetSavedConfiguration()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, java.lang.StringBuilder errors, AbstractVariable decl, IDecisionVariable var, Value value)Processes an assignment.private voidremovedLocalConfigChanges()Part 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 Detail
-
LOGGER
private static final EASyLoggerFactory.EASyLogger LOGGER
-
srcConfiguration
private Configuration srcConfiguration
this configuration, which should be saved.
-
destProject
private Project destProject
The destination project where the information of the configuration should be stored to.
-
onlyUserInput
private boolean onlyUserInput
Specifies whether only user Input should be stored:- true: Assignments in state
AssignmentState.ASSIGNEDandAssignmentState.FROZENwill be saved. - false: Assignments in state
AssignmentState.ASSIGNED,AssignmentState.FROZEN, andAssignmentState.DERIVEDwill be saved (i.e. also computed values).
- true: Assignments in state
-
-
Constructor Detail
-
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(Configuration, boolean, boolean)
-
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 state
AssignmentState.ASSIGNEDandAssignmentState.FROZENwill be saved. - false: Assignments in state
AssignmentState.ASSIGNED,AssignmentState.FROZEN, andAssignmentState.DERIVEDwill be saved (i.e. also computed values).
- true: Assignments in state
- Throws:
ConfigurationException- in case of any configuration errors- See Also:
createProject(Configuration),addVersion(Project, Configuration),addImports(Project, Configuration),#addVariables(Project, Configuration)
-
-
Method Detail
-
getSavedConfiguration
public Project getSavedConfiguration()
Returns the project where the values and frozen states are saved to.- Returns:
Configuration.getProject()if the constructor was called with ownProject = false, otherwise a new project which importsConfiguration.getProject().
-
getConfiguration
protected Configuration getConfiguration()
Returns theConfiguration, which will currently saved by this saver.- Returns:
- The configuration to be saved.
-
createProject
protected Project createProject(Configuration srcConfiguration)
Creates the project to store the configuration into.- Parameters:
srcConfiguration- the configuration to be stored- Returns:
- the project to store the configuration into
-
addVersion
protected void addVersion(Project destProject, Configuration srcConfiguration)
Adds the current version todestProject.- Parameters:
destProject- the destination project being set upsrcConfiguration- the source configuration
-
addImports
protected void addImports(Project destProject, Configuration srcConfiguration)
Adds the imports todestProject.- Parameters:
destProject- the destination project being set upsrcConfiguration- the source configuration
-
addLocalVariables
protected void addLocalVariables(Project destProject, Configuration srcConfiguration)
Adds local variables todestProject.- Parameters:
destProject- the destination project being set upsrcConfiguration- the source configuration
-
addAttributes
protected void addAttributes(Project destProject, Configuration srcConfiguration)
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
protected boolean isSavingEnabled(Project destProject, IDecisionVariable var)
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, java.lang.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
protected ConstraintSyntaxTree deriveOperand(AbstractVariable decl, IDecisionVariable var)
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
protected Value toSaveableValue(IDecisionVariable var, Value value)
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
private boolean checkState(IAssignmentState state)
Checks whether the sate (of a variable) should be saved.- Parameters:
state- The sate of the current variable to be saved.- Returns:
- true if the sate should be saved, false otherwise.
-
saveFreezeStates
protected void saveFreezeStates(Project confProject)
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:
Configuration.toProject(boolean)
-
createFreezeBlock
protected FreezeBlock createFreezeBlock(IFreezable[] freezables, Project parent)
Creates a freeze block, allowing customization (factory method).- Parameters:
freezables- the freezablesparent- the parent of the freeze block- Returns:
- the freeze block
-
-