Package org.faktorips.runtime.validation
Class DefaultGenericAttributeValidationConfiguration
- java.lang.Object
-
- org.faktorips.runtime.validation.DefaultGenericAttributeValidationConfiguration
-
- All Implemented Interfaces:
IGenericAttributeValidationConfiguration
public class DefaultGenericAttributeValidationConfiguration extends java.lang.Object implements IGenericAttributeValidationConfiguration
Default implementation ofIGenericAttributeValidationConfigurationthat uses aLocalespecificResourceBundleto load messages.Messages are created with one replacement parameter that is set to the attribute's localized
labeland 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
markersor other information to messages, you can override this class' methods and useMessage.Builderto modify the messages returned from them.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringERROR_INVALID_MSG_CODE_PREFIXMessage code prefix indicating a missing value outside of an attribute's allowed value set.static java.lang.StringERROR_IRRELEVANT_MSG_CODE_PREFIXMessage code prefix indicating a value is set for an irrelevant attribute.static java.lang.StringERROR_MANDATORY_MSG_CODE_PREFIXMessage code prefix indicating a missing value for a mandatory attribute.
-
Constructor Summary
Constructors Constructor Description DefaultGenericAttributeValidationConfiguration(java.util.Locale locale)DefaultGenericAttributeValidationConfiguration(java.util.ResourceBundle messages, java.util.Locale locale)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected MessagecreateErrorMessage(PolicyAttribute policyAttribute, IModelObject modelObject, java.lang.String msgCodePrefix, java.lang.String message)Creates an error message with a message code created from the given prefix viacreateMsgCode(String, IModelObject, PolicyAttribute)and an invalid object property for the given attribute.MessagecreateMessageForMissingMandatoryValue(PolicyAttribute policyAttribute, IModelObject modelObject)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.MessagecreateMessageForValueNotInAllowedValueSet(PolicyAttribute policyAttribute, IModelObject modelObject)Creates a message to indicate that the given attribute's value on the given model object is not allowed by the value set.MessagecreateMessageForValuePresentForIrrelevantAttribute(PolicyAttribute policyAttribute, IModelObject modelObject)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 java.lang.StringcreateMsgCode(java.lang.String msgCodePrefix, IModelObject modelObject, PolicyAttribute policyAttribute)Creates a message code from the pattern <prefix>.<policyCmptTypeName>.<policyAttributeName>.protected java.lang.Stringformat(java.lang.String msgKey, java.lang.Object... replacementParameters)Formats the Stringobtained from this configuration'sResourceBundlewith the given key using the replacement parameters.protected java.lang.StringgetLabelFor(PolicyAttribute policyAttribute, IModelObject modelObject)Returns the label for the given attribute to be used in an error message.java.util.LocalegetLocale()Returns theLocalethis configuration was created for.java.util.ResourceBundlegetMessages()Returns theResourceBundlefor this configuration.booleanshouldValidate(PolicyAttribute policyAttribute, IModelObject modelObject)Decides whether the givenPolicyAttributeshould be validated for the givenIModelObject.
-
-
-
Field Detail
-
ERROR_MANDATORY_MSG_CODE_PREFIX
public static final java.lang.String ERROR_MANDATORY_MSG_CODE_PREFIX
Message code prefix indicating a missing value for a mandatory attribute.- See Also:
- Constant Field Values
-
ERROR_IRRELEVANT_MSG_CODE_PREFIX
public static final java.lang.String ERROR_IRRELEVANT_MSG_CODE_PREFIX
Message code prefix indicating a value is set for an irrelevant attribute.- See Also:
- Constant Field Values
-
ERROR_INVALID_MSG_CODE_PREFIX
public static final java.lang.String ERROR_INVALID_MSG_CODE_PREFIX
Message code prefix indicating a missing value outside of an attribute's allowed value set.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultGenericAttributeValidationConfiguration
public DefaultGenericAttributeValidationConfiguration(java.util.Locale locale)
-
DefaultGenericAttributeValidationConfiguration
public DefaultGenericAttributeValidationConfiguration(java.util.ResourceBundle messages, java.util.Locale locale)
-
-
Method Detail
-
getLocale
public java.util.Locale getLocale()
Returns theLocalethis configuration was created for.
-
getMessages
public java.util.ResourceBundle getMessages()
Returns theResourceBundlefor this configuration.
-
shouldValidate
public boolean shouldValidate(PolicyAttribute policyAttribute, IModelObject modelObject)
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, java.lang.String msgCodePrefix, java.lang.String message)
Creates an error message with a message code created from the given prefix viacreateMsgCode(String, IModelObject, PolicyAttribute)and an invalid object property for the given attribute.
-
createMsgCode
protected java.lang.String createMsgCode(java.lang.String msgCodePrefix, IModelObject modelObject, PolicyAttribute policyAttribute)Creates a message code from the pattern <prefix>.<policyCmptTypeName>.<policyAttributeName>.
-
format
protected java.lang.String format(java.lang.String msgKey, java.lang.Object... replacementParameters)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
protected java.lang.String getLabelFor(PolicyAttribute policyAttribute, IModelObject modelObject)
Returns the label for the given attribute to be used in an error message.- Parameters:
policyAttribute- the model type reference for the validated attributemodelObject- the model object instance on which the attribute was validated- 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.
-
createMessageForMissingMandatoryValue
public Message createMessageForMissingMandatoryValue(PolicyAttribute policyAttribute, IModelObject modelObject)
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 validated
-
createMessageForValuePresentForIrrelevantAttribute
public Message createMessageForValuePresentForIrrelevantAttribute(PolicyAttribute policyAttribute, IModelObject modelObject)
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 validated
-
createMessageForValueNotInAllowedValueSet
public Message createMessageForValueNotInAllowedValueSet(PolicyAttribute policyAttribute, IModelObject modelObject)
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 validated
-
-