Modeling Workflow Engine 2 (MWE2) in Nutshell

mwe2 java

The Modeling Workflow Engine is a tool and language from Eclipse. It's, however, not specific to the Eclipse IDE. MWE comes in two versions: 1 and 2, following the newer will be used. It essentially gives one the ability to call Java Objects in a procedural fashion. The way this works is that one creates a new workflow file (APP_NAME.mwe2) and the Java Classes. Java Classes are called Components by Eclipse.
A workflow could look like

module HelloWorld SayHello { message = "Hello World!" }

and of course it needs the corresponding Component

import org.eclipse.emf.mwe2.runtime.workflow.IWorkflowComponent; import org.eclipse.emf.mwe2.runtime.workflow.IWorkflowContext; public class SayHello implements IWorkflowComponent { private String message = "Default Hello!"; // Getter & Setter are used for the attributes public void setMessage(String message) { this.message = message; } public String getMessage() { return message; } public void invoke(IWorkflowContext ctx) { System.out.println(getMessage()); } public void preInvoke() {} public void postInvoke() {} }

This piece of code will create a new SayHello Object. Set the message, then invoke it. Or, written as code

/* THIS IS NOT GENERATED CODE */ public class HelloWorld { public static void main(String[] args) { SayHello comp1 = new SayHello(); comp1.preInvoke(); comp1.setMessage("Hello World!"); // add all following attributes comp1.invoke(); comp1.postInvoke(); } }

run the workflow

To run this code one can simply use Eclipse, which comes with a Run Configuration. If one would like to run it programmatically he can import the MWE Launcher.

// import org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher; Mwe2Launcher.main(new String[]{"path/to/workflow.mwe2"});

super type

As one can see: every component has to implement IWorkflowComponent and the 3 Methods. This can be simplified by making a common super type.

import org.eclipse.emf.mwe2.runtime.workflow.IWorkflowComponent; import org.eclipse.emf.mwe2.runtime.workflow.IWorkflowContext; public abstract class IWorkflowComponentAdapter implements IWorkflowComponent { @Override public void preInvoke() {} @Override public void invoke(final IWorkflowContext ctx) {} @Override public void postInvoke() {} }

using the adapter the SayHello can be written as

public class SayHello extends IWorkflowComponentAdapter { private String message = "Default Hello!"; /* + Getter & Setter */ @Override public void invoke(IWorkflowContext ctx) { System.out.println(getMessage()); } }

sharing data between components

Sample Component 1

public void invoke(IWorkflowContext ctx) { // the WorkflowContext behaves like a HashMap ctx.put("key", "data") ctx.put("char", 'a') }

Sample Component 2

public void invoke(IWorkflowContext ctx) { String data = (String) ctx.get("key") // "data" Character code = (Character) ctx.get("char") // 'a' }

workflow features

module RichWorkflow /* comments with stars */ // or double slashes // gloabl varriables var inputFile = "model.gmfgen" var shareKey = "Model1" Workflow { // start the first component (this one is in the package "component") component = component.ResourceReader { // an attribute can be a global variable model = shareKey // a string can be any text inside double or single quotes // you can use ${} to reference gloabl variables uri = "inputFolder/${inputFile}" // type numbers like this timeout = 2000 // and booleans delete = true // one may override them again delete = false } // then start the second component component = component.Transformer { model = shareKey // to use lists one has not to the Setter and Getter but rather: // public void addMessage(String message) { message = "Hello again" message = "add me too" // you may also add sub components robot = Robot { name = "bob" age = 1 } } }

Reference

Documentation help.eclipse.org

History Jun 27, 2017