XWeave is still in its early days, so there might be problems and shortcomings. Please report them to the team.
The usage of XWeave is best explained by examples. Download the XWeave source project. It contains a test folder with various examples. The sources are available as a ZIP package here:
A further sample for XWeave is contained in the bundle
oaw4_screencast_examples.zip that is available at the
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
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 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.
Here we weave a number of elements:
You don't have to use the same root element. You can do a „submatch“, like this:
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.
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.
Note that you can also use * (the asterisk) as the name of an element. This then matches all instances of that particular type.