Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsHow to invoke MOFSCRIPT from java code..
https://www.eclipse.org/forums/index.php/mv/msg/123033/375594/#msg_375594
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]]>Gabriel Merin Cubero2006-11-02T09:14:14-00:00Re: How to invoke MOFSCRIPT from java code..
https://www.eclipse.org/forums/index.php/mv/msg/123033/375596/#msg_375596
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
// 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 {
> 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]]>Jon Oldevik2006-11-02T12:50:44-00:00Re: How to invoke MOFSCRIPT from java code..
https://www.eclipse.org/forums/index.php/mv/msg/123033/560461/#msg_560461
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
// 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 {
> 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]]>Jon Oldevik2006-11-02T12:50:44-00:00Re: How to invoke MOFSCRIPT from java code..
https://www.eclipse.org/forums/index.php/mv/msg/123033/375598/#msg_375598
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
>]]>Gabriel Merin Cubero2006-11-02T15:27:44-00:00Re: How to invoke MOFSCRIPT from java code..
https://www.eclipse.org/forums/index.php/mv/msg/123033/560474/#msg_560474
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
>]]>Gabriel Merin Cubero2006-11-02T15:27:44-00:00Re: How to invoke MOFSCRIPT from java code..
https://www.eclipse.org/forums/index.php/mv/msg/123033/602112/#msg_602112
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]]>beaperez Mising name2007-06-27T10:38:01-00:00Re: How to invoke MOFSCRIPT from java code..
https://www.eclipse.org/forums/index.php/mv/msg/123033/378271/#msg_378271
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?