[XPAND] Output transformation to string [message #488990] |
Thu, 01 October 2009 06:57 |
Cedric Moonen Messages: 274 Registered: August 2009 |
Senior Member |
|
|
Hello,
I am very new to the modeling project in general. I am trying to transform a diagram made using GMF to text by using XPAND. I've been able to do so but I am only able to ouptut the result to an external file. This is the code I use (I've found it on the net):
public void convertToText() {
EObject model = getDiagram().getElement();
// configure outlets
OutputImpl output = new OutputImpl();
Outlet outlet = new Outlet("myOutput.txt");
outlet.setOverwrite(true);
output.addOutlet(outlet);
// create execution context
Map globalVarsMap = new HashMap();
XpandExecutionContextImpl execCtx = new XpandExecutionContextImpl(
output, null, globalVarsMap, null, null);
EmfRegistryMetaModel metamodel = new EmfRegistryMetaModel() {
@Override
protected EPackage[] allPackages() {
return new EPackage[] { SodaPackage.eINSTANCE,
EcorePackage.eINSTANCE };
}
};
execCtx.registerMetaModel(metamodel);
// generate
XpandFacade facade = XpandFacade.create(execCtx);
String templatePath = "templates::Pattern2Text::Main";
try {
facade.evaluate(templatePath, model);
} catch (EvaluationException ee) {
ee.printStackTrace();
}
}
The code works fine and I have the correct text transformation in my file. But, instead of outputing the result to a file, I need to have it as a string that I can use in my program.
Of course, I can always open the file and read its content but it seems a bit overkill. Is there a way to get the result directly, without needing to go to a temporary file ?
Thanks
Cédric
|
|
|
Re: [XPAND] Output transformation to string [message #489002 is a reply to message #488990] |
Thu, 01 October 2009 07:38 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Cédric,
this question came up a few days ago in this newsgroup. Please have a
look at the thread "How to generate into a string instead of a file with
xpand?"
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
C schrieb:
> Hello,
> I am very new to the modeling project in general. I am trying to
> transform a diagram made using GMF to text by using XPAND. I've been
> able to do so but I am only able to ouptut the result to an external
> file. This is the code I use (I've found it on the net):
>
> public void convertToText() {
> EObject model = getDiagram().getElement();
>
> // configure outlets
> OutputImpl output = new OutputImpl();
> Outlet outlet = new Outlet("myOutput.txt");
> outlet.setOverwrite(true);
> output.addOutlet(outlet);
>
> // create execution context
> Map globalVarsMap = new HashMap();
> XpandExecutionContextImpl execCtx = new XpandExecutionContextImpl(
> output, null, globalVarsMap, null, null);
> EmfRegistryMetaModel metamodel = new EmfRegistryMetaModel() {
> @Override
> protected EPackage[] allPackages() {
> return new EPackage[] { SodaPackage.eINSTANCE,
> EcorePackage.eINSTANCE };
> }
> };
> execCtx.registerMetaModel(metamodel);
>
> // generate
> XpandFacade facade = XpandFacade.create(execCtx);
> String templatePath = "templates::Pattern2Text::Main";
> try {
> facade.evaluate(templatePath, model);
> } catch (EvaluationException ee) {
> ee.printStackTrace();
> }
> }
>
> The code works fine and I have the correct text transformation in my
> file. But, instead of outputing the result to a file, I need to have it
> as a string that I can use in my program.
> Of course, I can always open the file and read its content but it seems
> a bit overkill. Is there a way to get the result directly, without
> needing to go to a temporary file ?
>
> Thanks
> Cédric
|
|
|
Powered by
FUDForum. Page generated in 0.02402 seconds