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):

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 ?

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