|
Re: use Generated file in memory directly [message #1067834 is a reply to message #1067592] |
Wed, 10 July 2013 19:19 |
|
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
Day Job: https://www.everest-systems.com
|
|
|
Re: use Generated file in memory directly [message #1067839 is a reply to message #1067834] |
Wed, 10 July 2013 19:30 |
|
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
Day Job: https://www.everest-systems.com
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03460 seconds