Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [XPAND] Output transformation to string
[XPAND] Output transformation to string [message #488990] Thu, 01 October 2009 06:57 Go to next message
Cedric Moonen is currently offline Cedric MoonenFriend
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 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
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
Previous Topic:Extend - Debuging extend script when you invoke M2M from runtime eclipse workbench
Next Topic:M2T with Xpand
Goto Forum:
  


Current Time: Sat Apr 20 02:40:44 GMT 2024

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

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

Back to the top