Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Execute operation in java code(getting and operation from .etl file and then execute it by java code)
Execute operation in java code [message #1781029] Wed, 31 January 2018 16:29 Go to next message
taghreed altamimi is currently offline taghreed altamimiFriend
Messages: 184
Registered: October 2014
Senior Member
Hi,
The following code gets the transformation rules and the guard for each rule.My question is : if the guard is an operation can i execute it ?? and i f yes what java code i need to execute an operation in standalone manner??

package etljavatool;
import  org.eclipse.epsilon.eol.dom.Parameter;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.epsilon.eol.dom.ExecutableBlock;
import org.eclipse.epsilon.eol.execute.operations.*;
import org.eclipse.epsilon.etl.EtlModule;
import org.eclipse.epsilon.etl.dom.TransformationRule;
import org.eclipse.epsilon.etl.execute.*;
import org.eclipse.epsilon.etl.execute.context.*;
import org.eclipse.epsilon.etl.execute.operations.*;
import org.eclipse.epsilon.etl.parse.*;
import org.eclipse.epsilon.etl.strategy.*;
import org.eclipse.epsilon.eol.IEolModule;
import org.eclipse.epsilon.eol.models.IModel;
public class EtlTool{
 public static void main(String[] args) throws Exception {
	
	EtlModule module = new EtlModule();
	module.parse(new File("C:/Epsilon/eclipse-epsilon-1.3-win32-x86_64/workspace/EtlJavaTool/src/TraceabilityFeb3.etl"));
		
	if (!module.getParseProblems().isEmpty()) return;
		
	module.getTransformationRules(); // Returns a list of transformation rules
	
	for (TransformationRule tr : module.getTransformationRules()) {
	//TransformationRule rule = module.getTransformationRules().get(5);
    List<Parameter>  t  = tr.getTargetParameters() ;
    Parameter s  = tr.getSourceParameter() ;
    s.getTypeName();
    t.get(0);
       		
     System.out.println("Target type "+ t.get(0).getTypeName());
    
    System.out.println("Source type "+ s.getTypeName()); 

	ExecutableBlock<Boolean> ex =tr.getGuard();
	
	if (ex != null)
	{//ex.getBody();
	    System.out.println("guard "+ex.getBody() );	
	   
	   }	
	}

}
}


Thanks,
Taghreed
Re: Execute operation in java code [message #1781098 is a reply to message #1781029] Thu, 01 February 2018 11:21 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 1
Registered: February 2018
Junior Member
You need to use the #execute(IEolContext) method, which takes an execution context, which will provide you with the return value from whatever expression you have on the guard (regardless of whether it is an operation or not).

You could probably reuse the EtlContext in the EtlModule, by invoking #getContext() on it. Regardless, if you want to try running standalone subexpressions in the program, you will need to prepare the context a bit. For instance, you'll have to add the proper variables to the frame stack (context.getFrameStack().put(...)) and define the transformation strategy. You might want to look at the EtlModule#executeImpl source code for hints on that.

Hope that helps!
Re: Execute operation in java code [message #1781164 is a reply to message #1781029] Fri, 02 February 2018 08:49 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2162
Registered: July 2009
Location: York, UK
Senior Member

Hi Taghreed,

I'd recommend going through the code of TransformationRule (e.g. line 144 in [1] shows how guards are executed).

Cheers,
Dimitris

[1] https://git.eclipse.org/c/epsilon/org.eclipse.epsilon.git/tree/plugins/org.eclipse.epsilon.etl.engine/src/org/eclipse/epsilon/etl/dom/TransformationRule.java
Re: Execute operation in java code [message #1781295 is a reply to message #1781164] Mon, 05 February 2018 17:26 Go to previous messageGo to next message
taghreed altamimi is currently offline taghreed altamimiFriend
Messages: 184
Registered: October 2014
Senior Member
Hi Dimitris,
public static void main(String[] args) throws Exception {
	
	EtlModule module = new EtlModule();
	module.parse(new File("C:/Epsilon/eclipse-epsilon-1.3-win32-x86_64/workspace/EtlJavaTool/src/TraceabilityFeb3.etl"));
	
	if (!module.getParseProblems().isEmpty()) return;
		
	module.getTransformationRules(); // Returns a list of transformation rules
	
	for (TransformationRule tr : module.getTransformationRules()) {
		if (tr.getName().equals("AcceptEventAction2entryNone")) {
    List<Parameter>  t  = tr.getTargetParameters() ;
    Parameter s  = tr.getSourceParameter() ;
       	  
	
	ExecutableBlock<Boolean> ex =tr.getGuard();
		if (ex != null)
	{
		boolean guardSatisfied = true;
			
	        guardSatisfied = ex.execute(module.getContext(), 
				Variable.createReadOnlyVariable(s.getName(), s), 
				Variable.createReadOnlyVariable("self", s));	
	   }	
	}
	}
}
}


The Etl rule that i am trying to get its guard and executing is
rule AcceptEventAction2entryNone
	transform a : UML!AcceptEventAction
	to e : lqnmodel!entry{
	
	 guard: isNONEPattern(a.outgoing.first())
	 
	 	
	    e.name=a.name;
	    e.type=lqnmodel!EntryType#NONE;
	  	
}


I keep getting an exception says that :
Exception in thread "main" Property 'outgoing' not found in object a:UML!AcceptEventAction

'outgoing' is the parameter for the guard ,I think that i am sending wrong parameters when i am calling execute.Can you please take a look and advise me how to fix the problem.

Many thanks,
Taghreed.
Re: Execute operation in java code [message #1781312 is a reply to message #1781295] Mon, 05 February 2018 22:04 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2162
Registered: July 2009
Location: York, UK
Senior Member

Hi Taghreed,

Off the top of my head the problem seems to be in Variable.createReadOnlyVariable(s.getName(), s). What you need to pass as the value of the variable is not "s" but an instance of its type (AcceptEventAction). You'll also need to put the model in module.getContext().getModelRepository(). You may find the Epsilon Demo Language described in [1] to be an easier entry point than ETL for understanding how Epsilon interpreters work.

Cheers,
Dimitris

[1] https://www.eclipse.org/epsilon/doc/articles/developing-a-new-language/
Re: Execute operation in java code [message #1781451 is a reply to message #1781312] Wed, 07 February 2018 12:19 Go to previous messageGo to next message
Horacio Hoyos is currently offline Horacio HoyosFriend
Messages: 242
Registered: October 2009
Location: Mexico
Senior Member

Hi Taghreed,

Perhaps if you also provide a bit more context on what you are trying to achieve we can provide alternative means to such end.

Cheers,


Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
Re: Execute operation in java code [message #1781474 is a reply to message #1781451] Wed, 07 February 2018 17:05 Go to previous messageGo to next message
taghreed altamimi is currently offline taghreed altamimiFriend
Messages: 184
Registered: October 2014
Senior Member
Hi ,
Sorry i didn't understand ,what do you mean by " provide a bit more context "?? Can you please elaborate more
I think that i am confused about what does the context of the transformation mean???
as i understand the context of the transformation consists of source model and its metamodel and the target model and its metamodel and etl rules.Am i correct???

Thanks,
Taghreed


Re: Execute operation in java code [message #1781525 is a reply to message #1781474] Thu, 08 February 2018 08:41 Go to previous messageGo to next message
Horacio Hoyos is currently offline Horacio HoyosFriend
Messages: 242
Registered: October 2009
Location: Mexico
Senior Member

I menat context (information) in the sense of why do you only want to execute the guard ? Are you trying to do some debugging or using he guard tests to trigger some other process?

Cheers,


Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
Re: Execute operation in java code [message #1781564 is a reply to message #1781525] Thu, 08 February 2018 16:55 Go to previous messageGo to next message
taghreed altamimi is currently offline taghreed altamimiFriend
Messages: 184
Registered: October 2014
Senior Member
Hi Horacio,
I am a PhD student interested in change propagation approaches.I developed an etl transformation and i know that ETL doesn't support incrementality. My goal is to propagate changes form the source model to the target model without re executing the etl transformation again.The source model is UML model and the target model is performance model(Layered queuing network model).I applied some changes on the source model(UML) and then detect changes by EMF compare tool.I generated .etl.model by Epsilon Haetae to get the mapping between source model elements types and target model elements types.Now i am able to identify the target type for every source type by querying ( .etl.model ) using EOL. and also identify target element for changed source element and update it by calling an EOL operation according to the differences that generated by EMF compare. From .etl.model i can also get the guard for the source element type so i need to execute it using java tool and calling it through my EOL code to make sure that the guard is still valid for the source element that has been changed .In some cases when the source element changed the guard evaluation also changed. for example if the guard became True , i need to take an action to change the target model by creating the target element for that changed source element.
I need a way to execute the guard which i am getting its name and its argument by querying (.etl.model) using EOL code .
Attached a minimal example has a simple EOL code getting the guard.

Thanks,
Taghreed
Re: Execute operation in java code [message #1781982 is a reply to message #1781564] Thu, 15 February 2018 12:48 Go to previous message
Horacio Hoyos is currently offline Horacio HoyosFriend
Messages: 242
Registered: October 2009
Location: Mexico
Senior Member

Hi Taghreed,

That is a very interesting project! I am sure we could collaborate more directly if you want (I am currently working on incremental execution of Epsilon languages myself), perhaps as an external assessor to your PhD (lets take this offline - can you drop me an email[1]?)

I think the problem with our approach is that to execute the guard you need to assign the rule parameters model object elements:
...
// This method would be responsible for finding the element that changed, if it was used for this rule (note that this could be a list of elements)
Object sVal = etlModelComapre.getSourceElementThatChangedFor(tr);
guardSatisfied = ex.execute(module.getContext(), 
				Variable.createReadOnlyVariable(s.getName(), sVal),     // We put the changed Object in the context 
				Variable.createReadOnlyVariable("self", sVal));	


You also need to consider that the guard expression might use other object references, those should also be added to the context. If the guard uses an "all" call, then the model that is being queried should also be in the context.

Cheers,

[1] https://www.cs.york.ac.uk/people/hhoyos


Horacio Hoyos Rodriguez
Kinori Tech
Need professional support for Epsilon, EMF?
Go to: https://kinori.tech
Previous Topic:Getting EReference name from emf model and save it in a variable
Next Topic:ETL-Trace
Goto Forum:
  


Current Time: Tue Apr 16 21:35:19 GMT 2024

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

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

Back to the top