I am developing a rcp project having multiple plugins and i am using AJDT aspectJ for logging purpose in the application. I have created two aspects one for info logging and one for exception logging in each plugin.Aspect is working fine for base plugin but it is not working for other plugin.
I am having few queries regarding above implementation:
I am getting below error if having one aspect in each plugin:
Caused by: org.aspectj.lang.NoAspectBoundException: com_tsystems_rvs_client_gui_user_RvsUserAspect
at com.tsystems.rvs.client.gui.user.RvsUserAspect.aspectOf(RvsUserAspect.aj:1)
at com.tsystems.rvs.client.gui.user.RvsUserAspect.<clinit>(RvsUserAspect.aj:27)
Code for normal aspect used to log info msg
public aspect RvsFrameworkAspect {
public pointcut scope(): within(com.tsystems.rvs.client.gui.framework.*);
before() : scope(){
Signature sig=thisJoinPointStaticPart.getSignature();
String infoFormat="Entering ["+sig.getDeclaringType().getName()+"."+sig.getName();
logTrace(infoFormat, thisJoinPointStaticPart, thisEnclosingJoinPointStaticPart);
}
after() : scope(){
Signature sig=thisJoinPointStaticPart.getSignature();
String infoFormat="Leaving ["+sig.getDeclaringType().getName()+"."+sig.getName()+"]";
logTrace(infoFormat, thisJoinPointStaticPart, thisEnclosingJoinPointStaticPart);
}
protected synchronized void logTrace(String info, StaticPart location,
StaticPart enclosing) {
Signature signature = location.getSignature();
String source = signature.getDeclaringTypeName() + ":" +
(enclosing.getSourceLocation().getLine());
LoggerMode.getInstance().logInfo(" " + source + " - " + info);
}
}
Code for log exceptions in plugin
public aspect RvsFrameworkExceptionAspect {
public pointcut scope(): within(com.tsystems.rvs..*);
private Map<Throwable, String> loggedThrowables = new WeakHashMap<Throwable, String>();
after() throwing(Throwable t): scope() {
logThrowable(t, thisJoinPointStaticPart,
thisEnclosingJoinPointStaticPart);
}
before (Throwable t): handler(Exception+) && args(t) && scope() {
logThrowable(t, thisJoinPointStaticPart,
thisEnclosingJoinPointStaticPart);
}
protected synchronized void logThrowable(Throwable t, StaticPart location,
StaticPart enclosing) {
if (!loggedThrowables.containsKey(t)) {
loggedThrowables.put(t, null);
Signature signature = location.getSignature();
String source = signature.getDeclaringTypeName() + ":"
+ (enclosing.getSourceLocation().getLine());
LoggerMode.getInstance().logError(" " + source + " - " + t.toString(), t);
}
}
}
Please help me what i am doing wrong in my implementation.
Probably your pointcut in RvsFrameworkExceptionAspect
is just advising classes you want to exclude. Specifically,
within(com.tsystems.rvs..*)
will match
com.tsystems.rvs.client.gui.user.RvsUserAspect
,
i.e. you are advising another aspect, as it seems. Try to be a little more specific about what you want to intercept.
Edit concerning your additional question in the comment:
You can try this if your aspects all have class names ending with "Aspect":
within(com.tsystems.rvs..*) && !within(*..*Aspect)
Otherwise you can exclude single aspect classes or just include fewer non-aspect classes, whatever is simpler in your case. Generally, it is hard to provide helpful hints without knowing your full code base, so please understand I that might not hit the target as exactly as you might wish. ;-)