Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Ecore data types for array, vector and list
Ecore data types for array, vector and list [message #1822499] Sun, 08 March 2020 18:17 Go to next message
yawar rasheed is currently offline yawar rasheedFriend
Messages: 8
Registered: September 2019
Junior Member
I have a question. what are the Ecore data types to declare a variable
as an array/ vector or list.
Re: Ecore data types for array, vector and list [message #1822501 is a reply to message #1822499] Sun, 08 March 2020 19:34 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7103
Registered: July 2009
Senior Member
Hi

The normal approach is to use the multiplicity of an EStructuralFeature to specify an upper bound, usually -1, and ordered/unique as appropriate.

If you really want DataTypes you can use the Bag/OrderedSet/Sequence/Set types from the OCL Standard Library. This may be appropriate/necessary if you need nested collections. The OCLinEcore editor makes these types more accessible.

Regards

Ed Willink

Re: Ecore data types for array, vector and list [message #1822506 is a reply to message #1822501] Mon, 09 March 2020 03:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31843
Registered: July 2009
Senior Member
In general you can create an EDataType that wraps any arbitrary Java class. E.g., EByteArray and EEList from Ecore.ecore:

https://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.ecore/model/Ecore.ecore#n389
https://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.ecore/model/Ecore.ecore#n421

If the data type is serializeable, you also need to implement the support for that in the generated factory, e.g.,

https://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/impl/EcoreFactoryImpl.java#n834

Arrays are not idea as data types because 1) .equals is object identity for the values and b) the values are mutable without notification.



Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Ecore data types for array, vector and list [message #1822727 is a reply to message #1822506] Thu, 12 March 2020 09:37 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7103
Registered: July 2009
Senior Member
Hi

Indeed. Java collections have Class equality semantics which is 'wrong'. The OCL collections although implemented by Java classes have the model-wise correct DataType equality semantics. Most of the time OCL and Java are so similar one wonders why bother with OCL rather than Java or Xbase. However when you get to the darker corners OCL is correct for modeling purposes.

All of these subtleties should be irrelevant, since for almost all purposes the standard Ecore multiplicities do everything that you need.

Regards

Ed Willink
Previous Topic:Generation of ID's
Next Topic:Move the NameSpace declaration to Inner element
Goto Forum:
  


Current Time: Wed Apr 21 10:12:58 GMT 2021

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

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

Back to the top