Skip to main content



      Home
Home » Modeling » Ecore Tools » How to add child nodes using the reflective API of EMF?(How to add child nodes using the reflective API of EMF?)
How to add child nodes using the reflective API of EMF? [message #630719] Mon, 04 October 2010 12:51
Eclipse UserFriend
See
http:// www.eclipse.org/forums/index.php?t=msg&th=197805&sta rt=0&S=9d4b40b4b637cfad75d0340c23461ca4
for the reply I got and progress I made.

Thanks!
Adrian

[I had originally posted this over at Model->UML but Ecore Tools seems to be the right place to ask.]

Greetings!

I am able to add nodes to an EMF model generated from XSD:

EPackage ep = poClass.getEPackage();
EClass ctNew = (EClass) ep.getEClassifier("ChangeType");
EObject ctObject = ep.getEFactoryInstance().create(ctNew);
ctObject.eSet(ctObject.eClass().getEStructuralFeature("comment "), "...");

I am also able to add a node to a single-valued feature:
EClass cltNew = (EClass) ep.getEClassifier("ChangeLogType");
clt = ep.getEFactoryInstance().create(cltNew);
po.eSet(poClass.getEStructuralFeature("changeLog"), clt);

I can also obtain the list of change entries under the many-values change node:

EList<EObject> changes = clt.eClass().getEStructuralFeature("change").eContents();

Here is my problem:

changes.add(ctObject);

gives

Caused by: java.lang.UnsupportedOperationException
at org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImp l.add(EContentsEList.java:779)
at java.util.AbstractSequentialList.add(Unknown Source)
at java.util.AbstractList.add(Unknown Source)

which I had planned to use as follows:

clt.eSet(clt.eClass().getEStructuralFeature("changeType"), changes);

Is there a way to add child nodes using the reflective API of EMF?

I need to avoid using specific types of the generated model in this section of code, since this code should be usable by multiple separate generated models.

Thanks in advance for any advice.

Adrian


[Updated on: Wed, 06 October 2010 09:25] by Moderator

Previous Topic:ecorediag and ecore mismatch
Next Topic:Top xml element in ecore
Goto Forum:
  


Current Time: Sat Jul 19 21:04:51 EDT 2025

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

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

Back to the top