Professional Documents
Culture Documents
1 Introduction
O. Nierstrasz et al. (Eds.): MoDELS 2006, LNCS 4199, pp. 170–184, 2006.
c Springer-Verlag Berlin Heidelberg 2006
A Slice of MDE with AOP 171
vocabulary of interest and are based on the typical modeling elements that all
data modeling approaches have in common: class, attribute, method and associ-
ation. In this paper we present examples in the domain of e-commerce in which
we identify some typical domain entities used in the rest of this paper: Shop,
ShoppingBasket, Customer and ShopAccount are domain classes; ShopAccount
defines the amountSpent domain attribute, ShoppingBasket defines the applyDis-
count(discount) domain method and associations exist relating Customer with
ShopAccount and ShoppingBasket.
i.e. applying the rules at certain events and gathering the necessary information
for their application. At the implementation level, rule connections crosscut the
core application and therefore AOP is a good technique for encapsulating it,
as identified and addressed in previous work [2, 4, 5, 8]. This work has shown
that the aspects that encapsulate the rule connections are built up of the same
elements, that vary with certain situations: rule application time, contextual
information and activation time. As such, we identified several aspect patterns for
implementing different kinds of business rule connections. Although these aspect
patterns achieve the decoupling of rule connections, they are entirely expressed
at the programming level, and thus cannot be understood by the domain expert.
Moreover, as many different issues need to be taken into account as part of the
connection aspects, it becomes hard for the application engineer to write these
aspects. Thus, as the same issues recur in every connection aspect, we propose
abstracting them in high-level features of a high-level rule connection language.
This language allows expressing rule connections as separate and explicit entities
at the domain level. Separating rules from their connections (also at the domain
level) allows reusing both parts independently. Moreover, we do not only propose
new high-level abstractions but also provide a set of variations for each different
issue involved in the definition of the rule connections:
the receiver and the result of invoking the domain method are available. 2) the
rule requires information that is not available in the context of the connection
event: in order to capture this unavailable information, capture points are defined
as an extra component of the connection specification, as follows: CAPTURE
AT event1, ..., eventN, where event1, ..., eventN are names of events that
capture the moment when the required information is reachable, and expose
it. Moreover, the rule connection language allows specifying how the available
or captured information needs to be mapped to the information required by
the rule by linking the two in mapping specifications of the form: MAPPING
event.infoExposed TO infoRequired.
The example below specifies that the BRDiscount rule should only be con-
sidered in the context of an express checkout (a special kind of checkout which
uses payment information already stored in the shop and that does not require
validation by the client). CheckoutExpress is a high-level event capturing the in-
vocation of a domain method mapped to the checkoutExpress(Customer) method
defined in the class Shop.
CONNECT BRDiscount PROPS 100
BEFORE Checkout
MAPPING Checkout.basket TO basket
ACTIVATE WHILE CheckoutExpress
In the previous section we described how high-level rules are defined in terms of
high-level domain entities of a domain model. Our approach aims at generating
executable rules from those high-level specifications. Thus, in order to generate
an implementation for the rules which is ready to be integrated with an existing
core application, the high-level entities involved in the rule definition, need to be
mapped to the implementation. We briefly describe this mapping, although it is
not the focus of this paper. Given a domain entity, defining this mapping requires
pointing out which entity or entities in the existing application implement that
domain concept. If this is the case, a one-to-one mapping exists between the
domain entity and the concrete implementation entities. These one-to-one map-
pings are the only ones supported in current high-level languages [13, 16, 19, 10].
However, the definition of the mapping can become more sophisticated when it
is not possible to identify existing implementation entities realizing the desired
domain concept. In this case we say that the mapping is unanticipated or that
176 M.A. Cibrán and M. D’Hondt
B around() {
rule:
rule.setX(thisJoinPointObject);
X IS 'new value'
BEFORE event if (rule.condition()) {
1 rule.action(); //X assigned by action
MAPPING event.targetObject TO X return proceed(rule.getX(), args0); //new target
} else return proceed(); //proceed normally
}
rule:
before() {
X IS 'new
w val
value'
rule.setX(thisJoinPointObject);
2 if (rule.condition())
rule.action();
}
around() {
rule.setX(args0[j]);
rule: //param i in event's domain method maps to param j of connectionMethod
BEFORE event X IS 'new value' if (rule.condition()) {
1 rule.action(); //X assigned by action
MAPPING event.param_i TO X args0[j] = rule.getX());//replace original param at j
}
return proceed(thisJoinPointObject, args0);
}
rule: before() {
X IS 'new
ew value
vvalue' rule.setX(args0[j]);
2 if (rule.condition())
rule.action();
}
around() {
C
Object result = proceed();
rule: i rule.setX(result);
AFTER event X IS 'new
ew va
value' if (rule.condition()){
1 rule.action();
MAPPING event.returnValue TO X rule: ii return result; i
X IS 'new value' return rule.getX(); ii
} else return proceed();
}
after() {
if (rule.condition()){
AFTER event 2
rule.action();
}
D around() {
if (rule.condition()){
INSTEAD OF event
rule.action();
return rule.getX();
MAPPING event.returnValue TO X } else return proceed();
}
Fig. 1. A: Transformations (1) and (2); B, C and D: Transformations (2) and (3)
Aspect weaving consists of merging the aspects with the base implementation of
the system.
In this section we present the automatic transformation from high-level rule
connections to aspects (based on the patterns identified in previous work). The
use of AOP in this transformation is completely transparent for the domain
expert, as the AOP peculiarities are not exposed in the high-level rule connection
language (as described in Section 2.2). We illustrate this transformation using
JAsCo [18], a dynamic AOP language that introduces two concepts: an aspect
bean which is able to specify crosscutting behavior in a reusable way by means
178 M.A. Cibrán and M. D’Hondt
of one or more logically related hooks, and a connector responsible for deploying
the reusable crosscutting behavior in a specific context and declaring how several
of these aspects collaborate.
Table 1 gives an overview of the proposed transformations in our approach:
each high-level feature is translated into an AOP implementation. However, we
observe and show that these transformations cannot be analyzed independently
of each other, as dependences exist between them. Due to the lack of space, we
illustrate this situation only describing transformations (1), (2) and (3) in detail.
Note however that all of the listed transformations have been implemented.
specified and thus when the construct (2) comes into place. Part A of Figure 1
depicts the combination of transformations (1) and (2).
As mentioned before, transformation (2) generates an advice in charge of
applying the rule. However, depending on the case of a BEFORE, AFTER or
INSTEAD OF connection, a different kind of advice has to be generated. More-
over, determining the kind of advice also depends on whether the contextual
information — passed to the rule using the MAPPING clause — is assigned
to a new value in the rule. This implies the existence of dependencies between
transformations (2) and (3) as their outputs cannot be analyzed independently
of each other. The following three cases are considered, as depicted in parts B,
C and D of Figure 1 (underlined lines correspond to transformation (3) whereas
the rest corresponds to transformation (2)):
B) If the rule is connected before the connection event, then two cases are pos-
sible:
1) the information available in the context of the connection event is passed
to the rule where it is assigned to a new value: we need to be able to access
the contextual domain objects and make them available for the rule, trigger
the rule’s action where the domain objects are assigned to new values, and
retrieve the modified information from the rule to be taken into account
in the invocation of the original behavior captured by the connection event.
Thus, an around advice is created for this purpose, since it allows intercepting
the application at a certain point, adding some extra business logic and
proceeding with the original execution, eventually considering a different
target object and parameters.
2) the contextual information is passed to the rule and not assigned by the
rule: in this case, a before advice suffices to trigger the rule’s action, as the
original event execution does not need to be modified.
C) If the rule is connected after an event, then two cases are possible:
1) the result of invoking the event is passed to the rule: in this case, an around
advice is created which first invokes the original behavior captured by the
event and passes the result of that execution to the rule. Two cases are
possible regarding the return value of the around advice: i) if in the rule the
passed value is assigned to a new value, then the around advice returns that
new value; ii) otherwise, the original result is returned.
2) no result is passed to the rule: an after advice suffices to trigger the rule’s
action, after the execution of the connection event.
D) If a rule is connected instead of the execution of the connection event: the
original execution has to be replaced by the rule’s action. This is achieved in
an around advice which invokes the rule’s action and does not proceed with the
original execution.
4 Implementation
The entire domain model has been implemented supporting the definition of
domain entities, high-level rules and their connections, as explained in section
2. Parsers for the presented rule and connection languages have been imple-
mented using JavaCC. Following the transformations described in 3.2 and 3.3,
high-level rules are automatically translated into Java classes and high-level rule
connections are automatically translated into JAsCo aspect beans and connec-
tors. During this implementation, the following challenges were tackled:
5 Related Work
High-level rule languages are proposed in some existing approaches [13, 16, 19,
10]. However, in these approaches rules are expressed in terms of high-level
domain concepts that are simply aliases for implementation entities and thus
A Slice of MDE with AOP 181
6 Discussion
know that aspects ultimately affect the existing application at run time even if
this is not visible in the source code. The more mature AO approaches provide
excellent tool support for showing the impact of aspects in a base application.
The same mature AO approaches have an acceptable performance overhead,
especially if one knows which are the costly features to avoid.
A second important issue is the scalability of our approach, in particular when
the number of rules grows. As always, scalability depends largely on the quality
of the tool support. Since this paper identifies, argues and presents the funda-
mental concepts of our approach, we feel that tool support and a quantitative
evaluation is outside its scope. Note, however, such an evaluation of our approach
is currently undertaken using an industrial application in the healthcare domain,
where a huge amount of business rules on healthcare regulations, medications
and so on is present. One of the concerns with respect to scalability is the size of
the domain model in terms of the number of rules. We have found that a set of
business rules typically considers the same domain entities, even if the reference
to some attributes or methods on these entities may vary between the rules.
Therefore, an initial effort is required for building the domain model, whereas a
much smaller effort is required for adapting the domain model as new rules are
added. In [3], a paper that focusses on the domain model and how it is mapped
to the implementation, we discuss possible tools that automate the construction
of the initial domain model.
Another issue related to the scalability of our approach with numerous rules,
is rule interference. In previous work we investigated current AO approaches and
their support for combining rule connection aspects at the implementation level
[4,2,5]. As such, we could extend our high-level languages with explicit constructs
for specifying rule precedence and so on. However, with large amounts of rules,
manually detecting and resolving dependencies is not scalable. Therefore, we
are currently investigating alternative techniques such as critical pair analysis
for automatically, exhaustively and statically determining dependencies between
rules. Since our high-level languages have a limited number of constructs and
use elements from the domain model, such an analysis technique is feasible.
Although in this paper we opted for illustrating the proposed transformations
using JAsCo, their implementation is not bound to the specific features of this
particular technology. We build on the common AOP concepts (i.e. aspect, ad-
vice and joinpoint) and therefore, any other AOP approach that supports the
pointcut-advice model can be used as well. As with JAsCo, in case the chosen
AOP technology is dynamic (i.e. aspects can be added or removed at run-time),
the hot deployment of rules is achieved. Otherwise, in the case of a static AOP
technology, explicit support must exist in the high-level connection language to
be able to dynamically deploy and undeploy rules.
The choice of constructs of our high-level languages is the result of extensive
previous work [2, 4, 5]. As such we are able to express the business rules that we
find in the applications of our industrial partners as well as the ones presented
in books on business rules [11, 17]. However, special business rules, for example
that have time-dependent conditions, cannot be expressed and this is subject
A Slice of MDE with AOP 183
7 Conclusion
In this paper we proposed an approach that combines MDE and AOSD in order
to automatically translate high-level business rules to OOP programs and their
connections to aspects in charge of integrating them with existing object-oriented
applications. Moving to a higher level of abstraction improves understandability
as it becomes possible to easily reason about the rule and connection concerns in
terms of the domain. Moreover, it is possible for the domain expert to add, mod-
ify and remove rules. Furthermore, the use of AOP in the transformations allows
us to keep the implementation of the rules and their connections well modularized
and localized, without invasively changing the existing core application. More-
over, as the mapping from high-level entities to their implementation is made
explicit, rule traceability becomes possible. This work also contributes to raising
the level of abstraction of common AOP constructs, at the same time keeping
domain experts oblivious to the use of AOP. Finally, the use of a dynamic AOP
approach enhances run-time adaptability and variability, as it becomes possible
to dynamically adapt the behavior of the core application by simply plugging in
different sets of business rules, creating different versions of the same applica-
tion. A prototype implementation of our approach as well as a discussion on its
advantages and limitations were presented.
Acknowledgements. This work was carried out during the tenure of Maja
D’Hondt’s ERCIM fellowship.
References
1. A. Arsanjani. Rule object 2001: A Pattern Language for Adaptive and Scalable
Business Rule Construction. 2001.
2. M. A. Cibrán, M. D’Hondt, and V. Jonckers. Aspect-Oriented Programming for
Connecting Business Rules. In Proceedings of BIS International Conference, Col-
orado Springs, USA, June 2003.
3. M. A. Cibrán, M. D’Hondt, and V. Jonckers. Mapping high-level business rules to
and through aspects. L’Objet, 12(2-3), Sept. 2006 (to appear).
4. M. A. Cibrán, M. D’Hondt, D. Suvée, W. Vanderperren, and V. Jonckers. JAsCo
for Linking Business Rules to Object-Oriented Software. In Proceedings of CSITeA
International Conference, Rio de Janeiro, Brazil, June 2003.
5. M. A. Cibrán, D. Suvée, M. D’Hondt, W. Vanderperren, and V. Jonckers. Inte-
grating Rules with Object-Oriented Software Applications using Aspect-Oriented
Programming. In Proceedings of ASSE’04, Argentine Conference on Computer
Science and Operational Research, Córdoba, Argentina, 2004.
184 M.A. Cibrán and M. D’Hondt