Introduction

The modeling workflow engine is a declarative configurable generator engine. It provides a simple, XML based configuration language with which all kinds of generator workflows can be described. A generator workflow consists of a number of so-called workflow components that are executed sequentially in a single JVM.

Workflow components

At the heart of the workflow engine lies the WorkflowComponent. A WorkflowComponent represents a part of a generator process. Such parts are typically model parsers, model validators, model transformers and code generators. MWE ships with different WorkflowComponents which should be used where suitable, but you can also implement your own. The only thing you have to do is to implement the org.eclipse.emf.mwe.core.WorkflowComponent interface:

The invoke() operation performs the component's actual work. checkConfiguration is used to check whether the component is configured correctly before the workflow starts. More on these two operations later.

A workflow description consists of a list of configured WorkflowComponents.

The workflow shown above consists of three different workflow components. The order of the declaration is important! The workflow engine will execute the components in the specified order. To allow the workflow engine to instantiate the workflow component classes, WorkflowComponent implementations must have a default constructor.

Workflow

A workflow is just a composite implementation of the WorkflowComponent interface. The invoke and checkConfiguration methods delegate to the contained workflow components.

The Workflow class declares an adder() method

public void addComponent(WorkflowComponent comp)

which is used by the workflow factory in order to wire up a workflow (see next section 'Workflow Configuration').

Workflow Components with IDs

If you want your workflow components to have an ID (so that you can recognize its output in the log) you have to implement the interface WorkflowComponentWithID and the setID() and getID() operations. Alternatively, you can also extend the base class AbstractWorkflowComponent, which handles the ID setter/getter for you.

More convenience

AbstractWorkflowComponent has a property called skipOnErrors. If set to true, it will not execute if the workflow's issues collection contains errors. This is convenient if you want to be able to skip code generation when the preceding model verification finds errors. Note that instead of implementing invoke(...), subclasses of AbstractWorkflowComponent have to implement invokeInternal(...). This is necessary to allow the framework to intercept the invocation and stop it when there are errors in the workflow.

Workflow Configuration

A workflow is wired up using an XML configuration language based on the dependency injection pattern (DI). Here is an example (not working, just an example!):

First there is a simple property baseDir with the value "." defined. This property can be used in any attributes in the workflow file. The second property statement imports a property file. Property files use the well-known Java properties file syntax. There is one feature we added: You can use previously declared properties inside the properties file.

Example:

model = myModel
pathToModel = ${baseDir}/${model}.xmi

Components

The wired up object graph consists of so called components (A workflow component is a special kind of a component). A component is declared by an XML element. The name represents the property of the parent component holding this component.

Example:

<component class='MyBean'>
<bean class='MyBean'/>
</component>

The Java class MyBean needs to have a corresponding property accessor. E.g.:

There are currently the following possibilities for declaring the property accessors:

Accessor methods

As we have seen, one possibility for declaring a dependency is to declare a corresponding setter Method.

public void set<propertyname>(<PropertyType> e)

If you want to set multiple multiple values for the same property, you should define an adder method.

public void add<propertyname>(<PropertyType> e)

In some cases you may want to have key value pairs specified. This is done by providing the following method:

public void put(Object k,Object v)

Component creation

The corresponding Java class (specified using the class attribute) needs to have a default constructor declared. If the class attribute is omitted, the Java class determined from the accessor method will be used. For the preceding example we could write...

<component class='MyBean'>
<bean/>
</component>

...because the setter method uses the MyBean type as its parameter type. This is especially useful for more complex configurations of workflow components.

Note that we will probably add factory support in the future.

References

A component can have an attribute id. If this is the case we can refer to this component throughout the following workflow configuration.

In this example an object with the id mm (an instance of my.MetaModel), is first declared and then referenced using the attribute idRef. Note that this object will only be instantiated once and then reused. It is not allowed to specify any other attributes besides idRef for object references.

Simple Parameters

Elements with only one attribute value are simple parameters. Simple parameters may not have any child elements.

Both methods are equivalent, although declaring an attribute way saves a few keystrokes. However, the attributes class, id and file are reserved so they cannot be used.

Parameters are injected unsing the same accessor methods as described for components. The only difference is that they are not instantiated using a default constructor but instead using a so called converter.

Converters

There are currently converter implementations registered for the following Java types:

Object

String

String[] (uses s.split(','))

Boolean (both primitive and wrapper)

Integer (both primitive and wrapper)

Including other workflow files (a.k.a cartridges)

If an element has a property file it is handled as an inclusion. Using an inclusion one can inject a graph described in another workflow file. Here is an example:

file 1: mybean.mwe

<anyname class='MyClass'/>

file 2: workflow.mwe

<comp class='MyBean'>
<bean file='mybean.mwe'/>
</comp>

One can pass properties and components into the included file in the usual way.

As you can see simple parameters are mapped to properties in the included workflow file and components can be accessed using the idRef attribute.

Properties defined in the included workflow description will be overwritten by the passed properties.

The root element of a workflow description can have any name, because there is no parent defining an accessor method. Additionally you have to specify the attribute class for a root element. There is only one exception: If the root element is named workflow the engine knows that it has to instantiate the type org.eclipse.emf.mwe.internal.core.Workflow. Of course you can specify your own subtype of org.eclipse.emf.mwe.internal.core.Workflow using the class attribute (if you need to for any reason).

InheritAll Feature

If you don't want to explicitely pass the parameters to an included workflow description, you can use the inheritAll attribute. This will make all the properties and beans that are visible to the actual workflow file also visible to the included workflow file.

<component file="my/included/workflow.mwe" inheritAll="true"/>

Component Implementation and Workflow Execution

This section describes how to implement workflow components, how they can communicate with each other and how the workflow execution can be controlled.

The Workflow Context

Workflow components have to communicate among each other. For example, if an XMIReader component reads a model that a constraint checker component wants to check, the model must be passed from the reader to the checker. The way this happens is as follows. In the invoke operation, a workflow component has access to the so-called workflow context. This context contains any number of named slots. In order to communicate, two components agree on a slot name, the first component puts an object into that slot and the second component takes it from there. Basically, slots are named variables global to the workflow. The slot names are configured from the workflow file. Here is an example:

As you can see, both these workflow components use the slot named model. Below is the (abbreviated) implementation of the XmiReader. It stores the model data structure into the workflow context in the slot whose name was configured in the workflow file.

Issues

Issues provide a way to report errors and warnings. There are two places where issues are used in component implementations:

Inside the checkConfiguration operation, you can report errors or warnings. This operation is called before the workflow starts running.

Inside the invoke operation, you can report errors or warnings that occur during the execution of the workflow. Typical examples are constraint violations.

The Issues API is pretty straightforward: you can call addError and addWarning. The operations have three parameters: the reporting component, a message as well as the model element that caused the problem, if there is one. The operations are also available in a two-parameter version, omitting the first (reporting component) parameter.

Controlling the Workflow

There is an implicit way of controlling the workflow: if there are errors reported from any of the checkConfiguration operations of any workflow component, the workflow will not start running!

There is also an explicit way of terminating the execution of the workflow: if any invoke operation throws a WorkflowInterruptedException (a runtime exception) the workflow will terminate immediately.

Workflow AO

It is sometimes necessary to enhance existing workflow component declarations with additional properties. This is exemplified in the Template AOP example. To implement such an Advice Component, you have to extend the AbstractWorkflowAdvice class. You have to implement all the necessary getters and setters for the properties you want to be able to specify for that advice; also you have to implement the weave() Operation. In this operation, which takes the advised component as a parameter, you have to set the advised parameters:

In the workflow file things are straight forward: You have to specify the advice's component class to be the advice component, and use the special property adviceTarget to identify the target component: