How to invoke MOFSCRIPT from java code.. [message #375594] |
Thu, 02 November 2006 04:14  |
Eclipse User |
|
|
|
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 07:50   |
Eclipse User |
|
|
|
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 10:27   |
Eclipse User |
|
|
|
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 06:38  |
Eclipse User |
|
|
|
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 07:50  |
Eclipse User |
|
|
|
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 10:27  |
Eclipse User |
|
|
|
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 06:38  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03710 seconds