Package org.faktorips.runtime.validation
Class DefaultGenericAttributeValidationConfiguration
java.lang.Object
org.faktorips.runtime.validation.DefaultGenericAttributeValidationConfiguration
- All Implemented Interfaces:
IGenericAttributeValidationConfiguration
public class DefaultGenericAttributeValidationConfiguration
extends Object
implements IGenericAttributeValidationConfiguration
Default implementation of
IGenericAttributeValidationConfiguration that uses a
Locale specific ResourceBundle to load messages.
Messages are created with one replacement parameter that is set to the attribute's localized
label and with a message code created from an error
specific
prefix("InvalidAttribute.Mandatory"/"InvalidAttribute.Irrelevant"/"InvalidAttribute.Invalid"),
the name of the policy type and the attribute name.
To add markers or other information to messages, you can override this class'
methods and use Message.Builder to modify the messages returned
from them.
An IMarker for missing required
information, that will be used in the default implementation of
createMessageForMissingMandatoryValue(PolicyAttribute, IModelObject, Class) can be
provided in the constructor.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringMessage code prefix indicating a missing value outside of an attribute's allowed value set.static final StringMessage code prefix indicating a value is set for an irrelevant attribute.static final StringMessage code prefix indicating a missing value for a mandatory attribute. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultGenericAttributeValidationConfiguration(Locale locale, IMarker requiredInformationMissingMarker) DefaultGenericAttributeValidationConfiguration(ResourceBundle messages, Locale locale) DefaultGenericAttributeValidationConfiguration(ResourceBundle messages, Locale locale, IMarker requiredInformationMissingMarker) -
Method Summary
Modifier and TypeMethodDescriptionprotected Message.BuilderbuilderForErrorMessage(PolicyAttribute policyAttribute, IModelObject modelObject, GenericRelevanceValidation.Error error, Class<? extends IModelObject> definingModelObjectClass, String message) Creates an error message builder with a message code created from the given prefix viacreateMsgCode(GenericRelevanceValidation.Error, PolicyAttribute, Class)and an invalid object property for the given attribute.protected MessagecreateErrorMessage(PolicyAttribute policyAttribute, IModelObject modelObject, GenericRelevanceValidation.Error error, Class<? extends IModelObject> definingModelObjectClass, String message) Creates an error message with a message code created from the given prefix viacreateMsgCode(GenericRelevanceValidation.Error, PolicyAttribute, Class)and an invalid object property for the given attribute.createMessageForMissingMandatoryValue(PolicyAttribute policyAttribute, IModelObject modelObject, Class<? extends IModelObject> definingModelObjectClass) Creates a message to indicate that the given attribute's value on the given model object is missing but the value set does not allow anullvalue.createMessageForValueNotInAllowedValueSet(PolicyAttribute policyAttribute, IModelObject modelObject, Class<? extends IModelObject> definingModelObjectClass) Creates a message to indicate that the given attribute's value on the given model object is not allowed by the value set.createMessageForValuePresentForIrrelevantAttribute(PolicyAttribute policyAttribute, IModelObject modelObject, Class<? extends IModelObject> definingModelObjectClass) Creates a message to indicate that the given attribute's value on the given model object is set but the value set does not allow a value.protected StringcreateMsgCode(GenericRelevanceValidation.Error error, PolicyAttribute policyAttribute, Class<? extends IModelObject> definingModelObjectClass) Creates a message code from the pattern <errorCode>.<definingModelObjectClassName>.<policyAttributeName>.protected StringFormats the Stringobtained from this configuration'sResourceBundlewith the given key using the replacement parameters.protected StringgetLabelFor(PolicyAttribute policyAttribute, IModelObject modelObject) Returns the label for the given attribute to be used in an error message.Returns theLocalethis configuration was created for.Returns theResourceBundlefor this configuration.Returns theIMarkerused tocreate a message for a missing mandatory value.booleanshouldValidate(PolicyAttribute policyAttribute, IModelObject modelObject) Decides whether the givenPolicyAttributeshould be validated for the givenIModelObject.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.faktorips.runtime.validation.IGenericAttributeValidationConfiguration
createMessageForValueNotInAllowedValueSet, getValueSet
-
Field Details
-
ERROR_MANDATORY_MSG_CODE_PREFIX
Message code prefix indicating a missing value for a mandatory attribute.- See Also:
-
ERROR_IRRELEVANT_MSG_CODE_PREFIX
Message code prefix indicating a value is set for an irrelevant attribute.- See Also:
-
ERROR_INVALID_MSG_CODE_PREFIX
Message code prefix indicating a missing value outside of an attribute's allowed value set.- See Also:
-
-
Constructor Details
-
DefaultGenericAttributeValidationConfiguration
-
DefaultGenericAttributeValidationConfiguration
-
DefaultGenericAttributeValidationConfiguration
-
DefaultGenericAttributeValidationConfiguration
public DefaultGenericAttributeValidationConfiguration(ResourceBundle messages, Locale locale, @CheckForNull IMarker requiredInformationMissingMarker)
-
-
Method Details
-
getLocale
Returns theLocalethis configuration was created for. -
getMessages
Returns theResourceBundlefor this configuration. -
getMissingMandatoryValueMarker
Returns theIMarkerused tocreate a message for a missing mandatory value. -
shouldValidate
Description copied from interface:IGenericAttributeValidationConfigurationDecides whether the givenPolicyAttributeshould be validated for the givenIModelObject.- Specified by:
shouldValidatein interfaceIGenericAttributeValidationConfiguration- Parameters:
policyAttribute- the model type reference for the validated attributemodelObject- the model object instance on which the attribute may be validated- Returns:
- whether validation for the given combination of
PolicyAttributeandIModelObjectshould run
-
createErrorMessage
protected Message createErrorMessage(PolicyAttribute policyAttribute, IModelObject modelObject, GenericRelevanceValidation.Error error, Class<? extends IModelObject> definingModelObjectClass, String message) Creates an error message with a message code created from the given prefix viacreateMsgCode(GenericRelevanceValidation.Error, PolicyAttribute, Class)and an invalid object property for the given attribute.- Implementation Requirements:
- calling
builderForErrorMessage(PolicyAttribute, IModelObject, org.faktorips.runtime.validation.GenericRelevanceValidation.Error, Class, String)is preferred if you want to adapt the message.
-
builderForErrorMessage
protected Message.Builder builderForErrorMessage(PolicyAttribute policyAttribute, IModelObject modelObject, GenericRelevanceValidation.Error error, Class<? extends IModelObject> definingModelObjectClass, String message) Creates an error message builder with a message code created from the given prefix viacreateMsgCode(GenericRelevanceValidation.Error, PolicyAttribute, Class)and an invalid object property for the given attribute. -
createMsgCode
protected String createMsgCode(GenericRelevanceValidation.Error error, PolicyAttribute policyAttribute, Class<? extends IModelObject> definingModelObjectClass) Creates a message code from the pattern <errorCode>.<definingModelObjectClassName>.<policyAttributeName>. -
format
Formats the Stringobtained from this configuration'sResourceBundlewith the given key using the replacement parameters.- Parameters:
msgKey- the key to find the format String from theResourceBundle.replacementParameters- the parameters to be passed toString.format(String, Object...)
-
getLabelFor
Returns the label for the given attribute to be used in an error message.- Implementation Requirements:
- Implementers may use the given model object to further qualify the field.
- Implementation Note:
- The default implementation uses the
attribute's labelin the locale provided to this configuration's constructor and returns it in double quotes. - Parameters:
policyAttribute- the model type reference for the validated attributemodelObject- the model object instance on which the attribute was validated
-
createMessageForMissingMandatoryValue
public Message createMessageForMissingMandatoryValue(PolicyAttribute policyAttribute, IModelObject modelObject, Class<? extends IModelObject> definingModelObjectClass) Description copied from interface:IGenericAttributeValidationConfigurationCreates a message to indicate that the given attribute's value on the given model object is missing but the value set does not allow anullvalue.- Specified by:
createMessageForMissingMandatoryValuein interfaceIGenericAttributeValidationConfiguration- Parameters:
policyAttribute- the model type reference for the validated attributemodelObject- the model object instance on which the attribute was validateddefiningModelObjectClass- the model object class where the generic validation is defined
-
createMessageForValuePresentForIrrelevantAttribute
public Message createMessageForValuePresentForIrrelevantAttribute(PolicyAttribute policyAttribute, IModelObject modelObject, Class<? extends IModelObject> definingModelObjectClass) Description copied from interface:IGenericAttributeValidationConfigurationCreates a message to indicate that the given attribute's value on the given model object is set but the value set does not allow a value.- Specified by:
createMessageForValuePresentForIrrelevantAttributein interfaceIGenericAttributeValidationConfiguration- Parameters:
policyAttribute- the model type reference for the validated attributemodelObject- the model object instance on which the attribute was validateddefiningModelObjectClass- the model object class where the generic validation is defined
-
createMessageForValueNotInAllowedValueSet
public Message createMessageForValueNotInAllowedValueSet(PolicyAttribute policyAttribute, IModelObject modelObject, Class<? extends IModelObject> definingModelObjectClass) Description copied from interface:IGenericAttributeValidationConfigurationCreates a message to indicate that the given attribute's value on the given model object is not allowed by the value set.- Specified by:
createMessageForValueNotInAllowedValueSetin interfaceIGenericAttributeValidationConfiguration- Parameters:
policyAttribute- the model type reference for the validated attributemodelObject- the model object instance on which the attribute was validateddefiningModelObjectClass- the model object class where the generic validation is defined
-