Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » use Generated file in memory directly
use Generated file in memory directly [message #1067592] Tue, 09 July 2013 13:45 Go to next message
Adnan AL-SOSWA is currently offline Adnan AL-SOSWAFriend
Messages: 41
Registered: May 2010
Member
Hi all ,

I want guidance please about xpnad generation procedure. I worte xpand template to generate another xpand template and I want to run the generated template when it is still in memory without writing it to disk .

I appreciate your guidance .


Thanks in advance.

[Updated on: Tue, 09 July 2013 13:57]

Report message to a moderator

Re: use Generated file in memory directly [message #1067834 is a reply to message #1067592] Wed, 10 July 2013 19:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
Hi

the following works for me but i dont know if it will work in all cases

public static void main(String[] args) {
		final Template template = XpandParseFacade.file(new StringReader("«DEFINE test FOR String»«FILE 'x.text'»Hallo «this»!«ENDFILE»«ENDDEFINE»"), "test/Test.xpt");
		Output out = new OutputImpl();
		out.addOutlet(new Outlet("my-gen"));
		ResourceManager resourceManager = new ResourceManagerDefaultImpl() {
		@Override
		public Resource loadResource(String fullyQualifiedName,
				String extension) {
			if ("test::Test".equals(fullyQualifiedName)){
				return template;
			}
			return super.loadResource(fullyQualifiedName, extension);
		}
		};
		ProtectedRegionResolver prs = null;
		ProgressMonitor monitor = new NullProgressMonitor();
		ExceptionHandler exceptionHandler = null; 
		NullEvaluationHandler nullEvaluationHandler = null;
		VetoableCallback callback = null;
		XpandExecutionContext execCtx = new XpandExecutionContextImpl(resourceManager , out, prs, new HashMap<String, Variable>(), monitor, exceptionHandler, nullEvaluationHandler, callback);
		XpandFacade.create(execCtx).evaluate("test::Test::test", "xxx");

	}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: use Generated file in memory directly [message #1067839 is a reply to message #1067834] Wed, 10 July 2013 19:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
The following works as well

import java.io.InputStream;

import org.eclipse.emf.mwe.core.resources.AbstractResourceLoader;
import org.eclipse.emf.mwe.core.resources.ResourceLoaderFactory;
import org.eclipse.emf.mwe.internal.core.MWEPlugin;
import org.eclipse.xpand2.XpandExecutionContext;
import org.eclipse.xpand2.XpandExecutionContextImpl;
import org.eclipse.xpand2.XpandFacade;
import org.eclipse.xpand2.output.Outlet;
import org.eclipse.xpand2.output.Output;
import org.eclipse.xpand2.output.OutputImpl;
import org.eclipse.xtext.util.StringInputStream;

public class TestIt {
	
	public static class MyRL extends AbstractResourceLoader {

		@Override
		protected Class<?> tryLoadClass(String clazzName)
				throws ClassNotFoundException {
			return MWEPlugin.loadClass(MWEPlugin.ID, clazzName);
		}
		
		@Override
		public InputStream getResourceAsStream(String path) {
			if ("test/Test.xpt".equals(path)) {
				return new StringInputStream("«DEFINE test FOR String»«FILE 'x.text'»Halloooooo «this»!«ENDFILE»«ENDDEFINE»"); 
			}
			return super.getResourceAsStream(path);
		}
	
		
	
	}

	public static void main(String[] args) {
		System.setProperty(ResourceLoaderFactory.PARAM_RESOURCELOADER_CLASS, MyRL.class.getName());
		Output out = new OutputImpl();
		out.addOutlet(new Outlet("my-gen"));
		
		XpandExecutionContext execCtx = new XpandExecutionContextImpl(out, null);
		XpandFacade.create(execCtx).evaluate("test::Test::test", "xxx");

	}

}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: use Generated file in memory directly [message #1071153 is a reply to message #1067839] Fri, 19 July 2013 13:01 Go to previous messageGo to next message
Adnan AL-SOSWA is currently offline Adnan AL-SOSWAFriend
Messages: 41
Registered: May 2010
Member
Hi Christian ,

Thank you for your answer .

but As I understood from your answer , it is implementing xpnad code without need to physiacl template file and its workflow am I right ?

what I need actually is generating templates and files to memory , then use these template and file to final generation to disk .

for example :
String wfFile2 = "workflow/generator.mwe";			
		properties2.put("modelFile", modelFilePath);
		properties2.put("src-gen", src-gen);

if you please How I can make src-gen position in memory and how I access the generated template there ?

in the next step :
String wfFile3 = "workflow/generator2.mwe";			
		properties2.put("modelFile", modelFilePath);
		properties2.put("src-gen", folderondisk or workspace);

generator2.mwe should run on the generated template in memory .

anothee question please : why my plugin can not find the generated template when I specify local folder to keep the generated template?

to make it simple I am looking for : what is the best way to implement template in plugin and reusing genertaed templte in the same plugin ?

any guidance or tutorial for better understanding or examples are appreciated

Thanks in advance
Re: use Generated file in memory directly [message #1071168 is a reply to message #1071153] Fri, 19 July 2013 13:38 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
Hi sorry no tutorial but my Code does what you ask for (OK my
template is hard coded but this does not count)

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:JET Editor in Kepler
Next Topic:[XPAND] Define EMF metamodel From XML with XPand
Goto Forum:
  


Current Time: Fri Apr 26 20:44:02 GMT 2024

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

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

Back to the top