Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Is it possible to add elements to an existing model ?
[ATL] Is it possible to add elements to an existing model ? [message #57482] Sat, 11 August 2007 10:41 Go to next message
Guillaume Gauffre is currently offline Guillaume GauffreFriend
Messages: 65
Registered: July 2009
Member
Hi,

I wish to add elements of a model into another which is a kind of
repository. To do that,I made a transformation which creates the target
model elements I need, and programmatically, I launch my transformation
using as target model the existing model instead of a new model
(depending on the model already exists or not) !

######## transformation header #######
-- @atlcompiler atl2004
module saveil;
create OUT : asurIL refining IN : asurIL;


######## my code ########
ASMModel outputModel = null;
ASMModel inputModel =
emfamh.loadModel("IN" ,asurilMM_EMF,domainModelPath.toFile().toURI().toURL().openS tream());
if (domainProject.exists(new Path(".components"))) {
outputModel =
emfamh.loadModel("OUT",asurilMM_EMF,domainProject.getFile( ".components").getContents());
} else {
outputModel = emfamh.newModel("OUT", asurilMM_EMF);
}
Map models = new HashMap();
models.put(asurilMM_EMF.getName(), asurilMM_EMF); // input metamodel
models.put(asurilMM_EMF.getName(), asurilMM_EMF); // output metamodel
models.put("IN", inputModel); // input model
models.put("OUT", outputModel); // output model

AtlLauncher.getDefault().launch(saveilURL,Collections.EMPTY_ MAP,models,Collections.EMPTY_MAP);
emfamh.saveModel(outputModel,".components", domainProject);
########################

I try to use the refining mode for this transformation.
It works fine if the target model is new but it generates an exception
if I use the existing model :

"java.lang.IllegalArgumentException: argument type mismatch"

NativeOperation public static void
org.atl.engine.vm.nativelib.ASMTransientLink.addTargetElemen t(org.atl.engine.vm.StackFrame,org.atl..engine.vm.nativelib. ASMTransientLink,org.atl.engine.vm.nativelib.ASMString,org.a tl.engine.vm.nativelib.ASMOclAny)
args = [TransientLink {rule = 'MODEL', sourceElements = {input =
IN!<unnamed>}, targetElements = {}, variables = {}}, TransientLink {rule
= 'MODEL', sourceElements = {input = IN!<unnamed>}, targetElements = {},
variables = {}}, 'output']

Refining mode or normal mode, the error is the same !
Is it possible to do what I want ?
Maybe, using 2 source models, one to refine with the content of the
second ? How to do that ?

Many thanks !

Guillaume
Re: [ATL] Is it possible to add elements to an existing model ? [message #57509 is a reply to message #57482] Sat, 11 August 2007 11:07 Go to previous messageGo to next message
Guillaume Gauffre is currently offline Guillaume GauffreFriend
Messages: 65
Registered: July 2009
Member
Sorry, I think I have found the solution be using 2 input models,
creating a target model which merge the 2 input

Guillaume

Guillaume Gauffre a écrit :
> Hi,
>
> I wish to add elements of a model into another which is a kind of
> repository. To do that,I made a transformation which creates the target
> model elements I need, and programmatically, I launch my transformation
> using as target model the existing model instead of a new model
> (depending on the model already exists or not) !
>
> ######## transformation header #######
> -- @atlcompiler atl2004
> module saveil;
> create OUT : asurIL refining IN : asurIL;
>
>
> ######## my code ########
> ASMModel outputModel = null;
> ASMModel inputModel =
> emfamh.loadModel("IN" ,asurilMM_EMF,domainModelPath.toFile().toURI().toURL().openS tream());
>
> if (domainProject.exists(new Path(".components"))) {
> outputModel =
> emfamh.loadModel("OUT",asurilMM_EMF,domainProject.getFile( ".components").getContents());
>
> } else {
> outputModel = emfamh.newModel("OUT", asurilMM_EMF);
> }
> Map models = new HashMap();
> models.put(asurilMM_EMF.getName(), asurilMM_EMF); // input metamodel
> models.put(asurilMM_EMF.getName(), asurilMM_EMF); // output metamodel
> models.put("IN", inputModel); // input model
> models.put("OUT", outputModel); // output model
>
> AtlLauncher.getDefault().launch(saveilURL,Collections.EMPTY_ MAP,models,Collections.EMPTY_MAP);
>
> emfamh.saveModel(outputModel,".components", domainProject);
> ########################
>
> I try to use the refining mode for this transformation.
> It works fine if the target model is new but it generates an exception
> if I use the existing model :
>
> "java.lang.IllegalArgumentException: argument type mismatch"
>
> NativeOperation public static void
> org.atl.engine.vm.nativelib.ASMTransientLink.addTargetElemen t(org.atl.engine.vm.StackFrame,org.atl..engine.vm.nativelib. ASMTransientLink,org.atl.engine.vm.nativelib.ASMString,org.a tl.engine.vm.nativelib.ASMOclAny)
>
> args = [TransientLink {rule = 'MODEL', sourceElements = {input =
> IN!<unnamed>}, targetElements = {}, variables = {}}, TransientLink {rule
> = 'MODEL', sourceElements = {input = IN!<unnamed>}, targetElements = {},
> variables = {}}, 'output']
>
> Refining mode or normal mode, the error is the same !
> Is it possible to do what I want ?
> Maybe, using 2 source models, one to refine with the content of the
> second ? How to do that ?
>
> Many thanks !
>
> Guillaume
Re: [ATL] Is it possible to add elements to an existing model ? [message #58069 is a reply to message #57509] Fri, 17 August 2007 08:46 Go to previous message
Guillaume Gauffre is currently offline Guillaume GauffreFriend
Messages: 65
Registered: July 2009
Member
I finally get what I want, a model 'MERGE' which merge the content of a
repository 'COMP' + content of a new model 'IN' !
It works fine launching the transformation using Eclipse Run Dialog
But its behavior changes when launching it programmatically !

The transformation is first copying content of repository model into the
output model by using an entrypoint. All components are copying, and
other matched rules will put into the output model, new elements using
some constraints !

If you look to the entrypoint below, I have put some debug information
about the components I want to copy into the output model :
there is 2 strange things
- launching programmatically, the number of components inserted in the
merge model is 0 (thisModule.mergeModel.components->size()) so, in that
case, the assignment 'model.components <- oldmodel.components' doesn't
seem to work !
- using the eclipse running dialog, the set of components get with
'asurIL!Component.allInstancesFrom('COMP')' is empty, and using the
helper compFromRep, it works fine !

Here is the two strange things I don't understand. I insert below the
launching java code I used, maybe I do something wrong here.

Thank you for your interest

Guillaume

############################################################ ####
module saveil;
create MERGE : asurIL from COMP : asurIL, IN : asurIL;

helper def: mergeModel : asurIL!ASURIL_Model = OclUndefined;

helper def : compFromRep : Set(asurIL!Component) =
asurIL!Component.allInstancesFrom('COMP');

helper context asurIL!Component def : isInstanceOf(name : String) :
Boolean = asurIL!Component.allInstancesFrom(name)->exists(e|e=self);

helper context asurIL!Component def : notDefined() : Boolean =
thisModule.compFromRep->forAll(e|e.Name<>self.Name);

entrypoint rule COPY() {
using {
oldmodel : asurIL!ASURIL_Model =
asurIL!ASURIL_Model.allInstancesFrom('COMP')->asSequence()- >first();
}
to
model : asurIL!ASURIL_Model (
Name <- 'Components Repository'
)
do {
if (not oldmodel.oclIsUndefined()) {
oldmodel.components->size().debug('old model exists');
model.components <- oldmodel.components;
}
thisModule.mergeModel <- model;
thisModule.compFromRep->size().debug('nb comp in repository');
thisModule.mergeModel.components->size().debug('nb comp in merge model');
thisModule.compFromRep.debug('components in repository');
asurIL!Component.allInstancesFrom('COMP').debug('components in
repository 2');
}
}
############################################################ ######

URL saveilURL = FileLocator.find(bundle, new Path("saveil.asm"),
Collections.EMPTY_MAP);

try {
ASMModel compModel = null ;
ASMModel outputModel = emfamh.newModel("MERGE", asurilMM_EMF);
ASMModel inputModel = emfamh.loadModel("IN", asurilMM_EMF,
domainProject.getFile(domainModelPath.lastSegment()).getCont ents(true));

// if repository exists, loading it, either loading an empty model
if (domainProject.exists(new Path(".components"))) {
compModel = emfamh.loadModel("COMP", asurilMM_EMF,
domainProject.getFile(".components").getContents(true));
} else {
compModel = emfamh.newModel("COMP", asurilMM_EMF);
}

Map<String, ASMModel> models = new HashMap<String, ASMModel>();
models.put(asurilMM_EMF.getName(), asurilMM_EMF); // metamodel
models.put(inputModel.getName(), inputModel); // input model
models.put(compModel.getName(), compModel); // input model
models.put(outputModel.getName(), outputModel); // output model

// Launch ATL transformation
AtlLauncher.getDefault().launch(saveilURL, Collections.EMPTY_MAP,
models, Collections.EMPTY_MAP);

emfamh.saveModel(outputModel,".components",domainProject);

System.out.println("save complete");
} catch (CoreException ex) {
ex.printStackTrace();
}


Guillaume Gauffre a écrit :
> Sorry, I think I have found the solution be using 2 input models,
> creating a target model which merge the 2 input
>
> Guillaume
>
> Guillaume Gauffre a écrit :
>> Hi,
>>
>> I wish to add elements of a model into another which is a kind of
>> repository. To do that,I made a transformation which creates the
>> target model elements I need, and programmatically, I launch my
>> transformation using as target model the existing model instead of a
>> new model (depending on the model already exists or not) !
>>
>> ######## transformation header #######
>> -- @atlcompiler atl2004
>> module saveil;
>> create OUT : asurIL refining IN : asurIL;
>>
>>
>> ######## my code ########
>> ASMModel outputModel = null;
>> ASMModel inputModel =
>> emfamh.loadModel("IN" ,asurilMM_EMF,domainModelPath.toFile().toURI().toURL().openS tream());
>>
>> if (domainProject.exists(new Path(".components"))) {
>> outputModel =
>> emfamh.loadModel("OUT",asurilMM_EMF,domainProject.getFile( ".components").getContents());
>>
>> } else {
>> outputModel = emfamh.newModel("OUT", asurilMM_EMF);
>> }
>> Map models = new HashMap();
>> models.put(asurilMM_EMF.getName(), asurilMM_EMF); // input metamodel
>> models.put(asurilMM_EMF.getName(), asurilMM_EMF); // output metamodel
>> models.put("IN", inputModel); // input model
>> models.put("OUT", outputModel); // output model
>>
>> AtlLauncher.getDefault().launch(saveilURL,Collections.EMPTY_ MAP,models,Collections.EMPTY_MAP);
>>
>> emfamh.saveModel(outputModel,".components", domainProject);
>> ########################
>>
>> I try to use the refining mode for this transformation.
>> It works fine if the target model is new but it generates an exception
>> if I use the existing model :
>>
>> "java.lang.IllegalArgumentException: argument type mismatch"
>>
>> NativeOperation public static void
>> org.atl.engine.vm.nativelib.ASMTransientLink.addTargetElemen t(org.atl.engine.vm.StackFrame,org.atl..engine.vm.nativelib. ASMTransientLink,org.atl.engine.vm.nativelib.ASMString,org.a tl.engine.vm.nativelib.ASMOclAny)
>>
>> args = [TransientLink {rule = 'MODEL', sourceElements = {input =
>> IN!<unnamed>}, targetElements = {}, variables = {}}, TransientLink
>> {rule = 'MODEL', sourceElements = {input = IN!<unnamed>},
>> targetElements = {}, variables = {}}, 'output']
>>
>> Refining mode or normal mode, the error is the same !
>> Is it possible to do what I want ?
>> Maybe, using 2 source models, one to refine with the content of the
>> second ? How to do that ?
>>
>> Many thanks !
>>
>> Guillaume
Previous Topic:collection of objects in the from of a rule
Next Topic:[ATL] : Manage errors
Goto Forum:
  


Current Time: Thu Mar 28 10:35:55 GMT 2024

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

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

Back to the top