Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [XPAND] perform OAW code without creating physical files
[XPAND] perform OAW code without creating physical files [message #503986] Wed, 16 December 2009 17:34 Go to next message
Caroline Bourdeu d'Aguerre is currently offline Caroline Bourdeu d'AguerreFriend
Messages: 6
Registered: July 2009
Junior Member
Hi all,

I am looking for a M2T technology. i want to execute a transformation code that I have exctracted from a file. The code transformation is in a string. Is it possible to execute an OAW transformation without create a physical file (xpt) ?

Thank in advance,

Caroline
Re: [XPAND] perform OAW code without creating physical files [message #504044 is a reply to message #503986] Wed, 16 December 2009 22:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14725
Registered: July 2009
Senior Member
Hello Caroline,

afaik this is not possible out of the box. it may be possible by hooking into some internals of Xpand e.g. like this

import java.io.Reader;
import java.io.StringReader;

import org.eclipse.internal.xpand2.ast.Template;
import org.eclipse.internal.xpand2.parser.XpandParseFacade;
import org.eclipse.xpand2.XpandExecutionContextImpl;
import org.eclipse.xpand2.XpandFacade;
import org.eclipse.xpand2.output.Outlet;
import org.eclipse.xpand2.output.OutputImpl;
import org.eclipse.xtend.expression.Resource;


public class XpandRunner {
	
	public static void main(String[] args) {
		OutputImpl out = new OutputImpl();
		out.addOutlet(new Outlet("src-gen"));
		XpandExecutionContextImpl ctx = new XpandExecutionContextImpl(out, null) {
			
			private Template template;
			
			@Override
			public Resource currentResource() {
				if (template == null) {
					String templateString = "«DEFINE test FOR String»«FILE \"test.txt\"»Hello «this»«ENDFILE»«ENDDEFINE»";
					Reader r = new StringReader(templateString );
					template = XpandParseFacade.file(r , "sample/test.xpt");
				}
				return template;
			}
		};
		
		
		XpandFacade.create(ctx).evaluate("test", "Welt", new Object[] {});
	}

}


but this may not be neccesary. can you tell more about your usecase. that do you mean with "exctracted from a file" ?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: [XPAND] perform OAW code without creating physical files [message #504179 is a reply to message #504044] Thu, 17 December 2009 15:20 Go to previous messageGo to next message
Caroline Bourdeu d'Aguerre is currently offline Caroline Bourdeu d'AguerreFriend
Messages: 6
Registered: July 2009
Junior Member
Thank you for your quick reply,

I have extracted from a file a code which is now in a string like:
String myCode = 
"«DEFINE Root(String fileName) FOR Package»
	«FILE fileName+".docbook"	-»
<?xml version='1.0' encoding="ISO-8859-15" ?>
<book lang="en">
		«EXPAND PackageChapter FOREACH ownedElement-»
</book>
	«ENDFILE»
«ENDDEFINE»";


is it possible to execute this code with out create a xpt file
Re: [XPAND] perform OAW code without creating physical files [message #504240 is a reply to message #504179] Thu, 17 December 2009 20:06 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14725
Registered: July 2009
Senior Member
hi,

my sample code could be a start but i would try to avoid to generate this way. what kind of file do you extract the template from?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Previous Topic:[XTEND] best practices cached extensions
Next Topic:QVTO helper fails
Goto Forum:
  


Current Time: Tue Oct 15 00:15:24 GMT 2024

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

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

Back to the top