Package org.faktorips.runtime.model.type
Class ModelObjectAttribute
- java.lang.Object
-
- org.faktorips.runtime.model.type.ModelObjectAttribute
-
public class ModelObjectAttribute extends java.lang.ObjectAModelObjectAttributecombines aPolicyAttributewith a specificIModelObjectof thePolicyCmptTypethePolicyAttributebelongs to and provides convenience methods to query and modify that combination.- Since:
- 21.6
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ObjectgetDefaultValue()Returns the product configured default value of the attribute identified by this model object attribute.IModelObjectgetModelObject()PolicyAttributegetPolicyAttribute()java.lang.ObjectgetValue()Returns the value of the this model object attribute.org.faktorips.valueset.ValueSet<?>getValueSet()Returns the set of values allowed for this model object attribute.booleanisEmpty()Checks whether this model object attribute is empty.booleanisIrrelevant()Returns whether this attribute is consideredRelevance.IRRELEVANT.booleanisMandatory()Returns whether this attribute is consideredRelevance.MANDATORY.booleanisOptional()Returns whether this attribute is consideredRelevance.OPTIONAL.booleanisRelevant()Returns whether this attribute is considered relevant.booleanisValuePresent()Checks whether this model object attribute has a non-empty value.static ModelObjectAttributeof(IModelObject modelObject, java.lang.String attributeName)Creates aModelObjectAttributefor the given model object and policy attribute.static ModelObjectAttributeof(IModelObject modelObject, PolicyAttribute policyAttribute)Creates aModelObjectAttributefor the given model object and policy attribute.ModelObjectAttributeremoveValue()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.ModelObjectAttributesetDefaultValue(java.lang.Object defaultValue)Sets the product configured default value of this attribute.ModelObjectAttributesetValueSet(org.faktorips.valueset.ValueSet<?> valueSet)Sets the product configured set of allowed values of this model object attribute.ObjectPropertytoObjectProperty()Returns anObjectPropertyfor this model object attribute.
-
-
-
Method Detail
-
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:
java.lang.IllegalArgumentException- if thePolicyAttributebelongs to aPolicyCmptTypetheIModelObjectis not an instance of
-
of
public static final ModelObjectAttribute of(@NonNull IModelObject modelObject, @NonNull java.lang.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
public IModelObject getModelObject()
-
getPolicyAttribute
public PolicyAttribute getPolicyAttribute()
-
getValue
public java.lang.Object getValue()
Returns the value of the this model object attribute.- Throws:
java.lang.IllegalArgumentException- if the attribute is not accessible for any reason- See Also:
PolicyAttribute.getValue(IModelObject)
-
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:
PolicyAttribute.isEmpty(IModelObject)
-
removeValue
public ModelObjectAttribute 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:
java.lang.IllegalArgumentException- if the model object attribute is not accessible for any reason.java.lang.UnsupportedOperationException- if invoked on aAttributeKind.CONSTANTattribute.- See Also:
PolicyAttribute.removeValue(IModelObject)
-
getValueSet
public org.faktorips.valueset.ValueSet<?> getValueSet()
Returns the set of values allowed for this model object attribute.- Throws:
java.lang.UnsupportedOperationException- if invoked on aAttributeKind.CONSTANTattribute.java.lang.IllegalStateException- if the method that should return a value set for this attribute has too many argumentsjava.lang.IllegalArgumentException- if the invocation of the method that should return a value set for this attribute fails for any reason- See Also:
PolicyAttribute.getValueSet(IModelObject)
-
setValueSet
public ModelObjectAttribute setValueSet(org.faktorips.valueset.ValueSet<?> valueSet)
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:
java.lang.UnsupportedOperationException- if invoked on aAttributeKind.CONSTANTattribute.java.lang.ClassCastException- if the type of value set does not match the property's configuration or the model object is noIConfigurableModelObject.java.lang.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.java.lang.IllegalArgumentException- if the invocation of the method that should set the value set for this attribute fails for any reason- See Also:
PolicyAttribute.setValueSet(IConfigurableModelObject, ValueSet)
-
getDefaultValue
public java.lang.Object 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:
java.lang.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.java.lang.IllegalArgumentException- if the invocation of the method that should get the default value for this attribute fails for any reasonjava.lang.ClassCastException- if the model object is noIConfigurableModelObject.- See Also:
PolicyAttribute.getDefaultValue(IModelObject)
-
setDefaultValue
public ModelObjectAttribute setDefaultValue(java.lang.Object defaultValue)
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:
java.lang.UnsupportedOperationException- if invoked on aAttributeKind.CONSTANTattribute.java.lang.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.java.lang.IllegalArgumentException- if the invocation of the method that should set the default value for this attribute fails for any reasonjava.lang.ClassCastException- if the model object is noIConfigurableModelObject.- See Also:
PolicyAttribute.setDefaultValue(IConfigurableModelObject, Object)
-
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
public ObjectProperty toObjectProperty()
Returns anObjectPropertyfor this model object attribute.
-
-