複数のプラグインを持つ rcp プロジェクトを開発しており、アプリケーションでログを記録するために AJDT アスペクト J を使用しています。各プラグインで情報ログ用と例外ログ用の 2 つのアスペクトを作成しました。アスペクトはベース プラグインでは正常に動作しますが、他のプラグインでは動作しません。
上記の実装に関していくつか質問があります:
- これはプラグインごとにアスペクトを定義する正しい方法ですか、それともすべてのプラグインに対して 1 つのアスペクトを作成できますか
- パッケージ名が異なるプラグインで同じである場合、プラグインごとに個別のアスペクトを作成する際に問題になります。
- 通常のロギングと例外ロギングのアスペクトを作成しようとしましたが、うまくいきませんでした。通常のアスペクトと例外のアスペクトのサンプルを添付します。
- パッケージ名を指定せずにアスペクトを定義する方法はありますか? ポイントカットでパッケージ名について言及しているので、問題が発生していると思います。
各プラグインに 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);
}
}
}
私の実装で間違っていることを教えてください。