如果正在添加不属于特定类别的项目,我必须执行一项发出警告的政策,除了允许和禁止此类添加的三个项目......
到目前为止,我能够找到这些项目并发出警告......但不知道如何阻止它们被添加......
例如。
允许的类别 鞋袜
但是如果我尝试将蔬菜项目添加到库存中,它应该会给我一个警告说“不允许的类别../nItem 将不会添加到库存中”......然后继续下一个项目......
这是我到目前为止写的......
pointcut deliverMessage() :
call(* SC.addItem(..));
pointcut interestingCalls(String category) :
call(Item.new(..)) && args(*, *, category);
before(String category): interestingCalls(category) {
if(category.equals("Socks")) {
System.out.println("category detect: " + category);
else if(category.equals("Shoes"))
System.out.println("category detect: " + category);
else {
check=true;
System.out.println("please check category " + category);
}
}