Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » How to get the location of the currently executing template in java wrapper(Trying to get the path in the file system where the template that called a java service wrapper is located)
How to get the location of the currently executing template in java wrapper [message #1785258] Wed, 11 April 2018 15:36 Go to next message
Thomas Petrou is currently offline Thomas PetrouFriend
Messages: 12
Registered: April 2018
Junior Member
Hello all,

I am trying to get the path of a template that has a call to java service wrapper.

e.g.
I have a template that we assume it is located in /mtls/CallingWrapperTemplate.mtl
[comment encoding = UTF-8 /]

[module module_name('ECORE_NAMESPACE')]

[template public module_name(e : EClass)]
[javaWrapper()/]			


[/template]
[query public javaWrapper() : OclVoid = 
					invoke('javaWrapper', 
					'method_name()', 
					Sequence{})
 /]


In my javaWrapper class I would like to do something like
System.out.println(getPathOfCallingMtlTemplate());


The above code should print "/mtls/CallingWrapperTemplate.mtl"


Any ideas?

Thank you in advance
Thomas
Re: How to get the location of the currently executing template in java wrapper [message #1785291 is a reply to message #1785258] Thu, 12 April 2018 07:36 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6111
Registered: July 2009
Senior Member
Hi

Once you invoke Java code you have some interesting things available as call parameters. Perhaps one of those enables you to access the current 'program counter' and so the EObject of the MOFM2T metamodel enabling you to determine the caller.

Otherwise you have the Java stack that you dismember to find what you want - ugly.

Regards

Ed Willink
Re: How to get the location of the currently executing template in java wrapper [message #1785369 is a reply to message #1785291] Fri, 13 April 2018 06:11 Go to previous message
Thomas Petrou is currently offline Thomas PetrouFriend
Messages: 12
Registered: April 2018
Junior Member
Thanks Ed!

I have noticed that even the MTL launcher in eclipse i calling the main method on generate so i have created a JUNit method that calls my main method and it supplies a third argument which is the root path of the templates.

This is not exactly what i intended for and does not cover all the scenarios. Nevertheless I hope it is sufficient... we will see. If not i will try what you are suggesting and come back with the result :)

Thanks for the assistance
Previous Topic:Retrieve target folder during generation
Next Topic:guery name
Goto Forum:
  


Current Time: Sat Nov 17 03:10:28 GMT 2018

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

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

Back to the top