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: