Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » prune & graft on model.
prune & graft on model. [message #1211292] Tue, 26 November 2013 11:10 Go to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
I am trying to implement prune/dup & graft on a rather complex model.

Saving to disk a subtree (keeping it or deleting it in the process) is not a problem.
Grafting it back in (possibly multiple) positions is somewhat straightforward also, BUT for a single issue:

Most of model EClasses are derived from a single EClass: Identifiable.
Identifiable (among other things) has two important EAttributes:
- id: a numerical id unique *for each EClass* (two Identifiable *can* have the same id, if they belong to two different descendents).
- eId: a string built as <EClass.getName()>(<id>) I use as EKey for EClass serialization/deserialization.

When I graft back a subtree I need to handle those fields ensuring:
1) id/eId of grafted nodes are unique and do not duplicate values already in the model.
2) Containing references should duplicate the content (changing their id/eId).
3) Non-Containing references should point to some valid instance; this leads to three cases:
a) reference points to an instance in the base model (a search for eId should be performed)
b) reference points to an instance in the subtree being grafted (reference should point to a "modified" instance)
c) reference points to an instance which was in the base model, but has since been deleted (reference should be deleted).

Notice all this should be done while loading, i.e.: while loader resolves references in the form "modelType="ModelType(10002)"; later it's too late!

Is there an easy way to achieve this?
What should I override to customize the load process?

NOTE: I am using EMF in "Standalone" mode and I'm using only "Model Code", no Edit, no Editor.
Re: prune &amp; graft on model. [message #1212152 is a reply to message #1211292] Tue, 26 November 2013 19:48 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Mauro,

Comments below.

On 26/11/2013 12:10 PM, Mauro Condarelli wrote:
> I am trying to implement prune/dup & graft on a rather complex model.
>
> Saving to disk a subtree (keeping it or deleting it in the process) is
> not a problem.
> Grafting it back in (possibly multiple) positions is somewhat
> straightforward also, BUT for a single issue:
>
> Most of model EClasses are derived from a single EClass: Identifiable.
> Identifiable (among other things) has two important EAttributes:
> - id: a numerical id unique *for each EClass* (two Identifiable *can*
> have the same id, if they belong to two different descendents).
> - eId: a string built as <EClass.getName()>(<id>) I use as EKey for
> EClass serialization/deserialization.
>
> When I graft back a subtree I need to handle those fields ensuring:
> 1) id/eId of grafted nodes are unique and do not duplicate values
> already in the model.
> 2) Containing references should duplicate the content (changing their
> id/eId).
> 3) Non-Containing references should point to some valid instance; this
> leads to three cases:
> a) reference points to an instance in the base model (a search for
> eId should be performed)
> b) reference points to an instance in the subtree being grafted
> (reference should point to a "modified" instance)
> c) reference points to an instance which was in the base model, but
> has since been deleted (reference should be deleted).
>
> Notice all this should be done while loading, i.e.: while loader
> resolves references in the form "modelType="ModelType(10002)"; later
> it's too late!
>
> Is there an easy way to achieve this?
> What should I override to customize the load process?
It's really not clear to me how this process is happening during
loading. It seems to me you must have a bunch of things saved somewhere
that you somehow assemble. No doubt EcoreUtil.Copier will come in
handy. You might call it just to copy the containment tree, analyze
the result to massage the ids for the context into which you want to
insert the copy, and do your reference analysis to populate the Copier
map so that during Copier.copyReferences the references are hooked up
the way you intend.
>
> NOTE: I am using EMF in "Standalone" mode and I'm using only "Model
> Code", no Edit, no Editor.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Generating sub-models from main model
Next Topic:Code Generation Error for Meta Model Element named Enumeration
Goto Forum:
  


Current Time: Thu Mar 28 13:31:55 GMT 2024

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

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

Back to the top