Package org.faktorips.runtime.model.type
Class ModelObjectAttribute
java.lang.Object
org.faktorips.runtime.model.type.ModelObjectAttribute
A
ModelObjectAttribute combines a PolicyAttribute with a specific
IModelObject of the PolicyCmptType the PolicyAttribute belongs to and
provides convenience methods to query and modify that combination.- Since:
- 21.6
-
Method Summary
Modifier and TypeMethodDescriptionReturns the product configured default value of the attribute identified by this model object attribute.getValue()Returns the value of the this model object attribute.org.faktorips.valueset.ValueSet<?>Returns the set of values allowed for this model object attribute.booleanisEmpty()Checks whether this model object attribute is empty.booleanReturns whether this attribute is consideredRelevance.IRRELEVANT.booleanReturns whether this attribute is consideredRelevance.MANDATORY.booleanReturns whether this attribute is consideredRelevance.OPTIONAL.booleanReturns whether this attribute is considered relevant.booleanChecks whether this model object attribute has a non-empty value.static final ModelObjectAttributeof(IModelObject modelObject, String attributeName) Creates aModelObjectAttributefor the given model object and policy attribute.static final ModelObjectAttributeof(IModelObject modelObject, PolicyAttribute policyAttribute) Creates aModelObjectAttributefor the given model object and policy attribute.Sets the model object attribute to its null-value (nullfor most datatypes, aNullObjectfor for theNullObjectSupport-datatypesDecimalandMoney, and an empty string for the datatypeString) This only works for changeable attributes.setDefaultValue(Object defaultValue) Sets the product configured default value of this attribute.setValueSet(org.faktorips.valueset.ValueSet<?> valueSet) Sets the product configured set of allowed values of this model object attribute.Returns anObjectPropertyfor this model object attribute.
-
Method Details
-
of
public static final ModelObjectAttribute of(@NonNull IModelObject modelObject, @NonNull PolicyAttribute policyAttribute) Creates aModelObjectAttributefor the given model object and policy attribute.- Parameters:
modelObject- a model object instance of thePolicyCmptTypethePolicyAttributebelongs topolicyAttribute- a policy attribute- Throws:
IllegalArgumentException- if thePolicyAttributebelongs to aPolicyCmptTypetheIModelObjectis not an instance of
-
of
public static final ModelObjectAttribute of(@NonNull IModelObject modelObject, @NonNull String attributeName) Creates aModelObjectAttributefor the given model object and policy attribute.- Parameters:
modelObject- a model objectattributeName- the name of aPolicyAttributeof the model object'sPolicyCmptType
-
getModelObject
-
getPolicyAttribute
-
getValue
Returns the value of the this model object attribute.- Throws:
IllegalArgumentException- if the attribute is not accessible for any reason- See Also:
-
isValuePresent
public boolean isValuePresent()Checks whether this model object attribute has a non-empty value. -
isEmpty
public boolean isEmpty()Checks whether this model object attribute is empty.- Returns:
trueif empty- See Also:
-
removeValue
Sets the model object attribute to its null-value (nullfor most datatypes, aNullObjectfor for theNullObjectSupport-datatypesDecimalandMoney, and an empty string for the datatypeString) This only works for changeable attributes.- Returns:
- this
ModelObjectAttribute, to allow method chaining. - Throws:
IllegalArgumentException- if the model object attribute is not accessible for any reason.UnsupportedOperationException- if invoked on aAttributeKind.CONSTANTattribute.- See Also:
-
getValueSet
public org.faktorips.valueset.ValueSet<?> getValueSet()Returns the set of values allowed for this model object attribute.- Throws:
UnsupportedOperationException- if invoked on aAttributeKind.CONSTANTattribute.IllegalStateException- if the method that should return a value set for this attribute has too many argumentsIllegalArgumentException- if the invocation of the method that should return a value set for this attribute fails for any reason- See Also:
-
setValueSet
Sets the product configured set of allowed values of this model object attribute.Caution: as generics are erased at runtime, it is possible to set a
ValueSetof a mismatched type with this method, for example anOrderedValueSet<String>for an attribute with datatypeInteger, which will result in aClassCastExceptionon later method calls.- Parameters:
valueSet- the new value set- Returns:
- this
ModelObjectAttribute, to allow method chaining. - Throws:
UnsupportedOperationException- if invoked on aAttributeKind.CONSTANTattribute.ClassCastException- if the type of value set does not match the property's configuration or the model object is noIConfigurableModelObject.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- See Also:
-
getDefaultValue
Returns the product configured default value of the attribute identified by this model object attribute. Throws anIllegalStateExceptionif the model object has no getDefaultValue() method for this attribute. This also occurs if the corresponding policy class is not configured by a product class.- Throws:
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 reasonClassCastException- if the model object is noIConfigurableModelObject.- See Also:
-
setDefaultValue
Sets the product configured default value of this attribute. necessary) effective date can be retrieved- Parameters:
defaultValue- the new default value- Returns:
- this
ModelObjectAttribute, to allow method chaining. - Throws:
UnsupportedOperationException- if invoked on aAttributeKind.CONSTANTattribute.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 reasonClassCastException- if the model object is noIConfigurableModelObject.- See Also:
-
isIrrelevant
public boolean isIrrelevant()Returns whether this attribute is consideredRelevance.IRRELEVANT. -
isRelevant
public boolean isRelevant()Returns whether this attribute is considered relevant. -
isMandatory
public boolean isMandatory()Returns whether this attribute is consideredRelevance.MANDATORY. -
isOptional
public boolean isOptional()Returns whether this attribute is consideredRelevance.OPTIONAL. -
toObjectProperty
Returns anObjectPropertyfor this model object attribute.
-