Extending Ecore XMI serialization [message #1219757] |
Thu, 05 December 2013 11:22  |
Eclipse User |
|
|
|
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 #1219947 is a reply to message #1219862] |
Sat, 07 December 2013 01:57   |
Eclipse User |
|
|
|
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
|
|
|
|
Re: Extending Ecore XMI serialization [message #1220023 is a reply to message #1220019] |
Mon, 09 December 2013 03:41  |
Eclipse User |
|
|
|
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,
|
|
|
Powered by
FUDForum. Page generated in 0.10893 seconds