Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » [EMFTVM] Could resolve functions return null when no image found ?
[EMFTVM] Could resolve functions return null when no image found ? [message #1256208] Tue, 25 February 2014 07:49 Go to next message
EtienneB Mising name is currently offline EtienneB Mising name
Messages: 35
Registered: June 2011
Member
Dear Dennis,

I wanted to ask if it would be possible to add an option in the emftvm launcher in order to allow partial resolution of outut elements with the resolve operations (resolveTemp, resolve...). Indeed, I would like to activate or deactivate the fact that the emftvm throws an exception when resolveTemp does not manage to find the image of the source element passed as parameter.

One of the reasons for this is that I collect elements that could be produced by different rules and I don't want to repeat the condition of application of each rule variant all the time.

For instance, if I write (ATL pseudo code):
rule R1
{
  from
    e: IN!Element
    (e.name='root')
  to
    r: OUT!Root
    ....
}

rule R2
{
  from
    e: IN!Element
    (e.name='operation')
  to
    op: OUT!Operation
    ....
}

rule R
{
  from
    d_in: In!Diagram
  to
    d_out: OUT!Diagram
    (
      elements <- d_in.elements->select(e|e.name='root')
			       ->collect(e|thisModule.resolveTemp(e, 'r'))
	          ->union(d_in.elements->select(e|e.name='operation')
				       ->collect(e|thisModule.resolveTemp(e, 'op'))
}

it works fine; but maintaining rule R becomes complex if I have too many way to map objects of type Element.

Instead of repeating the filter (select clause) in rule R, I would prefer to write:
rule R
{
  from
    d_in: In!Diagram
  to
    d_out: OUT!Diagram
    (
      elements <- d_in.elements->collect(e|thisModule.resolveTemp(e, 'r'))
		  ->union(d_in.elements->collect(e|thisModule.resolveTemp(e, 'op'))
		  ->excluding(OclUndefined)
    )
}

The only problem here is that the EMFTVM runtime throws an exception if resolve functions do not work. Would it be possible to have an option in the emftvm launch in order to deactivate this exception, and return null (OclUndefined) instead?

I would find it more convenient to be able to control this behaviour with a simple option passed as parameter of the ExecEnv launch function or to the constructor of this class.

What is your opinion about this?

Thanks for your answer,
Etienne.
Re: [EMFTVM] Could resolve functions return null when no image found ? [message #1256578 is a reply to message #1256208] Tue, 25 February 2014 15:28 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis Wagelaar
Messages: 166
Registered: September 2012
Senior Member

This is what we use at HealthConnect:

--- Returns the same as thisModule.resolveTemp(var : OclAny, rule_name : String, target_pattern_name : String),
--- except that it returns OclUndefined if no trace exists instead of throwing an error.
helper def : resolveIfExists(var : Sequence(OclAny), rule_name : String, target_pattern_name : String) : OclAny =
    let tr : OclAny = thisModule.traces.getLinksByRule(rule_name, false) in
    if tr.oclIsUndefined() then
    	OclUndefined
    else
    	let sel : OclAny = tr.getUniqueSourceElements(var) in
        if sel.oclIsUndefined() then
        	OclUndefined
        else
        	let te : OclAny = sel.getSourceElements().get(0).getSourceOf().getTargetElement(target_pattern_name) in
            if te.oclIsUndefined() then
            	OclUndefined
            else
            	te.getObject()
            endif
        endif
       endif;


You may adapt the code to use thisModule.traces.getDefaultSourceElement(var) instead. See the EMFTVM Trace metamodel for details (nsURI="http://www.eclipse.org/m2m/atl/emftvm/2011/Trace").


Cheers,
Dennis
Re: [EMFTVM] Could resolve functions return null when no image found ? [message #1257584 is a reply to message #1256578] Wed, 26 February 2014 15:44 Go to previous message
EtienneB Mising name is currently offline EtienneB Mising name
Messages: 35
Registered: June 2011
Member
This is nice, I could then fix my issues by adapting the code snippet you propose. Besides it makes the use of traces very flexible!

Thanks for your help,

Etienne.
Previous Topic:UML meta-model access
Next Topic:Error loading WSDL/XSD -> UML transformation programmatically
Goto Forum:
  


Current Time: Sat Oct 25 22:23:40 GMT 2014

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

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