using AspectJ or Spring Aop (doesn't matter), is it possible to intercept a method only if that method is called from within a certain class?
example:
public class House() {
String address;
public House(String address) {
this.address = address;
}
public String getAddress() {
return this.address();
}
}
public class BadHouse() {
public void doNotIntercept() {
House h = new House("1234");
h.getAddress();
}
}
public class GoodHouse() {
public void intercept() {
House h = new House("4567");
h.getAddress();
}
}
public class houseInterceptor() {
@Before("execution(com.example.House.getAddress(..))")
// only intercept on GoodHouse.class???
public void beforeGetAddress();
}
Can "within" be used in this circumstance? Thank you