我正在開發一個具有多個插件的rcp項目,並且我在應用程序中使用AJDT aspectJ作爲日誌記錄目的。我爲信息日誌記錄創建了兩個方面,一個用於每個插件中的異常日誌記錄.Aspect對基本插件工作正常,但不適用於其他插件。爲eclipse RCP項目中的多個插件創建方面
我有關於上述實施幾個疑問:
- 這是定義一個方面爲每個插件以正確的方式,或者我們可以爲所有插件的一個方面
- 如果包名是相同的不同的插件是爲每個插件創建分離方面的問題。
- 我試圖爲正常的日誌記錄和異常日誌記錄創建一個方面,但不適合我。附加正常方面和例外方面的樣本。
- 是否有任何方式來定義一個方面而不提供包名,我認爲我提到了它在創建問題的切入點中的包名。
我得到以下錯誤,如果有每個插件的一個方面:
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)
規範正常的一面用來記錄信息味精
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);
}
}
代碼記錄異常的插件,
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);
}
}
}
請幫助我在做什麼我的錯誤。
可以請你引導一些例子。 – Gaurav
我編輯了答案並希望它有幫助。 – kriegaex