0% found this document useful (0 votes)
135 views4 pages

AspectJ Pointcut Operators in Java

This experiment demonstrates using the && and || operators in AspectJ pointcut expressions. A ClassTest03 java application and AspectJ03 aspect file are created. The aspect defines a pointcut using || to match calls to setX(), setY(), or move() and && to require the calls occur within ClassTest03. The before advice prints a message for any join point matching the pointcut. Running the application outputs the message at points 1 and 3, showing the pointcut expression is triggered as expected.

Uploaded by

tushar umrao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
135 views4 pages

AspectJ Pointcut Operators in Java

This experiment demonstrates using the && and || operators in AspectJ pointcut expressions. A ClassTest03 java application and AspectJ03 aspect file are created. The aspect defines a pointcut using || to match calls to setX(), setY(), or move() and && to require the calls occur within ClassTest03. The before advice prints a message for any join point matching the pointcut. Running the application outputs the message at points 1 and 3, showing the pointcut expression is triggered as expected.

Uploaded by

tushar umrao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Experiment No.

: 10

Aim: Write a java application with Aspect illustrating the operator && and ||.

Theory:
In this experiment, some classes that participate in many illustrated examples of AspectJ are:
• Box, FigureElement, Group, Line, Point, ShapeFigureElement, SlotFulPoint.

The sources of these classes are from:


[Link]

❖ In AspectJ, pointcut expressions can be combined with the operators && (and), || (or), !
(not).
e.g.: Match all methods with names ending with Manager and DAO

Use '||' sign to combine both expressions.


bean(*Manager) || bean(*DAO)

Steps:
1. The package figures we have already installed in our Eclipse IDE for previous experiment,
and here also we are going to use [Link], [Link] and [Link] class
for our experiment.
2. Create [Link] class file and [Link] aspect file for demonstrating the
experiment work.

3. Now, Start working on code to run java application with fields in AspectJ.
4. Run the Aspect/Java Application file.

5. Now, output of the java application is visible in output console.

Code:
[Link] File
package [Link];
import [Link];
import [Link];
public aspect AspectJ03 {
pointcut moveAction() : ( call(void [Link](int,int)) || call(void
[Link](int)) || call(void [Link](int)) )
&& within (ClassTest03);
before() : moveAction() {
[Link]("before move");
}
}

[Link] file
package [Link];
import [Link];
import [Link];
import [Link];
public class ClassTest03 {
public static void main(String[] args) {
Point point = new Point(10, 200);
[Link]("---- (1) ----");
[Link](20);
[Link]("---- (2) ----");
FigureElement line= new Line (new Point (1,1), new Point (10,10));
[Link](10, 10);
[Link]("---- (3) ----");
}
}
Output:

You might also like