0
現在、aspectjを使用してロガーを実装しています。今私はどこから選択することができますGUIを持っている、つまり、呼び出しや実行を選択したいと思います。選択に基づいて、AOPは動作し、情報を記録する。AspectJでコンボボックスを使用して呼び出しと実行を選択する方法
これは可能ですか?誰もこれで私を助けることができますか?
現在、aspectjを使用してロガーを実装しています。今私はどこから選択することができますGUIを持っている、つまり、呼び出しや実行を選択したいと思います。選択に基づいて、AOPは動作し、情報を記録する。AspectJでコンボボックスを使用して呼び出しと実行を選択する方法
これは可能ですか?誰もこれで私を助けることができますか?
ポイントカット定義でif()
を使用できます。
私は、次のパッケージ構造とEclipseで新しいAspectJのプロジェクトを作成しました:
package aspectj;
@Aspect
public class MyAspect {
public static boolean call = true;
public static boolean exec = true;
@Pointcut("if() && call(* *.*(..)) && !within(aspectj..*)")
public static boolean callPointcut(JoinPoint jp) {
return call;
}
@Pointcut("if() && execution(* *.*(..)) && !within(aspectj..*)")
public static boolean execPointcut(JoinPoint jp) {
return exec;
}
@After("execPointcut(jp) || callPointcut(jp)")
public void advice(JoinPoint jp){
System.out.println(jp);
}
}
そしてGUI.java:
MyAspect.ajは、次のコードを持っています
package main;
public class GUI {
private JFrame frame;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
GUI window = new GUI();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public GUI() {
initialize();
}
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 328, 109);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
final JCheckBox chckbxCall = new JCheckBox("Call");
chckbxCall.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MyAspect.call = chckbxCall.isSelected();
}
});
chckbxCall.setSelected(true);
chckbxCall.setBounds(6, 6, 128, 23);
frame.getContentPane().add(chckbxCall);
final JCheckBox chckbxExecution = new JCheckBox("Execution");
chckbxExecution.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MyAspect.exec = chckbxExecution.isSelected();
}
});
chckbxExecution.setSelected(true);
chckbxExecution.setBounds(6, 41, 128, 23);
frame.getContentPane().add(chckbxExecution);
JButton btnTestbutton = new JButton("testButton");
btnTestbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("button pressed");
}
});
btnTestbutton.setBounds(172, 5, 117, 29);
frame.getContentPane().add(btnTestbutton);
}
}
希望の証拠として役立つ希望概念。
こんにちは、ありがとうございます。私はそれをやろうとしましたが、チェックボックスを選択すると何も起こりません。私はロギングの出力を得ることはありません。ところで、チェックボックスのコードはどこに置くべきですか?それは側面にありますか? – user1082494
完全に機能的な例を使って答えを更新しました。 – Fred
こんにちはフレッド。機能コードを手伝ってくれてありがとう。これは私をたくさん助けます。しかし、私はこれを外部のjarファイルに適用したい。 EclipseのConfigure Build Pathオプションを使用してインポートする外部jarファイルで.ajファイルを織りたいとします。このコードはそこにも適用されますか?もしそうなら、それを私に見せてもらえますか? – user1082494