Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Forbid to set both Attributes
Forbid to set both Attributes [message #1743659] Sun, 18 September 2016 12:27 Go to next message
Xi Ng is currently offline Xi NgFriend
Messages: 26
Registered: June 2016
Junior Member
Hello,

I would like to model the following situation:

An Element has an Enum Attribute "Name" and a String Attribute "Custom Name"
The user can set any of these two attributes, but not both.

Then the same Element has a Double and a Boolean Attribute. The user can set any of these two attributes, but not both.

Is there an elegant way, how to model this in EMF - or do I have to get into code writing? Or should this not even be a matter of EMF, so I should implement this function better in Sirius?

Does anybody experienced, have advice regarding this?

Thank you in advance
Xing

[Updated on: Sun, 18 September 2016 12:28]

Report message to a moderator

Re: Forbid to set both Attributes [message #1743691 is a reply to message #1743659] Mon, 19 September 2016 05:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
The things you describe can only be implemented with constraints. You will have to write such logic yourself. You could Google "EMF Constraints" to see other ways to express the logic, e.g., using OCL or using the extended validation framework. I'm not sure how Sirius handles such constraints, i.e., does it prevent the user from doing it, or does it just show an error when they do it...

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Forbid to set both Attributes [message #1743714 is a reply to message #1743691] Mon, 19 September 2016 08:01 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Yes. Once you exceed the limitations of the cherry-picked graphical/modeled artefacts you need code to express more arbitrary constraints.

EMF provides support for manual realization of the constraints in Java, but the required EAnnotations are a bit subtle.

The extended validation framework was an early attempt at automation that you can use if you are an enthusiast for XML programming.

OCLinEcore automates the EAnnotations enabling you to express the constraints in a compact specification language: OCL. Optionally you may request that the standard EMF genmodel autogenerate Java corresponding to the OCL avoiding the overheads of an OCL interpreter when your constraints execute. Follow the OCLinEcore and associated code generator tutorials.

I presume that Xcore also supports generating the constraints using Xbase as its language.

Regards

Ed Willink
Re: Forbid to set both Attributes [message #1743749 is a reply to message #1743714] Mon, 19 September 2016 12:46 Go to previous messageGo to next message
Xi Ng is currently offline Xi NgFriend
Messages: 26
Registered: June 2016
Junior Member
Hello,

thank you very much for your suggestions, I will take a closer look at the constraints with EAnnotations and OCL.
Thank you!

Xing
Re: Forbid to set both Attributes [message #1743838 is a reply to message #1743749] Tue, 20 September 2016 08:17 Go to previous messageGo to next message
Xi Ng is currently offline Xi NgFriend
Messages: 26
Registered: June 2016
Junior Member
Hello,

I tried now to model my problem, with just introducing one value (so no double, no boolean).
Then I tried to model the data type of this value as a UNION TYPE, which should then contain Double and Boolean.
I tried to model it exaclty as it is described in the official EMF Book, Second Edition.

EClass
name = Indicator
> EAttribute value : IndicatorValueType

EData Type
instance type name = java.lang.Object
name= IndicatorValueType

> EAnnotation
> source = http:///org/eclipse/emf/ecore/util/ExtendedMetaData

>> Details Entry
>> key = name, value = IndicatorValueType
>> key = memberTypes, value = Boolean Double

Now in the book, it also says, that when I have a EJavaObject, the serializable is false. So I assumed, I have to switched it from true to false. But then Eclipse tells me to also change my attribute's transiable to true.

But it does not work, neither with changing serializable/transiable, nor without.

Did I completely misunderstand the idea of a Union Type?

Xing
Re: Forbid to set both Attributes [message #1743848 is a reply to message #1743838] Tue, 20 September 2016 08:47 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

"I tried to model it exaclty". Perhaps, but without a repro and since it doesn't work, probably not.

"UNION TYPE". I have been using EMF for rather a long time and have never come across UNION TYPE. I assume it is one of the nasty areas necessary to support the anarchic 'modeling' of XSD. I really do not recommend it. Use the Sample Ecore Editor or some successor as your metamodel editor and don't use complexities until you are an EMF expert.

If you really want a 'union' type, then perhaps an EDataType for java.lang.Number will help. It's what I use in GIT\org.eclipse.ocl\plugins\org.eclipse.ocl.pivot\model\Pivot.ecore for Real and Integer where I need BigDecimal / Integer polymorphism.

Regards

Ed Willink
Re: Forbid to set both Attributes [message #1743870 is a reply to message #1743848] Tue, 20 September 2016 10:18 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
You'll need it to be serializeable, so don't set that to false otherwise you can only use it on transient attribute, and of course then it won't serialize, which I assume defeats the purpose.

One thing that looks wrong is "Boolean Double". Such references will expect to find an EDataType with that name in the same Ecore model, but I doubt you have that. To refer to a data type in another package, you must prefix it with the nsURI of that package, e.g.,
http://www.eclipse.org/emf/2003/XMLType#boolean
.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Setting several primitive values for structural feature
Next Topic:Delete
Goto Forum:
  


Current Time: Thu Apr 18 22:12:00 GMT 2024

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

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

Back to the top