I have to enforce a policy issuing a warning if items not belonging to a particular category are being added, apart from the three which are allowed and disallowing such additions.....
So far i am able to find the items and issue warning.... but not sure how to stop them from being added.... For Eg.
Allowed categories Shoes and socks
but if i try and add a vegetable item to the inventory it should give me a warning saying "category not allowed../nItem will not be added to inventory"..... and then proceed to the next item....
This is what i've written so far.....
import org.aspectj.lang.*;
public aspect a8 {
boolean check;
pointcut deliverMessage(): call(* ShoppingCart.addItem(..));
pointcut interestingcalls(String categorie): call(Item.new(..)) && args(*, *, categorie);
before(String categorie): interestingcalls(categorie)
{
if(categorie.equals("Shoes"))
{
System.out.println("categorie detect:" +categorie);
}
else if(categorie.equals("socks"))
{
System.out.println("categorie detect:" +categorie);
}
else
{
check=true;
around(categorie);
System.out.println("please check categorie" +categorie);
}
}
around(String categorie): interestingcalls(categorie) {
System.out.println("Start! "+categorie);
proceed(categorie);
System.out.println("End!");
}
}
I know i'm not using the around advice correctly....