Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Ecore model creation with EOL
Ecore model creation with EOL [message #1017342] Mon, 11 March 2013 16:11 Go to next message
serhat gezgin is currently offline serhat gezginFriend
Messages: 242
Registered: January 2013
Location: Izmir
Senior Member
i'm trying to create ecore model which fits its metamodel (attached)

and i write this code but i cant add Eatribute to Eclass How can i done this any

suggestion ?

<project default="main">
	<target name="main">
		<epsilon.emf.loadModel name="ecore" modelfile="models/Ecore.ecore" metamodeluri="http://www.eclipse.org/emf/2002/Ecore" read="true" store="false" />
		<epsilon.emf.loadModel name="OO" modelFile="models/OOInstance.ecore" metamodelUri="OO" read="false" store="true" />
		<epsilon.eol>
			var m : new EPackage;
			m.name = "m";
			
			for (i in 1.to(5)){
				var package : EPackage = new EPackage;
				package.name = "p" + i;
				m.eSubpackages.add(package);
			
				for (j in 1.to(3)) {
					
					var class : EClass = new EClass;
					class.name = "c" + i + "" + j;
					class.abstract = false;
					package.eClassifiers.add(class);
				}
			
			}
			
			for (c in EClass.allInstances) {
				c.eSuperTypes.add(EClass.allInstances.random());
			}
			
			for (c in EClass.allInstances) {
				//How can i add EAttribute (String type) ?
				c.eAttributes.add();
			}
			
      		<model ref="OO" />
		</epsilon.eol>
	</target>
</project>


regards,

Serhat GEZGIN
  • Attachment: Ecore.ecore
    (Size: 31.05KB, Downloaded 45 times)
Re: Ecore model creation with EOL [message #1017386 is a reply to message #1017342] Mon, 11 March 2013 18:15 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 310
Registered: January 2010
Senior Member
Hi Serhat,

According to the EPackage Registry view, eAttributes is a derived feature, i.e. it's not really stored anywhere, but rather computed from the eStructuralFeatures feature. Most derived features are read-only, AFAIK, so this might be the case as well. You should add your EAttribute through eStructuralFeatures, like this:

var attr = new ECore!EAttribute;
// ...
eClass.eStructuralFeatures.add(attr);

Re: Ecore model creation with EOL [message #1017404 is a reply to message #1017386] Mon, 11 March 2013 19:02 Go to previous messageGo to next message
serhat gezgin is currently offline serhat gezginFriend
Messages: 242
Registered: January 2013
Location: Izmir
Senior Member
Oh thanks it's work now Smile. But EAttribute's eAttributeType is Derived Feature too.

So How can i create EString Type EAttribute. I cant recognize and confused ?


When i use this i always get error. Cause of derived Feature eAttributeType.

			for (c in EClass.allInstances) {
				var attr = new EAttribute;
				attr.eAttributeType := EDataType.all.random();
				c.eStructuralFeatures.add(attr);
			}


Clear words how can i create attribute of string type Smile

Regards,

[Updated on: Mon, 11 March 2013 20:34]

Report message to a moderator

Re: Ecore model creation with EOL [message #1017455 is a reply to message #1017404] Mon, 11 March 2013 21:29 Go to previous message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 310
Registered: January 2010
Senior Member
If you look for a compatible non-derived feature through the EPackage Registry, you'll see that there is just one option: eType (which stores an EClassifier).

You can also find this out by looking at the documentation for the EAttribute class: you'll see that there's "getEType" and "setEType" but there's only "getEAttributeType" (so "eAttributeType" is a read-only feature):

http://download.eclipse.org/modeling/emf/emf/javadoc/2.4.3/org/eclipse/emf/ecore/EAttribute.html

In fact, I would suggest that you create the .ecore metamodel that you want through other means (such as an .emf file) and look at it with a regular text editor. It should tell you exactly what you need to do Smile.
Previous Topic: Nodes with centred content don't work
Next Topic:Emfatic Annotations
Goto Forum:
  


Current Time: Thu Dec 18 16:39:02 GMT 2014

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

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