Class PolicyAttribute

Direct Known Subclasses:
ConstantPolicyAttribute, DefaultPolicyAttribute

public abstract class PolicyAttribute extends Attribute
An attribute of a PolicyCmptType.
  • Constructor Details

  • Method Details

    • getType

      public PolicyCmptType getType()
      Returns the PolicyCmptType this attribute belongs to.
      Overrides:
      getType in class TypePart
    • getModelType

      @Deprecated public PolicyCmptType getModelType()
      Deprecated.
      Returns the parent Type
      Overrides:
      getModelType in class TypePart
    • getSuperAttribute

      public PolicyAttribute getSuperAttribute()
      Description copied from class: Attribute
      Returns the attribute that is overridden by this attribute if this attribute overrides another one. Otherwise returns null.
      Overrides:
      getSuperAttribute in class Attribute
      Returns:
      The attribute that is overridden by this attribute.
      See Also:
    • getValue

      public abstract Object getValue(IModelObject modelObject)
      Returns the value of the given model object's attribute identified by this model type attribute.
      Parameters:
      modelObject - a model object corresponding to the Type this attribute belongs to
      Returns:
      the value of the given model object's attribute identified by this model type attribute
      Throws:
      IllegalArgumentException - if the model object does not have an attribute fitting this model type attribute or that attribute is not accessible for any reason
    • setValue

      public abstract void setValue(IModelObject modelObject, Object value)
      Sets the given model object's attribute identified by this model type attribute to the given value. This only works for changeable attributes.
      Parameters:
      modelObject - a model object corresponding to the Type this attribute belongs to
      value - an object of this model type attribute's datatype
      Throws:
      IllegalArgumentException - if the model object does not have a changeable attribute fitting this model type attribute or that attribute is not accessible for any reason or the value does not fit the attribute's datatype.
      UnsupportedOperationException - if invoked on a AttributeKind.CONSTANT attribute.
    • removeValue

      public abstract void removeValue(IModelObject modelObject)
      Sets the given model object's attribute identified by this model type attribute to its null-value (null for most datatypes, a NullObject for the NullObjectSupport-datatypes Decimal and Money, and an empty string for the datatype String) This only works for changeable attributes.
      Parameters:
      modelObject - a model object corresponding to the Type this attribute belongs to
      Throws:
      IllegalArgumentException - if the model object does not have a changeable attribute fitting this model type attribute or that attribute is not accessible for any reason.
      UnsupportedOperationException - if invoked on a AttributeKind.CONSTANT attribute.
      Since:
      21.6
    • isEmpty

      public boolean isEmpty(IModelObject modelObject)
      Checks whether this attribute is empty on the given model object.

      An attribute is considered empty if its value is one of the following cases:

      • null
      • NullObject
      • empty/blank String
      Returns:
      true if empty
      Since:
      21.6
    • isValuePresent

      public boolean isValuePresent(IModelObject modelObject)
      Checks whether this attribute has a non-empty value on the given model object.
      Since:
      21.6
      See Also:
    • getDefaultValue

      public Object getDefaultValue(IConfigurableModelObject modelObject)
      Returns the (product configured) default value of the attribute identified by this configurable model type attribute. Throws an IllegalStateException if the model object has no default value constant or the product has no getDefaultValue~() method for this attribute.
      API Note:
      this method is supplanted by the more general getDefaultValue(IModelObject) but remains here for compile time compatibility with older versions.
      Parameters:
      modelObject - the configurable model object from which product component and (if necessary) effective date can be retrieved
      Throws:
      IllegalStateException - if the model object has no default value constant or the product has no getter method for this attribute's default value.
      IllegalArgumentException - if the invocation of the method that should get the default value for this attribute fails for any reason
      See Also:
    • getDefaultValue

      public abstract Object getDefaultValue(IModelObject modelObject)
      Returns the (product configured) default value of the attribute identified by this model type attribute. Throws an IllegalStateException if the model object has no default value constant or the product has no getDefaultValue~() method for this attribute.
      Parameters:
      modelObject - the configurable model object from which product component and (if necessary) effective date can be retrieved
      Throws:
      IllegalStateException - if the model object has no default value constant or the product has no getter method for this attribute's default value.
      IllegalArgumentException - if the invocation of the method that should get the default value for this attribute fails for any reason
      Since:
      22.6
      See Also:
    • getDefaultValue

      public abstract Object getDefaultValue(IProductComponent source, Calendar effectiveDate)
      Returns the product configured default value of the attribute identified by this model type attribute.
      Parameters:
      source - the product component to read the attribute default value from.
      effectiveDate - the date to determine the product component generation. If null the latest generation is used. Is ignored if the attribute's configuration is not changing over time.
      Throws:
      UnsupportedOperationException - if invoked on a AttributeKind.CONSTANT attribute.
      IllegalStateException - if the model object has no getter method for this attribute's default value. This also occurs if the corresponding policy class is not configured by a product class.
      IllegalArgumentException - if the invocation of the method that should get the default value for this attribute fails for any reason
    • setDefaultValue

      public abstract void setDefaultValue(IConfigurableModelObject modelObject, Object defaultValue)
      Sets the product configured default value of the attribute identified by this model type attribute.
      Parameters:
      modelObject - the configurable model object from which product component and (if necessary) effective date can be retrieved
      defaultValue - the new default value
      Throws:
      UnsupportedOperationException - if invoked on a AttributeKind.CONSTANT attribute.
      IllegalStateException - if the model object has no setter method for this attribute's default value. This also occurs if the corresponding policy class is not configured by a product class.
      IllegalArgumentException - if the invocation of the method that should set the default value for this attribute fails for any reason
      Since:
      20.6
    • setDefaultValue

      public abstract void setDefaultValue(IProductComponent target, Calendar effectiveDate, Object defaultValue)
      Sets the product configured default value of the attribute identified by this model type attribute.
      Parameters:
      target - the product component to write the attribute default value to
      effectiveDate - the date to determine the product component generation. If null the latest generation is used. Is ignored if the attribute's configuration is not changing over time.
      defaultValue - the new default value
      Throws:
      UnsupportedOperationException - if invoked on a AttributeKind.CONSTANT attribute.
      IllegalStateException - if the model object has no setter method for this attribute's default value. This also occurs if the corresponding policy class is not configured by a product class.
      IllegalArgumentException - if the invocation of the method that should set the default value for this attribute fails for any reason
      Since:
      20.6
    • setDefaultValue

      public abstract void setDefaultValue(IProductComponentGeneration target, Object defaultValue)
      Sets the product configured default value of the attribute identified by this model type attribute.
      Parameters:
      defaultValue - the new default value
      target - the product component generation
      Throws:
      UnsupportedOperationException - if invoked on a AttributeKind.CONSTANT attribute.
      IllegalStateException - if the model object has no setter method for this attribute's default value. This also occurs if the corresponding policy class is not configured by a product class.
      IllegalArgumentException - if the invocation of the method that should set the default value for this attribute fails for any reason
      Since:
      25.1
    • getValueSet

      public abstract org.faktorips.valueset.ValueSet<?> getValueSet(IModelObject modelObject, IValidationContext context)
      Returns the value set of the given model object's attribute identified by this model type attribute.

      Note: If the PolicyCmptType this PolicyAttribute belongs to defines an UnrestrictedValueSet including null, no method is generated by Faktor-IPS. Therefore, a value set method in a subclass is not found even if the IModelObject passed to this method is an instance of that subclass. To make sure to get the correct value set, always use IpsModel.getPolicyCmptType(IModelObject) on the actual IModelObject instead of IpsModel.getPolicyCmptType(Class) on the super class.

      Parameters:
      modelObject - a model object
      Throws:
      IllegalStateException - if the method that should return a value set for this attribute has too many arguments
      IllegalArgumentException - if the invocation of the method that should return a value set for this attribute fails for any reason
    • getValueSet

      public org.faktorips.valueset.ValueSet<?> getValueSet(IModelObject modelObject)
      Returns the value set of the given model object's attribute identified by this model type attribute.

      Note: If the PolicyCmptType this PolicyAttribute belongs to defines an UnrestrictedValueSet including null, no method is generated by Faktor-IPS. Therefore, a value set method in a subclass is not found even if the IModelObject passed to this method is an instance of that subclass. To make sure to get the correct value set, always use IpsModel.getPolicyCmptType(IModelObject) on the actual IModelObject instead of IpsModel.getPolicyCmptType(Class) on the super class.

      This method uses a default IValidationContext.
      Parameters:
      modelObject - a model object
      Throws:
      IllegalStateException - if the method that should return a value set for this attribute has too many arguments
      IllegalArgumentException - if the invocation of the method that should return a value set for this attribute fails for any reason
    • getValueSet

      public abstract org.faktorips.valueset.ValueSet<?> getValueSet(IProductComponent source, Calendar effectiveDate, IValidationContext context)
      Returns the value set of the given model object's attribute identified by this model type attribute. Returns an UnrestrictedValueSet if there is no method that returns a value set for this attribute.
      Parameters:
      source - the product component to read an attribute value set from. Must correspond to the Type this attribute belongs to.
      effectiveDate - the date to determine the product component generation. If null the latest generation is used. Is ignored if the attribute's configuration is not changing over time.
      Throws:
      IllegalStateException - if the method that should return a value set for this attribute has too many arguments
      IllegalArgumentException - if the invocation of the method that should return a value set for this attribute fails for any reason
    • getValueSet

      public org.faktorips.valueset.ValueSet<?> getValueSet(IProductComponent source, Calendar effectiveDate)
      Returns the value set of the given model object's attribute identified by this model type attribute. Returns an UnrestrictedValueSet if there is no method that returns a value set for this attribute.

      This method uses a default IValidationContext.

      Parameters:
      source - the product component to read an attribute value set from. Must correspond to the Type this attribute belongs to.
      effectiveDate - the date to determine the product component generation. If null the latest generation is used. Is ignored if the attribute's configuration is not changing over time.
      Throws:
      IllegalStateException - if the method that should return a value set for this attribute has too many arguments
      IllegalArgumentException - if the invocation of the method that should return a value set for this attribute fails for any reason
    • setValueSet

      public abstract void setValueSet(IConfigurableModelObject modelObject, org.faktorips.valueset.ValueSet<?> valueSet)
      Sets the product configured set of allowed values of the attribute identified by this model type attribute.

      Caution: as generics are erased at runtime, it is possible to set a ValueSet of a mismatched type with this method, for example an OrderedValueSet<String> for an attribute with Attribute.getDatatype() Integer, which will result in a ClassCastException on later method calls.

      Parameters:
      modelObject - the configurable model object from which product component and (if necessary) effective date can be retrieved
      valueSet - the new value set
      Throws:
      UnsupportedOperationException - if invoked on a AttributeKind.CONSTANT attribute.
      ClassCastException - if the type of value set does not match the property's configuration
      IllegalStateException - if the model object has no setter method for this attribute's value set. This also occurs if the corresponding policy class is not configured by a product class.
      IllegalArgumentException - if the invocation of the method that should set the value set for this attribute fails for any reason
      Since:
      20.6
    • setValueSet

      public abstract void setValueSet(IProductComponent target, Calendar effectiveDate, org.faktorips.valueset.ValueSet<?> valueSet)
      Sets the product configured set of allowed values of the attribute identified by this model type attribute.

      Caution: as generics are erased at runtime, it is possible to set a ValueSet of a mismatched type with this method, for example an OrderedValueSet<String> for an attribute with Attribute.getDatatype() Integer, which will result in a ClassCastException on later method calls.

      Parameters:
      target - the product component to write the attribute value set to. Must correspond to the Type this attribute belongs to.
      effectiveDate - the date to determine the product component generation. If null the latest generation is used. Is ignored if the attribute's configuration is not changing over time.
      valueSet - the new value set
      Throws:
      UnsupportedOperationException - if invoked on a AttributeKind.CONSTANT attribute.
      ClassCastException - if the type of value set does not match the property's configuration
      IllegalStateException - if the model object has no setter method for this attribute's value set. This also occurs if the corresponding policy class is not configured by a product class.
      IllegalArgumentException - if the invocation of the method that should set the value set for this attribute fails for any reason
      Since:
      20.6
    • setValueSet

      public abstract void setValueSet(IProductComponentGeneration target, org.faktorips.valueset.ValueSet<?> valueSet)
      Sets the product configured set of allowed values of the attribute identified by this model type attribute.

      Caution: as generics are erased at runtime, it is possible to set a ValueSet of a mismatched type with this method, for example an OrderedValueSet<String> for an attribute with Attribute.getDatatype() Integer, which will result in a ClassCastException on later method calls.

      Parameters:
      target - the product component generation, which will be used to write the attribute value set to the corresponding product component to.
      valueSet - the new value set
      Throws:
      UnsupportedOperationException - if invoked on a AttributeKind.CONSTANT attribute.
      ClassCastException - if the type of value set does not match the property's configuration
      IllegalStateException - if the model object has no setter method for this attribute's value set. This also occurs if the corresponding policy class is not configured by a product class.
      IllegalArgumentException - if the invocation of the method that should set the value set for this attribute fails for any reason
      Since:
      25.1