Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Constraining Cardinality in EMF(How does one constrain EMF collections?)
Constraining Cardinality in EMF [message #1738437] Tue, 19 July 2016 20:23 Go to next message
Geoffry Roberts is currently offline Geoffry RobertsFriend
Messages: 52
Registered: July 2016
Member
All,

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. I need to set limits on EMF lists to 1..* or 1..3 or 2..5. Setting bounds in ecore doesn't do much.

Is there a way?

Thanks
Re: Constraining Cardinality in EMF [message #1738556 is a reply to message #1738437] Wed, 20 July 2016 20:09 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It depends what you mean by enforce.

Ecore allows you to specify cardinalities.

If your system is well-behaved the cardinalities will be observed and
you only need a little intermittent validation that EMF can do.

If you want to validate at the point of mis-assignment you will need to
overload the getXXX methods to define a checking list.

Regards

Ed Willink


On 20/07/2016 20:12, Geoffry Roberts wrote:
> All,
> 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. I need to set limits on EMF lists to 1..*
> or 1..3 or 2..5. Setting bounds in ecore doesn't do much.
>
> Is there a way?
>
> Thanks



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Re: Constraining Cardinality in EMF [message #1738561 is a reply to message #1738437] Wed, 20 July 2016 20:59 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Geoffry,

Comments below.


On 20.07.2016 21:12, Geoffry Roberts wrote:
> All,
> I am generating EMF dynamically and I need to enforce cardinality in
> the generated model. How is this done?
Diagnostician.INSTANCE.validate:
org.eclipse.emf.ecore.util.Diagnostician.validate(EObject)
> I gather from what I have read so far one must use validations.
Yes.
> 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
org.eclipse.emf.ecore.util.EObjectValidator.validate_MultiplicityConforms(EObject,
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
well-formed.

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.
>
> Thanks


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Resolve eProxy with custom URI
Next Topic:Skipping resolution error when loading
Goto Forum:
  


Current Time: Sat Apr 27 05:24:26 GMT 2024

Powered by FUDForum. Page generated in 0.02666 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top