0

複数のプラグインを持つ rcp プロジェクトを開発しており、アプリケーションでログを記録するために AJDT アスペクト J を使用しています。各プラグインで情報ログ用と例外ログ用の 2 つのアスペクトを作成しました。アスペクトはベース プラグインでは正常に動作しますが、他のプラグインでは動作しません。

上記の実装に関していくつか質問があります:

  1. これはプラグインごとにアスペクトを定義する正しい方法ですか、それともすべてのプラグインに対して 1 つのアスペクトを作成できますか
  2. パッケージ名が異なるプラグインで同じである場合、プラグインごとに個別のアスペクトを作成する際に問題になります。
  3. 通常のロギングと例外ロギングのアスペクトを作成しようとしましたが、うまくいきませんでした。通常のアスペクトと例外のアスペクトのサンプルを添付します。
  4. パッケージ名を指定せずにアスペクトを定義する方法はありますか? ポイントカットでパッケージ名について言及しているので、問題が発生していると思います。

各プラグインに 1 つの側面がある場合、以下のエラーが発生します。

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

    }
}

}

私の実装で間違っていることを教えてください。

4

1 に答える 1

1

おそらく、あなたのポイントカットはRvsFrameworkExceptionAspect、除外したいクラスにアドバイスしているだけです。具体的には、

within(com.tsystems.rvs..*)

一致します

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

つまり、あなたは別の側面をアドバイスしているようです。傍受したいものについて、もう少し具体的にするようにしてください。


コメントで追加の質問について編集します。

すべてのアスペクトが「Aspect」で終わるクラス名を持っている場合は、これを試すことができます。

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

それ以外の場合は、単一のアスペクト クラスを除外するか、非アスペクト クラスの数を少なくすることができます。一般に、完全なコード ベースを知らずに役立つヒントを提供することは困難です。;-)

于 2012-08-30T12:05:02.270 に答える