Run MWE2 workflow from java project [message #674443] |
Thu, 26 May 2011 23:21 |
|
Hi,
I want to load my xtext-DSL-defined model back into eclipse (directly, without going via xmi) to be able to use it in a Java project. For now within the IDE in same project.
Option 1 is to make a component which can gain access to the slot variable which org.eclipse.xtext.mwe.Reader fills. The component would be written in java as in the hello world example in the xtext manual and started from the workflow.
In this approach I can run the "Hello world" example, but I dont know how to extend it so that instead of message="Helloworld" I could pass the model (which xtext.mwe.Reader delivers in the slot"), i.e instead of
SayHello {
message = "Hello World!"
}
I think it could look like
component = org.eclipse.xtext.mwe.Reader {
//useJavaClassPath = true
// or define search scope explicitly
path = modelPath
// this class will be generated by the xtext generator
register = dk.reson.RIDLStandaloneSetup {}
load = {
slot = "xmodel"
type = "R_IDL"
}
}
component WorkOnMyModel { // defined in java project
LoadedModel = "xmodel"
}
Unfortunately I could not make that work.(could not find syntax and mechanism for passing "xmodel".
Option 2 would be to let my java program run a workflow containing the mwe.Reader shown above. My Java code looks like this
public static void runGenerateXSD(R_IDLImpl MyModel ) {
ProgressMonitor monitor = new NullProgressMonitor();
Map<String, String> properties = new HashMap<String, String>();
Map<String, R_IDLImpl> slotContents = new HashMap<String, R_IDLImpl>();
WorkflowRunner workflowRunner = new WorkflowRunner();
slotContents.put("xmodel", MyModel);
properties.put("outlet_path", "./src-gen");
String workflowFile = "./src/workflow/ModelLoader.mwe2";
workflowRunner.run(workflowFile, monitor, properties, slotContents);
}
and the workflow looks like this
module workflow.ModelLoader
import org.eclipse.emf.mwe.utils.*
import org.eclipse.xpand2.output.*
import ridl.ridlPackage
import org.eclipse.xtext.generator.validation.JavaValidatorFragment
import ridl.*
var targetDir = "src-gen"
var fileEncoding = "UTF-8"
var modelPath = "/home/anders/runtime-EclipseApplication/test"
Workflow {
component = org.eclipse.xtext.mwe.Reader {
//useJavaClassPath = true
// or define search scope explicitly
path = modelPath
// this class will be generated by the xtext generator
register = dk.reson.RIDLStandaloneSetup {}
load = {
slot = "xmodel"
type = "R_IDL"
}
}
component = org.eclipse.xpand2.Generator {
metaModel = org.eclipse.xtend.typesystem.emf.EmfMetaModel {
metaModelPackage = "ridl.RidlPackage"
}
expand = "templates::DFD_Overview::main FOREACH xmodel"
outlet = {
path = targetDir
}
fileEncoding = fileEncoding
}
}
No syntax errors or the like.
When running the workflow with RunAs, it works without problems.
When running it from the java project(above) I get this:
0 [main] INFO eclipse.emf.mwe.core.WorkflowRunner - --------------------------------------------------------------------------------------
135 [main] INFO eclipse.emf.mwe.core.WorkflowRunner - EMF Modeling Workflow Engine 1.0.2, Build v201102150556
135 [main] INFO eclipse.emf.mwe.core.WorkflowRunner - (c) 2005-2009 openarchitectureware.org and contributors
135 [main] INFO eclipse.emf.mwe.core.WorkflowRunner - --------------------------------------------------------------------------------------
135 [main] INFO eclipse.emf.mwe.core.WorkflowRunner - running workflow: ./src/workflow/ModelLoader.mwe2
135 [main] INFO eclipse.emf.mwe.core.WorkflowRunner -
208 [main] ERROR rnal.core.ast.parser.WorkflowParser - Content is not allowed in prolog.
org.xml.sax.SAXParseException: Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1414)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1039)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:198)
at org.eclipse.emf.mwe.internal.core.ast.parser.WorkflowParser.parse(WorkflowParser.java:76)
at org.eclipse.emf.mwe.internal.core.ast.util.WorkflowFactory.parseAndInitialize(WorkflowFactory.java:105)
at org.eclipse.emf.mwe.internal.core.ast.util.WorkflowFactory.parseInitAndCreate(WorkflowFactory.java:59)
at org.eclipse.emf.mwe.internal.core.ast.util.WorkflowFactory.parseInitAndCreate(WorkflowFactory.java:52)
at org.eclipse.emf.mwe.core.WorkflowRunner.prepare(WorkflowRunner.java:332)
at org.eclipse.emf.mwe.core.WorkflowRunner.run(WorkflowRunner.java:290)
at ridlDebug.RidlTool.runGenerateXSD(RidlTool.java:33)
at ridlDebug.RidlTool.main(RidlTool.java:18)
246 [main] ERROR eclipse.emf.mwe.core.WorkflowRunner - [ERROR]: Content is not allowed in prolog.(Element: ./src/workflow/ModelLoader.mwe2; Reported by: -UNKNOWN-)
246 [main] ERROR eclipse.emf.mwe.core.WorkflowRunner - Workflow interrupted because of configuration errors.
What can be wrong?
Which option is simplest to make work? 1 or 2
Should I use MWE or MWE2runner when calling from JAVA?
On top of that, I tried to remove the xpand component from the workflow as in this case I don't need to expand. However, then I can't even run the workflow from RunAs. Should there be something else than the xpand component in the workflow?
Help Appreciated,
|
|
|
|
Re: Run MWE2 workflow from java project [message #674707 is a reply to message #674493] |
Sat, 28 May 2011 00:46 |
|
Thanks Alex,
No I was not aware of that document. I clearly searched for the wrong terms (and actually wrong concepts). Too complicated, which I also thought in the first place.
Your reference solved the problem in a few lines of code, only I could not make the example work out of the box.
I ran into
Unresolved proxy ... Make sure the EPackage has been registered.
Another post reported this solved by
MyPackagePackageImpl.init();
Whether this is the "right" solution, or something else should have been done.
Thanks. Saved my day (and night)
Anders
|
|
|
Powered by
FUDForum. Page generated in 0.03126 seconds