Information Technology Reference
In-Depth Information
about weaving code into different points inside the call graph
of a program. Such points are called join points . One specifies
on which join points the contributed code should be executed
by specifying a pointcut ,which is a set of join points.Whenever
the program execution reaches one of the join points described
in the pointcut, a piece of code associated with the pointcut
(called advice ) is executed.
In Xtend, the join points are the invocations to
transformation rules. Xtend provides a mechanism to define
and use around advices . Thus, it is possible to re-use available
transformation rules changing part of their behavior without
modifying any code.
Listing 3.12 presents an example of an advice, which is
weaved around every invocation of the transformation
rule createColumn(AttributemyAtt, TablemyTable) .
This advice is saved as any other Xtend file with extension
.ext , for instance myAdvice.ext . Note that the parameters
of the transformation rule must be also specified in the
pointcut. Inside the advice (line 2), we call the underlying
transformation rule. This is done using the implicit variable
ctx that provides an operation proceed() , which invokes the
underlying transformation rule with the original parameters.
Thus, the advice adds an entry to the execution log indicating
which underlying transformation rule is invoked, and then it
invokes the transformation rule.
1
2
around my: : path :: createColumn(Attribute myAtt, Table myTable):
log( " Invoking " + ctx.name) −> ctx.proceed();
Listing 3.12. Example of an Xtend advice
To weave the defined advice into the selected join points,
one needs to configure the XtendComponent indicating the
(fully qualified) name of the Xtend file containing the advice.
Listing 3.13 presents an example of such a configuration. Note
that in line 13, the workflow definition from Listing 3.11 now
includes the name of the Xtend file containing the advice.
 
Search WWH ::




Custom Search