The annotations/xml allow to define static constraint definitions.
In some cases, that would be useful to be able to define per instance constraints at runtime. For example, in a SaaS scenario, we often have customized constraint definitions for differents customers that are defined somewhere in the database or in specific xml files.
I've not seen something like this in the current specification.
Implementing such feature would probably just need an API to create or modify a BeanDescriptor and something to specify the BeanDescriptor in the class.
Example use :
public class SomeEntity {
@BeanDescriptor
public getInstanceBeanDescriptor(BeanDescriptor classDescriptor) {
if (isCustomized)
return new CustomizedBeanDescriptorForCustomer(classDescriptor, this);
return classDescriptor;
}
}
|