Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Extending Ecore XMI serialization
Extending Ecore XMI serialization [message #1219757] Thu, 05 December 2013 16:22 Go to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
I would like to extend the XMI serialization for EReference, normally you get following for an EReference in ecore model
<eStructuralFeatures xsi:type="ecore:EReference" name="name" upperBound="-1" eType="//type" containment="true"/>

1 - i would like to add extra attribute like id="2345235"..
2 - how to change the tag name "eStructrualFeature" to "myEStructualFeature"

any clue?

cheers,
Re: Extending Ecore XMI serialization [message #1219772 is a reply to message #1219757] Thu, 05 December 2013 17:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
I'm confused, you want to change how *.ecore itself is serialized?

On 05/12/2013 5:22 PM, ModelGeek Mising name wrote:
> I would like to extend the XMI serialization for EReference, normally
> you get following for an EReference in ecore model
> <eStructuralFeatures xsi:type="ecore:EReference" name="name"
> upperBound="-1" eType="//type" containment="true"/>
>
> 1 - i would like to add extra attribute like id="2345235"..
> 2 - how to change the tag name "eStructrualFeature" to
> "myEStructualFeature"
>
> any clue?
>
> cheers,


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Extending Ecore XMI serialization [message #1219835 is a reply to message #1219772] Fri, 06 December 2013 08:30 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member

I want to extend EReference and want to introduce new properties in the implementation and newly added properties should become part od XMI serialization. normally you get following for an EReference in ecore model
<eStructuralFeatures xsi:type="ecore:EReference" name="name" upperBound="-1" eType="//type" containment="true"/>

I want to new attribute to the tag which will show the state of the newly added property

<eStructuralFeatures xsi:type="ecore:CustomizedEReference" name="name" upperBound="-1" eType="//type" containment="true" newlyaddedProperty="somevalue"/>

Second part of my question was who to rename the whole tag

<CustomizedeStructuralFeatures xsi:type="ecore:CustomizedEReference" name="name" upperBound="-1" eType="//type" containment="true" newlyaddedProperty="somevalue"/>

hope i explained it better this time.

Cheers,
Re: Extending Ecore XMI serialization [message #1219836 is a reply to message #1219835] Fri, 06 December 2013 08:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Comments below.

On 06/12/2013 9:30 AM, ModelGeek Mising name wrote:
>
> I want to extend EReference and want to introduce new properties in
> the implementation and newly added properties should become part od
> XMI serialization.
That should happen by itself, but I think extending Ecore is a very bad
idea. Ecore has support for EAnnotations and you're generally better
"extending" Ecore by annotating it not by subclassing it.
> normally you get following for an EReference in ecore model
> <eStructuralFeatures xsi:type="ecore:EReference" name="name"
> upperBound="-1" eType="//type" containment="true"/>
Yes, because the actual class of the object in eStructuralFeatures is
EReference. If it's something derived from that, that class name will
appear instead.
>
> I want to new attribute to the tag which will show the state of the
> newly added property
That sounds like something you could do with an EAnnotation.
>
> <eStructuralFeatures xsi:type="ecore:CustomizedEReference" name="name"
> upperBound="-1" eType="//type" containment="true"
> newlyaddedProperty="somevalue"/>
>
> Second part of my question was who to rename the whole tag
> <CustomizedeStructuralFeatures xsi:type="ecore:CustomizedEReference"
> name="name" upperBound="-1" eType="//type" containment="true"
> newlyaddedProperty="somevalue"/>
That doesn't make sense. That's not the name of a feature in an EClass.
>
> hope i explained it better this time.
I think you're approach is not a good one. No tool will know about your
extensions, e.g., the generator won't know about them. Try to get by
with annotations.
>
> Cheers,
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Extending Ecore XMI serialization [message #1219862 is a reply to message #1219836] Fri, 06 December 2013 10:29 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
May be i am not explaining it well.
I have written an interface extending from ERference and have added new methods.

public interface EReferenceExt extends EReference {
public int getProperty();
}

public class EReferenceImplExt extends EReferenceImpl implements EReferenceExt {
protected int poperty = 1;

public int getProperty() {
return poperty;
}

}

Now i try to create ecore model programmatically:
EPackage pack = EcoreFactory.eINSTANCE.createEPackage();
pack.setName("pack");
pack.setNsURI("http://www.eclipse.org/emf/pack/person");

EClass person = EcoreFactory.eINSTANCE.createEClass();
person.setName("Person");
pack.getEClassifiers().add(person);

EAttribute name = EcoreFactory.eINSTANCE.createEAttribute();
name.setName("name");
name.setEType(EcorePackage.Literals.ESTRING);
person.getEStructuralFeatures().add(name);

EReference children = new EReferenceImplExt();
children.setName("children");
children.setEType(person);
children.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY);
children.setContainment(true);
children.setResolveProxies(true);

person.getEStructuralFeatures().add(children);

EReference spouse = new EReferenceImplExt();
spouse.setName("spouse");
spouse.setEType(person);
spouse.setContainment(true);
spouse.setResolveProxies(true);
person.getEStructuralFeatures().add(spouse);

URI uri1 = URI.createFileURI("c:\\testP.ecore");
ResourceSet resourceSet = new ResourceSetImpl();
//resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());

Resource resource = resourceSet.createResource(uri1);
resource.getContents().add(pack);

try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


Now when i see the ecore file i see

<eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
eType="#//Person" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="spouse" eType="#//Person"
containment="true"/>

it does not say anything about newadded property in EReferenceExt.... if i want to load the ecore model programmatically from generated ecore file, will it give me the instance of EReference or EReferenceExt? i want to get object of EReferenceExt.

do you have any clue?

thanks for your assistance

Cheers

[Updated on: Fri, 06 December 2013 10:32]

Report message to a moderator

Re: Extending Ecore XMI serialization [message #1219947 is a reply to message #1219862] Sat, 07 December 2013 06:57 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Comments below.

On 06/12/2013 11:29 AM, ModelGeek Mising name wrote:
> May be i am explaining it well. I have written an interface extending
> from ERference and have added new methods.
> public interface EReferenceExt extends EReference {
> public int getProperty();
> }
That seems like a bad idea.
>
> public class EReferenceImplExt extends EReferenceImpl implements
> EReferenceExt {
> protected int poperty = 1;
>
> public int getProperty() {
> return poperty;
> }
>
> }
>
> Now i try to create ecore model programmatically:
> EPackage pack = EcoreFactory.eINSTANCE.createEPackage();
> pack.setName("pack");
> pack.setNsURI("http://www.eclipse.org/emf/pack/person");
> EClass person = EcoreFactory.eINSTANCE.createEClass();
> person.setName("Person");
> pack.getEClassifiers().add(person);
>
> EAttribute name = EcoreFactory.eINSTANCE.createEAttribute();
> name.setName("name");
> name.setEType(EcorePackage.Literals.ESTRING);
> person.getEStructuralFeatures().add(name);
> EReference children = new EReferenceImplExt();
> children.setName("children");
> children.setEType(person);
> children.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY);
> children.setContainment(true);
> children.setResolveProxies(true);
> //children.setPeriroity(2);
> person.getEStructuralFeatures().add(children);
> EReference spouse = new EReferenceImplExt();
If you have an extension you ought to be using the factory for that
extended model to create the extension but I guess the sense that you
have no such model so that's not going to work at all because
spouse.eClass() is going to return just the EClass for EReference...
> spouse.setName("spouse");
> spouse.setEType(person);
> spouse.setContainment(true);
> spouse.setResolveProxies(true);
> person.getEStructuralFeatures().add(spouse);
>
> URI uri1 = URI.createFileURI("c:\\testP.ecore");
> ResourceSet resourceSet = new ResourceSetImpl();
> //resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore",
> new EcoreResourceFactoryImpl());
>
> Resource resource = resourceSet.createResource(uri1);
> resource.getContents().add(pack); try {
> resource.save(Collections.EMPTY_MAP);
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
>
> Now when i see the ecore file i see
> <eStructuralFeatures xsi:type="ecore:EReference" name="children"
> upperBound="-1"
> eType="#//Person" containment="true"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="spouse"
> eType="#//Person"
> containment="true"/>
Well yes, if reflectively it looks like an EReference that what will be
serialized and if reflectively there is no "property" EAttribute it
won't be serialized either.
>
> it does not say anything about newadded property in EReferenceExt....
Because apparently you've not modeled an extension, you've just written
some Java code and by EMF reflection, that's completely invisible.
> if i want to load the ecore model programmatically from generated
> ecore file, will it give me the instance of EReference or
> EReferenceExt? i want to get object of EReferenceExt.
>
> do you have any clue?
Again, it's a bad idea, but if you feel compelled to ignore advice, you
need model your extension, not just hand write some Java code.
>
> Cheers


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Extending Ecore XMI serialization [message #1220019 is a reply to message #1219947] Mon, 09 December 2013 08:26 Go to previous messageGo to next message
ModelGeek Mising name is currently offline ModelGeek Mising nameFriend
Messages: 550
Registered: June 2011
Senior Member
Is there any example/tutorial for modeling the extension?

Cheers,
Re: Extending Ecore XMI serialization [message #1220023 is a reply to message #1220019] Mon, 09 December 2013 08:41 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Don't do it. You'll just keep asking more questions and you discover
the problems of extending Ecore itself, so just use annotations.

On 09/12/2013 9:26 AM, ModelGeek Mising name wrote:
> Is there any example/tutorial for modeling the extension?
>
> Cheers,


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Undo/Redo Actions Disabled
Next Topic:eclipse drag and drop like gui builder
Goto Forum:
  


Current Time: Tue Apr 23 12:25:15 GMT 2024

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

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

Back to the top