|Re: prune & graft on model. [message #1212152 is a reply to message #1211292]
||Tue, 26 November 2013 19:48
| Ed Merks
Registered: July 2009
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
> 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.
Powered by FUDForum
. Page generated in 0.01624 seconds