Greetings,
I need to craft a pointcut to identify code which does not
adhere to a specific design pattern. Here is the pattern:
1. Assume an interface is defined as follows:
public interface MyProcessor{
public void process();
}
2. Assume a marker annotation has been defined called
"OkToIgnore".
3. Classes implementing the MyProcessor inteface must follow
the these rules:
A) The
process() method must be defined on this class (and each subclass) individually
(cannot rely on superclass to provide implementation).
B) Every public
attribute (defined directly on the class in question -- the one implementing
the interface) as well as every private attribute with a public or protected
accessor method (again, defined directly on the class implementing the
interface) must satisfy one of the following:
i)
The attribute is marked with the
"OkToIgnore" annotation.
ii) The
attribute (if public) or the public getter must be called/accessed within the
scope of the "process()" method defined on this class.
If one of (i) or (ii) is not satisfied, then I want to fail
compilation or log a message or some similar action to be implemented in the
advice. The action is not that important at this point – my challenge is
with defining the pointcut.
Note that the same rules must also apply to subclasses of
any class implementing the interface -- but these subclasses must define the
process() method themselves and must "process" their own attributes
(the ones defined directly on themselves) within that process method.
Is this even possible? If so, any help on how to define the
best pointcut for this scenario would be greatly appreciated! I am open to any
reasonable refactoring that might need to be done to enable this sort of
checking as well if that would help. I'd prefer not to have to refactor or add
extra code to the classes if at all possible though.
I look forward to your help with this challenge!!! Thanks in
advance!
Peter