public class DefaultValidationMessageHandler extends Object implements ValidationMessageHandler
A default implementation of the ValidationMessageHandler
interface.
This class performs the following steps for obtaining a
ValidationMessage
object for a given key:
TransformerContext
contains a
property with the name of the given key. If this is the case, its value will
be used as error message. This makes it possible to override validation
messages directly in the builder script when the validator is defined.setAlternativeResourceGroups(String)
method a list of
resource groups can be set, which will be searched for resources with message
keys. So an application can define a custom resource group containing the
error messages it wants to override and specify it here.getDefaultResourceGroup()
method will be used. If not otherwise set,
the name defined by the DEFAULT_RESOURCE_GROUP_NAME
constant is
used. This is a resource group shipped with the framework, which contains
default validation messages in a couple of supported languages.
DefaultValidationMessageHandler
also determines the
ValidationMessageLevel
of the messages it returns. This is done by
evaluating the errorLevel
property of the passed in
TransformerContext
. If this property is set, its value is interpreted
as an enumeration literal defined by the ValidationMessageLevel
class. If the property is undefined, the default message level
ValidationMessageLevel.ERROR
is used. The advantage behind this
concept is that the message level is completely transparent for validators.
So they can produce messages of any level, provided that the
TransformerContext
is properly configured.
The ValidationMessage
objects returned by this object are
thread-safe; they can be concurrently accessed without requiring further
synchronization.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_RESOURCE_GROUP_NAME
Constant for the default resource group with validation messages.
|
static String |
PROP_MESSAGE_LEVEL
Constant for the name of the property that defines the
ValidationMessageLevel of the validation messages produced by
this object. |
Constructor and Description |
---|
DefaultValidationMessageHandler()
Creates a new instance of
DefaultValidationMessageHandler . |
Modifier and Type | Method and Description |
---|---|
String |
getAlternativeResourceGroups()
Returns the alternative resource groups.
|
String |
getDefaultResourceGroup()
Returns the name of the default resource group.
|
protected ValidationMessageLevel |
getMessageLevel(TransformerContext context)
Determines the
ValidationMessageLevel for the validation messages
produced by this object. |
ValidationMessage |
getValidationMessage(TransformerContext context,
String key,
Object... params)
Returns a validation message.
|
void |
setAlternativeResourceGroups(String alternativeResourceGroups)
Sets the alternative resource groups.
|
void |
setDefaultResourceGroup(String defaultResourceGroup)
Sets the name of the default resource group.
|
public static final String DEFAULT_RESOURCE_GROUP_NAME
public static final String PROP_MESSAGE_LEVEL
ValidationMessageLevel
of the validation messages produced by
this object. This property can be set in the properties of the
TransformerContext
.public DefaultValidationMessageHandler()
DefaultValidationMessageHandler
.public String getDefaultResourceGroup()
public void setDefaultResourceGroup(String defaultResourceGroup)
DEFAULT_RESOURCE_GROUP_NAME
constant is used.defaultResourceGroup
- the new default resource groupsetAlternativeResourceGroups(String)
public String getAlternativeResourceGroups()
public void setAlternativeResourceGroups(String alternativeResourceGroups)
"specialMessages, extendedMessages"
is passed in,
the text for a validation message will be searched first in the group
"specialMessages", then in the group
"extendedMessages", and finally in the default resource group.
It is possible to set the alternative resource groups to null.
Then only the default resource group will be searched.alternativeResourceGroups
- a comma separated list of alternative
resource groupspublic ValidationMessage getValidationMessage(TransformerContext context, String key, Object... params)
getValidationMessage
in interface ValidationMessageHandler
context
- the transformer context (must not be null)key
- the key of the message (must not be null)params
- additional parameters to be integrated into the messageIllegalArgumentException
- if the transformer context or the key
are nullprotected ValidationMessageLevel getMessageLevel(TransformerContext context)
ValidationMessageLevel
for the validation messages
produced by this object. This implementation tests whether in the
TransformerContext
the PROP_MESSAGE_LEVEL
property is
set. If so, its value is evaluated. Otherwise the default level
ValidationMessageLevel.ERROR
is returned.context
- the TransformerContext
ValidationMessageLevel
Copyright © 2016 The JGUIraffe Team. All rights reserved.