| To: | "users@xxxxxxxxxx" <users@xxxxxxxxxx> |
|---|---|
| Subject: | AOP Help |
| From: | "Edward Sumerfield" <esumerfd@xxxxxxxxxxxxxx> |
| Date: | Mon, 6 Nov 2006 11:45:53 -0500 |
| Delivered-to: | mailing list users@cinjug.org |
| Domainkey-signature: | a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:sender:to:subject:mime-version:content-type:x-google-sender-auth; b=BjyFRRfVZa6fZ6pOL54vv4KkOaooHVW58xQlBysSAewMwCBxpuhRMfqcBPTJlxvG3VnIEh6JKXY0xhLkqm66BkepqQKPAUEHvDnCAkA4cUWh/czR0mFHl+YNYImbByXOi6kDxLAYu25TCxKf370rvqqRMDDfmawBslkvpSiwKJs= |
| Mailing-list: | contact users-help@cinjug.org; run by ezmlm |
| Reply-to: | esumerfd@xxxxxxxxxxxxxx |
| Sender: | esumerfd@xxxxxxxxx |
|
I am trying to use AspectJ to inject some code into the ui component paint methods but can't seem to get it to match the pointcuts. I am using the annotation format only since I can't use the aspectj compiler and just specifying the aspectj weaver to the interperter when the swing app is started. The code correctly adds advice to code that is in my package but doens't seem to be able to advice methods in the swing code. Here is a simple version of what I have. First a simple frame, panel and button. package com.aop.experiment; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class UiFrame extends JFrame { public static void main(String[] args) { new UiFrame(); } public UiFrame() { JButton button = new JButton("PressMe"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent a_event) { doThePressMeThing(); } }); JPanel panel = new JPanel(); panel.add(button); add(panel); setDefaultCloseOperation(EXIT_ON_CLOSE); setBounds(300, 200, 400, 300); setVisible(true); } /* * This is intercepted by the AOP advice. */ private void doThePressMeThing() { System.out.println("Press me was pressed"); } } My aspect in annotation format. I have three experimental pointcuts in this file. Match all children of Component that call paint, match all children of Component that are the execution of paint and a control that intercepts the button press method. package com.aop.experiment; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; /** * @author Edward Sumerfield */ @Aspect public class UiPaintTrace { @Pointcut("target(a_object) && call(void java.awt.Component+.paint(java.awt.Graphics))") public void paintWithCall(final Object a_object) { } @Before("paintWithCall(a_object)") public void beforePaintWithCall(Object a_object) { System.out.println("Before paintWithCall " + a_object); } @Pointcut("target(a_object) && execution(void java.awt.Component+.paint(java.awt.Graphics))") public void paintWithExecution(final Object a_object) { } @Before("paintWithExecution(a_object)") public void beforePaintWithExecution(Object a_object) { System.out.println("Before paintWithExecution " + a_object); } @Pointcut("target(a_object) && call(void *.doThePressMeThing())") public void pressMe(final Object a_object) { } @Before("pressMe(a_object)") public void beforePressMe(Object a_object) { System.out.println("Before PressMe " + a_object); } } And finally the Meta-INF/aop.xml file that defines what the weaver should use. <aspectj> <aspects> <aspect name="com.aop.experiment.UiPaintTrace" /> </aspects> <weaver options="-verbose -showWeaveInfo"> <include within="com.aop.experiment..*" /> <include within="javax.swing..*" /> <include within="java.awt..*" /> </weaver> </aspectj> When the main is executed and the button pressed I get this output from the weaver. java -javaagent:C:\Edward\aop\lib\aspectjweaver.1.5.2a.jar com.aop.experiment.UiFrame info AspectJ Weaver Version 1.5.2a built on Friday Aug 18, 2006 at 18:40:31 GMT info register classloader sun.misc.Launcher$AppClassLoader@9627532 info using configuration /C:/Edward/aop/output/META-INF/aop.xml info register aspect com.aop.experiment.UiPaintTrace info weaving 'com/aop/experiment/UiFrame' weaveinfo Join point 'method-call(void com.aop.experiment.UiFrame.doThePressMeThing())' in Type 'com.aop.experiment.UiFrame ' (UiFrame.java:45) advised by before advice from 'com.aop.experiment.UiPaintTrace' (UiPaintTrace.java) info AspectJ Weaver Version 1.5.2a built on Friday Aug 18, 2006 at 18:40:31 GMT info register classloader sun.reflect.misc.MethodUtil@6237616 info using configuration /C:/Edward/aop/output/META-INF/aop.xml info register aspect com.aop.experiment.UiPaintTrace info not weaving 'sun/reflect/misc/Trampoline' info weaving 'com/aop/experiment/UiFrame$1' info weaving 'com/aop/experiment/UiPaintTrace' info not weaving 'org/aspectj/lang/NoAspectBoundException' Before PressMe com.aop.experiment.UiFrame[frame0,300,200,400x300,layout=java.awt.BorderLayout,title=,resizable,normal,defaultCloseOperation=EXIT_ON_CLOSE,rootPane= javax.swing.JRootPane[,4,30,392x266,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true] Press me was pressed -- Ed |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | :SPAM: Re: Frie.nd.sh.ip, Jimmy |
|---|---|
| Next by Date: | Hibernate mapping extra data in link tables, twcrone |
| Previous by Thread: | :SPAM: Re: Frie.nd.sh.ip, Jimmy |
| Next by Thread: | Hibernate mapping extra data in link tables, twcrone |
| Indexes: | [Date] [Thread] [Top] [All Lists] |