27.03.2014 Views

SEKE 2012 Proceedings - Knowledge Systems Institute

SEKE 2012 Proceedings - Knowledge Systems Institute

SEKE 2012 Proceedings - Knowledge Systems Institute

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1 public aspect XDRUpdate {<br />

2 public pointcut jp (Fig fe ): target(fe)<br />

3 && ( call ( void Fig+. set ∗ (..))) && @annotation (UpdateConcern );<br />

4 public pointcut bcscope (): within (Fig+);<br />

5 public pointcut acscope (): within (∗ Update ∗ );<br />

6 public pointcut xpidrscope(): bcscope () || acscope ();<br />

7 /∗ Grey box specification of the Update concern base code ∗/<br />

8 declare @method: void Point . setX( int ): @UpdateConcern(Method.POINT SETX);<br />

9 declare @method: void Point . setX( int ): @Set(”int Point.x”);<br />

10 /∗ Grey box specification of the Update crosscutting concern code ∗/<br />

11 declare @method: void Display . update (): @UpdateConcern(Method.DISPLAY UPDATE);<br />

12 declare @method: void Update . aroundAdvBody( Fig ): @UpdateConcern(Method.UPDATE AROUND);<br />

13 declare @method: void Update . aroundAdvBody( Fig ): @Requires(”fe != null”);<br />

14 declare @method: void Update . aroundAdvBody( Fig ): @XCall(”public static void Display.update()”);<br />

15 declare @method: void Update . aroundAdvBody( Fig ): @Ensures(”fe != null”);<br />

16 }<br />

Figure 3. An example of the XPIDR for the update concern of the figure editor.<br />

can choose whether or not reveal specif c details of code to<br />

be advised. For example, lines 8−9 explicitly present details<br />

of the base code. So, developers referring this XPIDR<br />

know that the based code specif cally contains a Point .setX<br />

method. Besides that, we can observe that such a method<br />

contains two attached annotation properties.<br />

The former (line 8) is an annotation which can be declared<br />

anywhere. It refers to the update concern that the<br />

system realizes. Furthermore, it provides an enumeration<br />

property (Method.POINT SETX) which specif cally identif<br />

es which particular element of the Update concern it belongs<br />

to (the method Point .setX in this case). We use a<br />

enumeration property because we can mark several methods<br />

and advice of a particular concern.<br />

The latter denotes the set behavioral rule [9]. Hence,<br />

we can exactly specify what f elds must be set within the<br />

method Point .setX. In this case, the design rule on line 9<br />

states that the method Point .setX must have an a assignment<br />

(f eld state change) to the f eld Point .x. Wealsorepresent<br />

behavioral rules as metadata annotations. Thus, the<br />

set design rule is denoted by @Set, which is attached to<br />

the Point .setX method. With XPIDR we can also employ<br />

f ve more design (behavioral) rules. Table 1 presents the<br />

six design rules we draw from LSD [9] and that we made<br />

available by XPIDR. Note that since AspectJ 5, we can attach<br />

(mark) methods using the AspectJ supplying annotation<br />

feature such as declare @method (lines 8−15).<br />

The syntactic part of the XPIDR also exposes other<br />

two methods: (i) the method Display .update in line 11,<br />

and (ii) the method void Update.aroundAdvBody(Fig) in lines<br />

12−15. Both are related to the crosscutting concern code.<br />

The second one (Update.aroundAdvBody) denotes a separate<br />

method to represent an advice since AspectJ does not support<br />

supplying annotations for advice yet. The method<br />

Update.aroundAdvBody is composed by the behavioral rule<br />

@XCall to denote that the advice must have a call to method<br />

Display .update. This mandatory call is also exclusive in the<br />

scope of the XPIDR for the Update concern (since the notation<br />

starts with an ‘x’).<br />

Considering the behavioral contracts, pre- and postcondition<br />

are specif ed in lines 13 and 15 (see Figure 3), respectively.<br />

These conditions state that the target object<br />

(denoted by fe) must be non-null before and after method<br />

Update.aroudAdvBody’s execution. We refer to fe which is<br />

the exposed target Fig object by the pointcut jp. We also<br />

represent behavioral contracts as metadata annotations. We<br />

adopted the work by Boysen [2] in our XPIDR, which already<br />

provide Java 5 annotations for JML [7]. These JML<br />

behavioral contracts as metadata annotations can be also attached<br />

to the base code.<br />

Note that we use simple Java methods to refer to AspectJ<br />

advice since advice declarations in AspectJ are unnamed.<br />

We cannot explicitly refer them in our XPIDR to<br />

attach annotations with design rules. With such a limitation<br />

we rely on simple methods that are supposed to encapsulate<br />

the advice behaviors. For example, to implement the<br />

update concern, we should have an aspect named Update<br />

and according to our XPIDR it must declare the method<br />

Update.aroundAdvBody. Such a method is called from within<br />

an around advice declared in the same aspect Update.<br />

Figure 4 presents a Update aspect (lines 1−14) using our<br />

XPIDR provided in Figure 3. The aspect now depends only<br />

on the abstract public pointcut signatures of XDRUpdate, not<br />

on implementation details of the Fig and Point classes. As<br />

mentioned, we cannot supply annotations for AspectJ advice.<br />

Hence, we also specify the advice declared in the<br />

Update aspect. In line 6 we mark the around advice with<br />

a custom metadata annotation (@AroundAdvice<br />

UpdateConcern). In addition, the around advice (lines<br />

10−13) is specif ed with two behavioral rules. The former<br />

151

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!