|Re: Constraining Cardinality in EMF [message #1738561 is a reply to message #1738437]
||Wed, 20 July 2016 20:59
| Ed Merks
Registered: July 2009
On 20.07.2016 21:12, Geoffry Roberts wrote:
> I am generating EMF dynamically and I need to enforce cardinality in
> the generated model. How is this done?
> I gather from what I have read so far one must use validations.
> But it would appear I can't generate validation code.
Unless you have specialized constraints, you don't need a specialized
validator because the generic validator will enforce the constraints of
the Ecore model itself.
> I need to set limits on EMF lists to 1..* or 1..3 or 2..5. Setting
> bounds in ecore doesn't do much.
Those are checked by
EStructuralFeature, DiagnosticChain, Map<Object, Object>).
> Is there a way?
Such checks are, as you already realize, check by invoking the
validator. They're not "hard" constraints that are simply prevent.
E.g., you might add to a list, such that there are to many element, but
then you immediately remove one so it's okay again. If the multiplicity
constraint is 2..2, of course a new instance will have 0 elements in the
list, so you have to be able to add some, and maybe too many before it's
So don't expect a generated validator unless you need to write
constraint logic yourself, and don't expect that all constraints are
enforced at all times such that only well-formed instances can exists;
that's just not possible.
Professional Support: https://www.macromodeling.com/
Powered by FUDForum
. Page generated in 0.02113 seconds