2012-08-30 81 views
0

我正在開發一個具有多個插件的rcp項目,並且我在應用程序中使用AJDT aspectJ作爲日誌記錄目的。我爲信息日誌記錄創建了兩個方面,一個用於每個插件中的異常日誌記錄.Aspect對基本插件工作正常,但不適用於其他插件。爲eclipse RCP項目中的多個插件創建方面

我有關於上述實施幾個疑問:

  1. 這是定義一個方面爲每個插件以正確的方式,或者我們可以爲所有插件的一個方面
  2. 如果包名是相同的不同的插件是爲每個插件創建分離方面的問題。
  3. 我試圖爲正常的日誌記錄和異常日誌記錄創建一個方面,但不適合我。附加正常方面和例外方面的樣本。
  4. 是否有任何方式來定義一個方面而不提供包名,我認爲我提到了它在創建問題的切入點中的包名。

我得到以下錯誤,如果有每個插件的一個方面:

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); 

    } 
} 

}

請幫助我在做什麼我的錯誤。

回答

1

可能你的切入點RvsFrameworkExceptionAspect只是建議你想排除的類。具體來說,

within(com.tsystems.rvs..*)

將匹配

com.tsystems.rvs.client.gui.user.RvsUserAspect

即你勸告另一方面,因爲它似乎。試着更具體一些你想要攔截的東西。


編輯關於在評論你的另一個問題:

你可以,如果你的各方面都試試這個有「看點」結尾的類名:

within(com.tsystems.rvs..*) && !within(*..*Aspect)

否則你可以排除單個方面的類,或者只包含更少的非方面類,不管在你的情況下更簡單。一般來說,如果不知道您的完整代碼庫,很難提供有用的提示,所以請理解我可能無法完全按照您的意願實現目標。 ;-)

+0

可以請你引導一些例子。 – Gaurav

+0

我編輯了答案並希望它有幫助。 – kriegaex

相關問題