Class 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 (see IVariableFilter, 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 into Utils.
    Author:
    Holger Eichelberger
    • 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 wrapped
        filter - 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 wrapped
        variables - the variables representing the actual contents of this configuration
        filter - the external variable filter
      • Configuration

        private Configuration​(Configuration configuration,
                              java.util.Set<AbstractIvmlVariable> changed)
        Creates a projected configuration only containing the changed variables.
        Parameters:
        configuration - the base configuration
        changed - 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 configuration
        variablesFilter - the filter to apply to variables
        filter - the external variable filter
      • Configuration

        private Configuration​(Configuration configuration,
                              Project project,
                              IConfigurationFilter variablesFilter,
                              IVariableFilter filter)
        Creates a projected configuration.
        Parameters:
        configuration - the base configuration
        project - the top-level project used for the projection (may be null)
        variablesFilter - the filter to apply to variables
        filter - 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
      • 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 project
        considerImports - 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:
        true if there are no decision variables to be configured, false else
      • getName

        public java.lang.String getName()
        Description copied from class: IvmlElement
        Returns the simple name of the element.
        Specified by:
        getName in interface IResolvable
        Specified by:
        getName in class IvmlElement
        Returns:
        the simple name
      • getQualifiedName

        public java.lang.String getQualifiedName()
        Description copied from class: IvmlElement
        Returns the qualified name of the element.
        Specified by:
        getQualifiedName in class IvmlElement
        Returns:
        the qualified name
      • getType

        public TypeDescriptor<?> getType()
        Description copied from class: IvmlElement
        Returns the VIL type of the element.
        Specified by:
        getType in class IvmlElement
        Returns:
        the VIL type (may be a fake descriptor if not resolved / no advice)
      • getTypeName

        public java.lang.String getTypeName()
        Description copied from class: IvmlElement
        Returns the simple type name of the element.
        Specified by:
        getTypeName in class IvmlElement
        Returns:
        the simple type name
      • getQualifiedType

        public java.lang.String getQualifiedType()
        Description copied from class: IvmlElement
        Returns the qualified type name of the element.
        Specified by:
        getQualifiedType in class IvmlElement
        Returns:
        the qualified type name
      • getAttribute

        Attribute getAttribute​(int index)
        Returns the specified attribute.
        Specified by:
        getAttribute in class IvmlElement
        Parameters:
        index - the 0-based index of the attribute to return
        Returns:
        the specified attribute
        Throws:
        java.lang.IndexOutOfBoundsException - if index < 0 || index >= getAttributeCount()
      • getAttributeCount

        int getAttributeCount()
        Returns the number of attributes.
        Specified by:
        getAttributeCount in class IvmlElement
        Returns:
        the number of attributes
      • getValue

        public java.lang.Object getValue()
        Description copied from class: IvmlElement
        Returns the (untyped) value of the decision variable.
        Specified by:
        getValue in class IvmlElement
        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:
        getElement in class IvmlElement
        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: IvmlElement
        Returns the string value of the decision variable.
        Specified by:
        getStringValue in class IvmlElement
        Returns:
        the value (may be null)
      • getIntegerValue

        public java.lang.Integer getIntegerValue()
        Description copied from class: IvmlElement
        Returns the integer value of the decision variable.
        Specified by:
        getIntegerValue in class IvmlElement
        Returns:
        the value (may be null)
      • getRealValue

        public java.lang.Double getRealValue()
        Description copied from class: IvmlElement
        Returns the real value of the decision variable.
        Specified by:
        getRealValue in class IvmlElement
        Returns:
        the value (may be null)
      • getBooleanValue

        public java.lang.Boolean getBooleanValue()
        Description copied from class: IvmlElement
        Returns the boolean value of the decision variable.
        Specified by:
        getBooleanValue in class IvmlElement
        Returns:
        the value (may be null)
      • getEnumValue

        public EnumValue getEnumValue()
        Description copied from class: IvmlElement
        Returns the boolean value of the decision variable.
        Specified by:
        getEnumValue in class IvmlElement
        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 to path.
        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 to path.
        Parameters:
        path - the target path
        userValuesOnly - 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 after reason().
        Overrides:
        isValid in class IvmlElement
        Returns:
        true if this configuration is valid, false else
        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 for
        oldValue - the value of the variable before the change
      • get

        IvmlElement get​(java.lang.String name)
        Returns the mapped IVML element for name.
        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 holding var.
        Parameters:
        var - the variable
        Returns:
        the VIL instance holding var
      • findVariable

        private DecisionVariable findVariable​(IDecisionVariable var,
                                              DecisionVariable dVar)
        Searches for var in dVar, i.e., whether dVar or one of its contained variables holdes var.
        Parameters:
        var - the variable to search for
        dVar - the VIL variable wrapper to look into
        Returns:
        the VIL wrapper representing dVar or null if not found
      • allInstances

        public Set<?> allInstances​(TypeDescriptor<?> type)
        Returns all instances of the given type.
        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 for value and adds it to result.
        Parameters:
        value - the value
        result - the result (to be modified as a side effect)