Skip to main content



      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 11:36 Go to next message
Eclipse UserFriend
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 03:36 Go to previous messageGo to next message
Eclipse UserFriend
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 02:11 Go to previous message
Eclipse UserFriend
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: Sun Jun 22 21:14:50 EDT 2025

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

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

Back to the top