public interface Constraint<T> extends JavaBeanVersion
The constraint must be declared under the element
xs:annotation/xs:appinfo/osd:otherFacets
:
where<osd:constraint class="com.foo.MyConstraint" />
com.foo.MyConstraint
is
the fully qualified name of the class implementing this interface.
It is also possible to set additional JavaBean properties:
where<osd:constraint class="com.foo.MyConstraint"> <param1>...</param1> <param2>...</param2> </osd:constraint>
param1
and param2
are JavaBean properties of the specified class.
For more information, see the JavaBean specification.
setParam1(...)
and
setParam2(...)
);setup(ConstraintContext)
is called for the new instance.JavaBeanVersion.getBeanVersion()
is called for the new instance for checking if its implementation
has been modified since the last time the data model has been compiled. That is, since validation reports are
persisted into EBX® repository it is important to update the version to indicate
that this constraint has been modified and then must be revalidated during the next explicit
validation of the container dataset or table.
checkOccurrence(Object, ValueContextForValidation)
is called each time an associated element or attribute has to be validated.
Modifier and Type | Method and Description |
---|---|
void |
checkOccurrence(T aValue,
ValueContextForValidation aValidationContext)
Checks the specified value, and adds an
error message if invalid.
|
void |
setup(ConstraintContext aContext)
Checks and prepares this instance if called while the data model is being loaded.
|
String |
toUserDocumentation(Locale userLocale,
ValueContext aContext)
Returns the end-user documentation for this constraint.
|
getBeanVersion
void checkOccurrence(T aValue, ValueContextForValidation aValidationContext) throws InvalidSchemaException
The value passed as an argument by the container is a type occurrence. This means that if
the associated node is a simple type with an aggregated list declaration (that is,
maxOccurs > 1
),
this method is called for each occurrence of the list.
This value is never null
. If under certain circumstances, a check on a null
value is
necessary,
then the interface ConstraintOnNull
should be used.
If this constraint is attached to a table with N records, a full validation will call this method N times.
To avoid re-validating this constraint on each request for updating
the validation report, it is recommended to declare dependencies
.
For a table with many records, it may be necessary to optimize
the implementation. A good solution may be to implement the interface
ConstraintOnTable
instead of this interface.
See also performance and tuning.
For a single instance of this interface, this method may be called concurrently by several threads.
InvalidSchemaException
- if a dynamic condition in the data model prevents the execution of this method.void setup(ConstraintContext aContext)
This method must also declare any dependencies of the constraint so that validation is notified when a value is updated.
String toUserDocumentation(Locale userLocale, ValueContext aContext) throws InvalidSchemaException
This method returns null
if the specified locale is not handled by
the current implementation. The container tries several locales
when handling a partial internationalization of this method's implementation and/or
a mismatch between the locales declared by the associated module and the locales supported
by EBX®. In such cases, locales are tried in the following order:
Session.getLocaleForSchemaNode(SchemaNode)
);module.xml
;For a single instance of this interface, this method may be called concurrently by several threads.
InvalidSchemaException
- if a data model's dynamic condition prevents the execution of this method.SchemaFacet.getDocumentation(Locale, ValueContext)