Xweave

Examples and Tests
Workflow
Simple Aspects
Expression Aspects
Weaving Metamodels

This chapter describes how to use the XWeave model weaver. Please read the following paper to get an understanding of what a model weaver is, at least in our opinion :-)

http://www.voelter.de/data/workshops/AOM2007.pdf

XWeave is still in its early days, so there might be problems and shortcomings. Please report them to the team.

Examples and Tests

Workflow

XWeave comes with a pre-built workflow that can weave the contents of an aspect model into a model that is already stored in a workflow slot. You can of course look at this workflow and construct your own alternative, that, for example, weaves two models that are both already in workflow slots.

So here's how it works, this should be quite obvious:

<workflow>

  <bean class="org.eclipse.mwe.emf.StandaloneSetup" >
    <platformUri value=".."/>
    <registerEcoreFile 
       value="platform:/resource/prj/metamodel.ecore"/>
  </bean>

  <component class="org.eclipse.mwe.emf.Reader">
     <useSingleGlobalResourceSet value="true"/>
     <uri value="platform:/resource/project/modelfile.xmi" />
     <modelSlot value="base" />
  </component>

  <cartridge 
     file="org/openarchitectureware/util/xweave/wf-weave"
     baseModelSlot="base"
     aspectFile="platform:/resource/prj/aspect.xmi"/>

</workflow>

There is a second version of that file that allows you to specify an expression file (I will explain below why you would want to do this). It is called wf-weave-expr.oaw and takes an additional parameter, the expression file. Like so:

<workflow>

  ...

  <cartridge 
     file="org/openarchitectureware/util/xweave/wf-weave"
     baseModelSlot="base"
     aspectFile="platform:/resource/prj/aspect.xmi"
     expressionFile=“myexpressionfileLoadedFromClassPath“/>

</workflow>

Simple Aspects

Simple aspects do not use pointcut expressions. The weaving happens purely based on name equivalence. Here is a simple example. The Entity called Auto in the aspect is woven below the System root. System is present in both the base and the aspect. The matching happens based on that name equivalence.

Figure 37. Weaving models (1)

Weaving models (1)

Here we weave a number of elements:

Figure 38. Weaving models (2)

Weaving models (2)

You don't have to use the same root element. You can do a „submatch“, like this:

Figure 39. Weaving models (3)

Weaving models (3)

Expression Aspects

Here we're merging this Blob thing onto the Person entity. Note, however, that in the aspect the name of the Entity is called $target. The $ sign introduces an expression that returns a single element. In order for this to work, you have to create a .ext file that contains an expression of the same name (of course, without the $ sign). Note that the expression must be parametrized with the type that serves as the root for the base model. Finally, whatever that expression returns will be used as the target for the matching.

Figure 40. Expression aspects (1)

Expression aspects (1)

Here is another example that makes use of expressions, it actually uses two kinds of expressions. The %entities one is a multi-expression. I.e., since it is introduced by the percent sign, it has to return a collection of elements. You can also see the ?name thing as the name of the attribute that is added to each of the entities. It is a String expression; i.e. it has to return a String. It can be used to add any kind of names to the elements. Note that when String expressions are evaluated, the model is already woven! So, as you can see in the example below, you can actually access the Attr's eContainer.

Figure 41. Expression aspects (2)

Expression aspects (2)

Note that you can also use * (the asterisk) as the name of an element. This then matches all instances of that particular type.

Weaving Metamodels

The above examples all weave models (i.e. instances of some kind of meta model). XWeave can also weave meta models (i.e. .ecore files). There's nothing special about that from a user's perspective, so I don't provide examples here (there are some in the tests, however).