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 12:34 Go to next message
Caroline Bourdeu d'Aguerre is currently offline Caroline Bourdeu d'Aguerre
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 17:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6144
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" ?
Re: [XPAND] perform OAW code without creating physical files [message #504179 is a reply to message #504044] Thu, 17 December 2009 10:20 Go to previous messageGo to next message
Caroline Bourdeu d'Aguerre is currently offline Caroline Bourdeu d'Aguerre
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 15:06 Go to previous message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6144
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?
Previous Topic:[XTEND] best practices cached extensions
Next Topic:QVTO helper fails
Goto Forum:
  


Current Time: Fri Aug 01 00:03:31 EDT 2014

Powered by FUDForum. Page generated in 0.06438 seconds