Hi,
I try to define aspects for
checking a development rule:
This rule is that on a child of a
class (MotherClass), all the method beginning with âmmâ have to call a method
(which signature is âvoid checkCredentials(String)) in their
body.
A solution for that consists of
using the Advice before instead of the rule. But at this time we wonât use AOP
in production.
In fact the child classes are
facades and we want to be sure that security code will be called ever we call
a façade method.
I donât succeed in writing the
good aspect. At this time I try to find a solution based on static check with
âdeclare errorâ.
My classes are:
package
net.kernevez;
public
abstract class Mother {
public void checkCredentials( String
pRole)
{
if (pRole == null) {
//My code that absolutely need to be called
}
}
}
package
net.kernevez;
public class
AnyChild extends Mother {
public void mmBadMethod(){
System.out.println("ytyt");
}
public void mmGoodMethod() {
checkCredentials(null);
System.out.print("ytyt");
}
public void mGoodMethod() {
System.out.print("ytyt");
}
public void mmGoodMethod2() {
System.out.print("uyiuy");
checkCredentials(null);
}
}
The declaration and point cut
are:
pointcut allMethodToCheck() : within( net.kernevez.Mother+ ) &&
execution( * mm*(..));
pointcut
allMethodWithCredential() : within( net.kernevez.Mother+ ) && call(*
checkCredentials(String));
declare error : allMethodToCheck()&&!allMethodWithCredential() : "In
method called 'mm*' you need to call
checkCredentials()";
The result isnât that I
expected.
Has somebody an idea to solve my
problem ?
Thanks,
Philippe
Kernévez