use Generated file in memory directly [message #1067592] |
Tue, 09 July 2013 13:45  |
Eclipse User |
|
|
|
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] by Moderator 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   |
Eclipse User |
|
|
|
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");
}
|
|
|
Re: use Generated file in memory directly [message #1067839 is a reply to message #1067834] |
Wed, 10 July 2013 19:30   |
Eclipse User |
|
|
|
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");
}
}
|
|
|
Re: use Generated file in memory directly [message #1071153 is a reply to message #1067839] |
Fri, 19 July 2013 13:01   |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03132 seconds