Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » GMT (Generative Modeling Technologies) » How to invoke MOFSCRIPT from java code..
How to invoke MOFSCRIPT from java code.. [message #375594] Thu, 02 November 2006 09:14 Go to next message
Gabriel Merin Cubero is currently offline Gabriel Merin CuberoFriend
Messages: 12
Registered: July 2009
Junior Member
Hi! I have several MOFSCRIPT transformations but I would like to invoke
them directly form my Java code, instead of using MOFSCRIPT interface.
Hence, the user of my plug-in would be able to accomplish a
transformation by means of right-click or just a button-click.

Does anyone know how to accomplish this? Any hint? I've seen another
post with the same problem but it does not have any reply.

Thanks in advance,
Gabriel Merin
Re: How to invoke MOFSCRIPT from java code.. [message #375596 is a reply to message #375594] Thu, 02 November 2006 12:50 Go to previous messageGo to next message
Jon Oldevik is currently offline Jon OldevikFriend
Messages: 17
Registered: July 2009
Junior Member
Hi,

This is documented by an example in the latest MOFScript documentation
(see http://www.eclipse.org/gmt/mofscript/doc/ or
http://www.modelbased.net/mofscript/docs/MOFScript-User-Guid e.pdf).

Example code for parsing and executing is given below:

ParserUtil parserUtil = new ParserUtil();
ExecutionManager execMgr = ExecutionManager.getExecutionManager();
//
// The parserutil parses and sets the input transformation model
// for the execution manager.
//
File f = new File ("EcoreTest.m2t");
MOFScriptSpecification spec = parserUtil.parse(f, true);
// check for errors:
int errorCount = ParserUtil.getModelChecker().getErrorCount();
Iterator errorIt = ParserUtil.getModelChecker().getErrors(); // Iterator
of MofScriptParseError objects

System.out.println ("Parsing result: " + errorCount + " errors");
if (errorCount > 0) {

for (;errorIt.hasNext();) {
MofScriptParseError parseError = (MofScriptParseError) errorIt.next();
System.out.println("\t \t: Error: " + parseError.toString());
}
return;
}



// load source model
XMIResourceFactoryImpl _xmiFac = new XMIResourceFactoryImpl();
EObject sourceModel = null;
File sourceModelFile = new File ("SM.ecore");
ResourceSet rSet = new ResourceSetImpl ();
rSet.getResourceFactoryRegistry().getExtensionToFactoryMap() .put( "*",
_xmiFac);
URI uri = URI.createFileURI(sourceModelFile.getAbsolutePath());
Resource resource = rSet.getResource(uri, true);

if (resource != null) {
if (resource.getContents().size() > 0) {
sourceModel = (EObject) resource.getContents().get(0);
}
}

// set the source model for the exeution manager
execMgr.addSourceModel(sourceModel);
// sets the root output directory, if any is desired (e.g. "c:/temp")
execMgr.setRootDirectory("");
// if true, files are not generated to the file systsm, but populated
into a filemodel
// which can be fetched afterwards. Value false will result in standard
file generation
execMgr.setUseFileModel(false);
// Turns on/off system logging
execMgr.setUseLog(false);
// Adds an output listener for the transformation execution.
execMgr.getExecutionStack().addOutputMessageListener(this);
try {

execMgr.executeTransformation();
} catch (MofScriptExecutionException mex) {
mex.printStackTrace();
}





Gabriel Merin Cubero wrote:

> Hi! I have several MOFSCRIPT transformations but I would like to invoke
> them directly form my Java code, instead of using MOFSCRIPT interface.
> Hence, the user of my plug-in would be able to accomplish a
> transformation by means of right-click or just a button-click.

> Does anyone know how to accomplish this? Any hint? I've seen another
> post with the same problem but it does not have any reply.

> Thanks in advance,
> Gabriel Merin
Re: How to invoke MOFSCRIPT from java code.. [message #375598 is a reply to message #375596] Thu, 02 November 2006 15:27 Go to previous messageGo to next message
Gabriel Merin Cubero is currently offline Gabriel Merin CuberoFriend
Messages: 12
Registered: July 2009
Junior Member
Thank you very much Jon! It's been a great help.

Regards,
Gabriel Merin Cubero

Jon Oldevik escribió:
> Hi,
>
> This is documented by an example in the latest MOFScript documentation
> (see http://www.eclipse.org/gmt/mofscript/doc/ or
> http://www.modelbased.net/mofscript/docs/MOFScript-User-Guid e.pdf).
> Example code for parsing and executing is given below:
>
> ParserUtil parserUtil = new ParserUtil();
> ExecutionManager execMgr =
> ExecutionManager.getExecutionManager();
> //
> // The parserutil parses and sets the input transformation model
> // for the execution manager.
> //
> File f = new File ("EcoreTest.m2t");
> MOFScriptSpecification spec = parserUtil.parse(f, true);
> // check for errors:
> int errorCount = ParserUtil.getModelChecker().getErrorCount();
> Iterator errorIt = ParserUtil.getModelChecker().getErrors(); //
> Iterator of MofScriptParseError objects
>
> System.out.println ("Parsing result: " + errorCount + "
> errors");
> if (errorCount > 0) {
>
> for (;errorIt.hasNext();) {
> MofScriptParseError parseError = (MofScriptParseError)
> errorIt.next();
> System.out.println("\t \t: Error: " +
> parseError.toString());
> }
> return;
> }
>
>
>
> // load source model
> XMIResourceFactoryImpl _xmiFac = new
> XMIResourceFactoryImpl(); EObject sourceModel = null;
> File sourceModelFile = new File ("SM.ecore");
> ResourceSet rSet = new ResourceSetImpl ();
>
> rSet.getResourceFactoryRegistry().getExtensionToFactoryMap() .put( "*",
> _xmiFac);
> URI uri = URI.createFileURI(sourceModelFile.getAbsolutePath());
> Resource resource = rSet.getResource(uri, true);
>
> if (resource != null) {
> if (resource.getContents().size() > 0) {
> sourceModel = (EObject) resource.getContents().get(0);
> }
> }
>
> // set the source model for the exeution manager
> execMgr.addSourceModel(sourceModel);
> // sets the root output directory, if any is desired (e.g.
> "c:/temp")
> execMgr.setRootDirectory("");
> // if true, files are not generated to the file systsm, but
> populated into a filemodel
> // which can be fetched afterwards. Value false will result in
> standard file generation
> execMgr.setUseFileModel(false);
> // Turns on/off system logging execMgr.setUseLog(false);
> // Adds an output listener for the transformation execution.
> execMgr.getExecutionStack().addOutputMessageListener(this);
> try {
>
> execMgr.executeTransformation();
> } catch (MofScriptExecutionException mex) {
> mex.printStackTrace();
> }
>
>
>
>
>
> Gabriel Merin Cubero wrote:
>
>> Hi! I have several MOFSCRIPT transformations but I would like to
>> invoke them directly form my Java code, instead of using MOFSCRIPT
>> interface. Hence, the user of my plug-in would be able to accomplish a
>> transformation by means of right-click or just a button-click.
>
>> Does anyone know how to accomplish this? Any hint? I've seen another
>> post with the same problem but it does not have any reply.
>
>> Thanks in advance,
>> Gabriel Merin
>
Re: How to invoke MOFSCRIPT from java code.. [message #378271 is a reply to message #375596] Wed, 27 June 2007 10:38 Go to previous message
beaperez Mising name is currently offline beaperez Mising nameFriend
Messages: 81
Registered: July 2009
Member
Hello,
I am trying to do the same, but I have a main trnasformation which imports
several transformations. When I run the java file (using File f = new File
( main.m2t");) I get several errors, such as:

Error: MTTParseError: Cannot find import: second.m2t, line: 7, column: 7
.....
If I run the main transformation using the MOFSCRIPT interface it works, but
not if I invoke them directly from my java code.
Any hint?

Thanks in advance



"Jon Oldevik" <jon.oldevik@sintef.no> escribi
Re: How to invoke MOFSCRIPT from java code.. [message #560461 is a reply to message #375594] Thu, 02 November 2006 12:50 Go to previous message
Jon Oldevik is currently offline Jon OldevikFriend
Messages: 17
Registered: July 2009
Junior Member
Hi,

This is documented by an example in the latest MOFScript documentation
(see http://www.eclipse.org/gmt/mofscript/doc/ or
http://www.modelbased.net/mofscript/docs/MOFScript-User-Guid e.pdf).

Example code for parsing and executing is given below:

ParserUtil parserUtil = new ParserUtil();
ExecutionManager execMgr = ExecutionManager.getExecutionManager();
//
// The parserutil parses and sets the input transformation model
// for the execution manager.
//
File f = new File ("EcoreTest.m2t");
MOFScriptSpecification spec = parserUtil.parse(f, true);
// check for errors:
int errorCount = ParserUtil.getModelChecker().getErrorCount();
Iterator errorIt = ParserUtil.getModelChecker().getErrors(); // Iterator
of MofScriptParseError objects

System.out.println ("Parsing result: " + errorCount + " errors");
if (errorCount > 0) {

for (;errorIt.hasNext();) {
MofScriptParseError parseError = (MofScriptParseError) errorIt.next();
System.out.println("\t \t: Error: " + parseError.toString());
}
return;
}



// load source model
XMIResourceFactoryImpl _xmiFac = new XMIResourceFactoryImpl();
EObject sourceModel = null;
File sourceModelFile = new File ("SM.ecore");
ResourceSet rSet = new ResourceSetImpl ();
rSet.getResourceFactoryRegistry().getExtensionToFactoryMap() .put( "*",
_xmiFac);
URI uri = URI.createFileURI(sourceModelFile.getAbsolutePath());
Resource resource = rSet.getResource(uri, true);

if (resource != null) {
if (resource.getContents().size() > 0) {
sourceModel = (EObject) resource.getContents().get(0);
}
}

// set the source model for the exeution manager
execMgr.addSourceModel(sourceModel);
// sets the root output directory, if any is desired (e.g. "c:/temp")
execMgr.setRootDirectory("");
// if true, files are not generated to the file systsm, but populated
into a filemodel
// which can be fetched afterwards. Value false will result in standard
file generation
execMgr.setUseFileModel(false);
// Turns on/off system logging
execMgr.setUseLog(false);
// Adds an output listener for the transformation execution.
execMgr.getExecutionStack().addOutputMessageListener(this);
try {

execMgr.executeTransformation();
} catch (MofScriptExecutionException mex) {
mex.printStackTrace();
}





Gabriel Merin Cubero wrote:

> Hi! I have several MOFSCRIPT transformations but I would like to invoke
> them directly form my Java code, instead of using MOFSCRIPT interface.
> Hence, the user of my plug-in would be able to accomplish a
> transformation by means of right-click or just a button-click.

> Does anyone know how to accomplish this? Any hint? I've seen another
> post with the same problem but it does not have any reply.

> Thanks in advance,
> Gabriel Merin
Re: How to invoke MOFSCRIPT from java code.. [message #560474 is a reply to message #375596] Thu, 02 November 2006 15:27 Go to previous message
Gabriel Merin Cubero is currently offline Gabriel Merin CuberoFriend
Messages: 12
Registered: July 2009
Junior Member
Thank you very much Jon! It's been a great help.

Regards,
Gabriel Merin Cubero

Jon Oldevik escribió:
> Hi,
>
> This is documented by an example in the latest MOFScript documentation
> (see http://www.eclipse.org/gmt/mofscript/doc/ or
> http://www.modelbased.net/mofscript/docs/MOFScript-User-Guid e.pdf).
> Example code for parsing and executing is given below:
>
> ParserUtil parserUtil = new ParserUtil();
> ExecutionManager execMgr =
> ExecutionManager.getExecutionManager();
> //
> // The parserutil parses and sets the input transformation model
> // for the execution manager.
> //
> File f = new File ("EcoreTest.m2t");
> MOFScriptSpecification spec = parserUtil.parse(f, true);
> // check for errors:
> int errorCount = ParserUtil.getModelChecker().getErrorCount();
> Iterator errorIt = ParserUtil.getModelChecker().getErrors(); //
> Iterator of MofScriptParseError objects
>
> System.out.println ("Parsing result: " + errorCount + "
> errors");
> if (errorCount > 0) {
>
> for (;errorIt.hasNext();) {
> MofScriptParseError parseError = (MofScriptParseError)
> errorIt.next();
> System.out.println("\t \t: Error: " +
> parseError.toString());
> }
> return;
> }
>
>
>
> // load source model
> XMIResourceFactoryImpl _xmiFac = new
> XMIResourceFactoryImpl(); EObject sourceModel = null;
> File sourceModelFile = new File ("SM.ecore");
> ResourceSet rSet = new ResourceSetImpl ();
>
> rSet.getResourceFactoryRegistry().getExtensionToFactoryMap() .put( "*",
> _xmiFac);
> URI uri = URI.createFileURI(sourceModelFile.getAbsolutePath());
> Resource resource = rSet.getResource(uri, true);
>
> if (resource != null) {
> if (resource.getContents().size() > 0) {
> sourceModel = (EObject) resource.getContents().get(0);
> }
> }
>
> // set the source model for the exeution manager
> execMgr.addSourceModel(sourceModel);
> // sets the root output directory, if any is desired (e.g.
> "c:/temp")
> execMgr.setRootDirectory("");
> // if true, files are not generated to the file systsm, but
> populated into a filemodel
> // which can be fetched afterwards. Value false will result in
> standard file generation
> execMgr.setUseFileModel(false);
> // Turns on/off system logging execMgr.setUseLog(false);
> // Adds an output listener for the transformation execution.
> execMgr.getExecutionStack().addOutputMessageListener(this);
> try {
>
> execMgr.executeTransformation();
> } catch (MofScriptExecutionException mex) {
> mex.printStackTrace();
> }
>
>
>
>
>
> Gabriel Merin Cubero wrote:
>
>> Hi! I have several MOFSCRIPT transformations but I would like to
>> invoke them directly form my Java code, instead of using MOFSCRIPT
>> interface. Hence, the user of my plug-in would be able to accomplish a
>> transformation by means of right-click or just a button-click.
>
>> Does anyone know how to accomplish this? Any hint? I've seen another
>> post with the same problem but it does not have any reply.
>
>> Thanks in advance,
>> Gabriel Merin
>
Re: How to invoke MOFSCRIPT from java code.. [message #602112 is a reply to message #375596] Wed, 27 June 2007 10:38 Go to previous message
beaperez Mising name is currently offline beaperez Mising nameFriend
Messages: 81
Registered: July 2009
Member
Hello,
I am trying to do the same, but I have a main trnasformation which imports
several transformations. When I run the java file (using File f = new File
( main.m2t");) I get several errors, such as:

Error: MTTParseError: Cannot find import: second.m2t, line: 7, column: 7
.....
If I run the main transformation using the MOFSCRIPT interface it works, but
not if I invoke them directly from my java code.
Any hint?

Thanks in advance



"Jon Oldevik" <jon.oldevik@sintef.no> escribi
Previous Topic:[MOFScript] Java Integration - Parse Error
Next Topic:[MOFScript] Java integration
Goto Forum:
  


Current Time: Thu Mar 28 13:53:01 GMT 2024

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

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

Back to the top