Class Configuration
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.vilTypes.configuration.IvmlElement
-
- net.ssehub.easy.instantiation.core.model.vilTypes.configuration.Configuration
-
- All Implemented Interfaces:
IResolvable,IStringValueProvider,IVilType
public class Configuration extends IvmlElement implements IStringValueProvider
Represents a variability model and its configuration in VIL. This class provides specific methods to filter and select variables, attributes etc. Basically, the idea of this configuration class is to contain a filtered set of configurable elements (seeIVariableFilter, typically one that enables only frozen variables). It is currently unsure how much access we actually need to the variable and attribute declarations. Shifted this intoUtils.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IStringValueProvider
IStringValueProvider.StringComparator
-
-
Field Summary
Fields Modifier and Type Field Description private Attribute[]attributesprivate ChangeHistorychangedprivate Configurationconfigurationprivate IVariableFilterfilterprivate booleanisValidprivate java.util.Map<java.lang.String,IvmlElement>nameMapprivate Projectprojectprivate ScriptrootScriptprivate DecisionVariable[]variables
-
Constructor Summary
Constructors Modifier Constructor Description privateConfiguration(Configuration configuration, java.util.Set<AbstractIvmlVariable> changed)Creates a projected configuration only containing thechangedvariables.privateConfiguration(Configuration configuration, IConfigurationFilter variablesFilter, IVariableFilter filter)Creates a projected configuration (without explicit project).privateConfiguration(Configuration configuration, Project project, IConfigurationFilter variablesFilter, IVariableFilter filter)Creates a projected configuration.Configuration(Configuration configuration)Creates a new configuration instance from an EASy configuration based on frozen variables.(package private)Configuration(Configuration configuration, DecisionVariable[] variables, IVariableFilter filter)Creates a configuration from a given set of variables.Configuration(Configuration configuration, IVariableFilter filter)Creates a new configuration instance from an EASy configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<?>allInstances(TypeDescriptor<?> type)Returns all instances of the giventype.Sequence<Attribute>attributes()Returns the attributes of this configuration.Configurationcopy()Copies this configuration into a new configuration instance.DecisionVariablefindVariable(IDecisionVariable var)Searches for the VIL instance holdingvar.private DecisionVariablefindVariable(IDecisionVariable var, DecisionVariable dVar)Searches forvarindVar, i.e., whetherdVaror one of its contained variables holdesvar.(package private) IvmlElementget(java.lang.String name)Returns the mapped IVML element forname.(package private) AttributegetAttribute(int index)Returns the specified attribute.(package private) intgetAttributeCount()Returns the number of attributes.java.lang.BooleangetBooleanValue()Returns the boolean value of the decision variable.DecisionVariablegetByName(java.lang.String name)Returns the decision variable with the given (qualified) name.ChangeHistorygetChangeHistory()Returns the change history.ConfigurationgetConfiguration()Returns the underlying EASy configuration.IvmlElementgetElement(java.lang.String name)Returns the element matching the given (qualified) name.EnumValuegetEnumValue()Returns the boolean value of the decision variable.java.lang.IntegergetIntegerValue()Returns the integer value of the decision variable.java.lang.StringgetName()Returns the simple name of the element.java.lang.StringgetQualifiedName()Returns the qualified name of the element.java.lang.StringgetQualifiedType()Returns the qualified type name of the element.java.lang.DoublegetRealValue()Returns the real value of the decision variable.ScriptgetRootScript()Stores a hint to the root executing script (for VTL-by-name resolution).java.lang.StringgetStringValue()Returns the string value of the decision variable.java.lang.StringgetStringValue(IStringValueProvider.StringComparator comparator)Returns the string value of this object.TypeDescriptor<?>getType()Returns the VIL type of the element.java.lang.StringgetTypeName()Returns the simple type name of the element.java.lang.ObjectgetValue()Returns the (untyped) value of the decision variable.private voidindex(IvmlElement[] elements)Indexes the names of the given elements.protected voidinitializeAttributes()Lazily initializes the attributes.protected voidinitializeNested()Lazily initializes the nested parts.booleanisEmpty()Returns whether this configuration is empty.booleanisValid()Returns whether this configuration is valid, in particular afterreason().voidnotifyValueChanged(AbstractIvmlVariable variable, Value oldValue)Is called to notify the configuration about a changed variable value.Configurationreason()Re-reasons on the variable settings of this configuration.private voidresolveAndAddValue(Value value, java.util.Set<java.lang.Object> result)Resolves the VIL decision variable object forvalueand adds it toresult.ConfigurationselectAll()Returns a projection of this configuration returning all variables, including non-frozen runtime variables.ConfigurationselectByAnnotation(java.lang.String namePattern)Returns a projected version of this configuration according to the applied annotations.ConfigurationselectByAnnotation(java.lang.String name, java.lang.Object value)Returns a projected version of this configuration according to the applied annotations.ConfigurationselectByAttribute(java.lang.String namePattern)Returns a projected version of this configuration according to the applied annotations.ConfigurationselectByAttribute(java.lang.String name, java.lang.Object value)Returns a projected version of this configuration according to the applied annotations.ConfigurationselectByName(java.lang.String namePattern)Returns a projected version of this configuration according to the names of the variables.ConfigurationselectByProject(java.lang.String name)Returns a projected version of this configuration according to variables defined for the specified project.ConfigurationselectByProject(java.lang.String name, boolean considerImports)Returns a projected version of this configuration according to variables defined for the specified project.ConfigurationselectByType(java.lang.String typePattern)Returns a projected version of this configuration according to the type of the variables.ConfigurationselectChanged()Projects to the changed variables only.ConfigurationselectChangedWithContext()Projects to the changed variables with their context.ConfigurationselectFrozen()Projects this configuration to the frozen variables.voidsetRootScript(Script rootScript)Stores a hint to the root executing script (for VTL-by-name resolution).FileArtifactstore(Path path)Stores the underlying (unprojected) configuration topath.FileArtifactstore(Path path, boolean userValuesOnly)Stores the underlying (unprojected) configuration topath.Sequence<DecisionVariable>variables()Returns the decision variables represented by this configuration.-
Methods inherited from class net.ssehub.easy.instantiation.core.model.vilTypes.configuration.IvmlElement
checkElement, equals, equals2, getAnnotation, getAnnotation, getAttribute, getAttribute, getInstanceName, getTypeDescriptor, isEnacting, isNull, search, unequals, unequals2
-
-
-
-
Field Detail
-
rootScript
private Script rootScript
-
project
private Project project
-
configuration
private Configuration configuration
-
variables
private DecisionVariable[] variables
-
attributes
private Attribute[] attributes
-
nameMap
private java.util.Map<java.lang.String,IvmlElement> nameMap
-
filter
private IVariableFilter filter
-
isValid
private boolean isValid
-
changed
private ChangeHistory changed
-
-
Constructor Detail
-
Configuration
public Configuration(Configuration configuration)
Creates a new configuration instance from an EASy configuration based on frozen variables.- Parameters:
configuration- the IVML configuration instance to be wrapped
-
Configuration
public Configuration(Configuration configuration, IVariableFilter filter)
Creates a new configuration instance from an EASy configuration.- Parameters:
configuration- the IVML configuration instance to be wrappedfilter- the external variable filter, e.g., for frozen variables
-
Configuration
Configuration(Configuration configuration, DecisionVariable[] variables, IVariableFilter filter)
Creates a configuration from a given set of variables.- Parameters:
configuration- the IVML configuration instance to be wrappedvariables- the variables representing the actual contents of this configurationfilter- the external variable filter
-
Configuration
private Configuration(Configuration configuration, java.util.Set<AbstractIvmlVariable> changed)
Creates a projected configuration only containing thechangedvariables.- Parameters:
configuration- the base configurationchanged- the changed variables to be present in the projection
-
Configuration
private Configuration(Configuration configuration, IConfigurationFilter variablesFilter, IVariableFilter filter)
Creates a projected configuration (without explicit project).- Parameters:
configuration- the base configurationvariablesFilter- the filter to apply to variablesfilter- the external variable filter
-
Configuration
private Configuration(Configuration configuration, Project project, IConfigurationFilter variablesFilter, IVariableFilter filter)
Creates a projected configuration.- Parameters:
configuration- the base configurationproject- the top-level project used for the projection (may be null)variablesFilter- the filter to apply to variablesfilter- the external variable filter
-
-
Method Detail
-
index
private void index(IvmlElement[] elements)
Indexes the names of the given elements.- Parameters:
elements- the elements to index
-
getConfiguration
public Configuration getConfiguration()
Returns the underlying EASy configuration. This operation may be required to wrap old-style instantiators.- Returns:
- the EASy configuration
-
initializeNested
protected void initializeNested()
Description copied from class:IvmlElementLazily initializes the nested parts.- Specified by:
initializeNestedin classIvmlElement
-
initializeAttributes
protected void initializeAttributes()
Description copied from class:IvmlElementLazily initializes the attributes.- Specified by:
initializeAttributesin classIvmlElement
-
variables
public Sequence<DecisionVariable> variables()
Returns the decision variables represented by this configuration.- Returns:
- the decision variables
-
selectByName
public Configuration selectByName(java.lang.String namePattern) throws VilException
Returns a projected version of this configuration according to the names of the variables.- Parameters:
namePattern- a regular name pattern (or just the full name) all variables in the resulting configuration must match- Returns:
- the projected configuration
- Throws:
VilException- in case of an illformed name pattern
-
selectByType
public Configuration selectByType(java.lang.String typePattern) throws VilException
Returns a projected version of this configuration according to the type of the variables.- Parameters:
typePattern- a regular pattern (or just the full name) all variables in the resulting configuration must match- Returns:
- the projected configuration
- Throws:
VilException- in case of an illformed name pattern
-
selectByAnnotation
public Configuration selectByAnnotation(java.lang.String namePattern) throws VilException
Returns a projected version of this configuration according to the applied annotations.- Parameters:
namePattern- a regular name pattern (or just the full name) all applied annotations of all variables in the resulting configuration must match- Returns:
- the projected configuration
- Throws:
VilException- in case of an illformed name pattern
-
selectByAttribute
public Configuration selectByAttribute(java.lang.String namePattern) throws VilException
Returns a projected version of this configuration according to the applied annotations.- Parameters:
namePattern- a regular name pattern (or just the full name) all applied annotations of all variables in the resulting configuration must match- Returns:
- the projected configuration
- Throws:
VilException- in case of an illformed name pattern
-
selectByProject
public Configuration selectByProject(java.lang.String name, boolean considerImports)
Returns a projected version of this configuration according to variables defined for the specified project.- Parameters:
name- the name of the projectconsiderImports- whether imports of projects shall be considered- Returns:
- the projected configuration
-
selectByProject
public Configuration selectByProject(java.lang.String name)
Returns a projected version of this configuration according to variables defined for the specified project. Imports are considered by default.- Parameters:
name- the name of the project- Returns:
- the projected configuration
-
selectByAnnotation
public Configuration selectByAnnotation(java.lang.String name, java.lang.Object value) throws VilException
Returns a projected version of this configuration according to the applied annotations.- Parameters:
name- the name of the annotation (may be null)value- the value as an IVML identifier (may be null)- Returns:
- the projected configuration
- Throws:
VilException- in case of an illformed name pattern
-
selectByAttribute
public Configuration selectByAttribute(java.lang.String name, java.lang.Object value) throws VilException
Returns a projected version of this configuration according to the applied annotations.- Parameters:
name- the name of the annotation (may be null)value- the value as an IVML identifier (may be null)- Returns:
- the projected configuration
- Throws:
VilException- in case of an illformed name pattern
-
isEmpty
public boolean isEmpty()
Returns whether this configuration is empty.- Returns:
trueif there are no decision variables to be configured,falseelse
-
getStringValue
public java.lang.String getStringValue(IStringValueProvider.StringComparator comparator)
Description copied from interface:IStringValueProviderReturns the string value of this object.- Specified by:
getStringValuein interfaceIStringValueProvider- Overrides:
getStringValuein classIvmlElement- Parameters:
comparator- if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned- Returns:
- the string value
-
getName
public java.lang.String getName()
Description copied from class:IvmlElementReturns the simple name of the element.- Specified by:
getNamein interfaceIResolvable- Specified by:
getNamein classIvmlElement- Returns:
- the simple name
-
getQualifiedName
public java.lang.String getQualifiedName()
Description copied from class:IvmlElementReturns the qualified name of the element.- Specified by:
getQualifiedNamein classIvmlElement- Returns:
- the qualified name
-
getType
public TypeDescriptor<?> getType()
Description copied from class:IvmlElementReturns the VIL type of the element.- Specified by:
getTypein classIvmlElement- Returns:
- the VIL type (may be a fake descriptor if not resolved / no advice)
-
getTypeName
public java.lang.String getTypeName()
Description copied from class:IvmlElementReturns the simple type name of the element.- Specified by:
getTypeNamein classIvmlElement- Returns:
- the simple type name
-
getQualifiedType
public java.lang.String getQualifiedType()
Description copied from class:IvmlElementReturns the qualified type name of the element.- Specified by:
getQualifiedTypein classIvmlElement- Returns:
- the qualified type name
-
getAttribute
Attribute getAttribute(int index)
Returns the specified attribute.- Specified by:
getAttributein classIvmlElement- Parameters:
index- the 0-based index of the attribute to return- Returns:
- the specified attribute
- Throws:
java.lang.IndexOutOfBoundsException- ifindex < 0 || index >=getAttributeCount()
-
getAttributeCount
int getAttributeCount()
Returns the number of attributes.- Specified by:
getAttributeCountin classIvmlElement- Returns:
- the number of attributes
-
getValue
public java.lang.Object getValue()
Description copied from class:IvmlElementReturns the (untyped) value of the decision variable.- Specified by:
getValuein classIvmlElement- Returns:
- the value (may be null)
-
attributes
public Sequence<Attribute> attributes()
Returns the attributes of this configuration.- Returns:
- the attributes
-
getByName
public DecisionVariable getByName(java.lang.String name)
Returns the decision variable with the given (qualified) name.- Parameters:
name- the name of the variable to return- Returns:
- the variable or null if not found
-
getElement
public IvmlElement getElement(java.lang.String name)
Returns the element matching the given (qualified) name.- Specified by:
getElementin classIvmlElement- Parameters:
name- the name to search for- Returns:
- the matching element or null if not found
-
getStringValue
public java.lang.String getStringValue()
Description copied from class:IvmlElementReturns the string value of the decision variable.- Specified by:
getStringValuein classIvmlElement- Returns:
- the value (may be null)
-
getIntegerValue
public java.lang.Integer getIntegerValue()
Description copied from class:IvmlElementReturns the integer value of the decision variable.- Specified by:
getIntegerValuein classIvmlElement- Returns:
- the value (may be null)
-
getRealValue
public java.lang.Double getRealValue()
Description copied from class:IvmlElementReturns the real value of the decision variable.- Specified by:
getRealValuein classIvmlElement- Returns:
- the value (may be null)
-
getBooleanValue
public java.lang.Boolean getBooleanValue()
Description copied from class:IvmlElementReturns the boolean value of the decision variable.- Specified by:
getBooleanValuein classIvmlElement- Returns:
- the value (may be null)
-
getEnumValue
public EnumValue getEnumValue()
Description copied from class:IvmlElementReturns the boolean value of the decision variable.- Specified by:
getEnumValuein classIvmlElement- Returns:
- the value (may be null)
-
getRootScript
public Script getRootScript()
Stores a hint to the root executing script (for VTL-by-name resolution).- Returns:
- the hint to the executing script
-
setRootScript
public void setRootScript(Script rootScript)
Stores a hint to the root executing script (for VTL-by-name resolution).- Parameters:
rootScript- the hint to the executing script
-
store
public FileArtifact store(Path path) throws VilException
Stores the underlying (unprojected) configuration topath.- Parameters:
path- the target path- Returns:
- the created/modified file artifact
- Throws:
VilException- in case that storing the configuration fails
-
store
public FileArtifact store(Path path, boolean userValuesOnly) throws VilException
Stores the underlying (unprojected) configuration topath.- Parameters:
path- the target pathuserValuesOnly- store only user defined values (true) or the full configuration (false)- Returns:
- the created/modified file artifact
- Throws:
VilException- in case that storing the configuration fails
-
reason
public Configuration reason()
Re-reasons on the variable settings of this configuration. This operation is intended for runtime reasoning, in particular of changed variables only.- Returns:
- a projection of this configuration containing the variables changed by reasoning or this if the reasoner does not provide information on affected variables
-
selectFrozen
public Configuration selectFrozen()
Projects this configuration to the frozen variables. This method is intended to support runtime variability, i.e., to explicitly separate between pre-runtime instantiation and runtime instantiation. Please note that a configuration projected to frozen variables (in particular in pre-runtime instantiation) will remain frozen.- Returns:
- a projection of this configuration containing frozen variables only
-
selectAll
public Configuration selectAll()
Returns a projection of this configuration returning all variables, including non-frozen runtime variables. Please note that a configuration projected to frozen variables (in particular in pre-runtime instantiation) will remain frozen.- Returns:
- the projected configuration
-
copy
public Configuration copy()
Copies this configuration into a new configuration instance. This method is intended for instantiating runtime variabilities.- Returns:
- a copy of the configuration
-
isValid
public boolean isValid()
Returns whether this configuration is valid, in particular afterreason().- Overrides:
isValidin classIvmlElement- Returns:
trueif this configuration is valid,falseelse- See Also:
VariableValueMapping#getValidFlag(AbstractIvmlVariable)
-
selectChanged
public Configuration selectChanged()
Projects to the changed variables only.- Returns:
- a projects of the changed variables only, may be empty
- See Also:
selectChangedWithContext()
-
selectChangedWithContext
public Configuration selectChangedWithContext()
Projects to the changed variables with their context.- Returns:
- a projects of the changed variables only, may be empty
- See Also:
selectChanged()
-
notifyValueChanged
public void notifyValueChanged(AbstractIvmlVariable variable, Value oldValue)
Is called to notify the configuration about a changed variable value.- Parameters:
variable- the variable the value has changed foroldValue- the value of the variable before the change
-
get
IvmlElement get(java.lang.String name)
Returns the mapped IVML element forname.- Parameters:
name- the name- Returns:
- the mapped element (may be null)
-
getChangeHistory
public ChangeHistory getChangeHistory()
Returns the change history.- Returns:
- the change history
-
findVariable
public DecisionVariable findVariable(IDecisionVariable var)
Searches for the VIL instance holdingvar.- Parameters:
var- the variable- Returns:
- the VIL instance holding
var
-
findVariable
private DecisionVariable findVariable(IDecisionVariable var, DecisionVariable dVar)
Searches forvarindVar, i.e., whetherdVaror one of its contained variables holdesvar.- Parameters:
var- the variable to search fordVar- the VIL variable wrapper to look into- Returns:
- the VIL wrapper representing
dVaror null if not found
-
allInstances
public Set<?> allInstances(TypeDescriptor<?> type)
Returns all instances of the giventype.- Parameters:
type- the type to look for- Returns:
- all instances (may be empty)
-
resolveAndAddValue
private void resolveAndAddValue(Value value, java.util.Set<java.lang.Object> result)
Resolves the VIL decision variable object forvalueand adds it toresult.- Parameters:
value- the valueresult- the result (to be modified as a side effect)
-
-