Determine which aspects are attached to this class.

Is it possible to determine what aspects are associated with this class and access their instances?

Something like:

Foo foo = new Foo(); List<Object> aspects = getAllAspectsOf(foo); 
+7
source share
3 answers

First, you probably won’t be able to perform such monitoring using existing Aspect APIs, because wrapper aspects that intercept calls for a specific purpose are NOT bound to any one component, so there wouldn’t be any natural way detecting interception aspects.

Nevertheless, maybe you could wrap up the aspects inside a kind of strategic class, but the amount of work to maintain it would be very significant.

http://www.eclipse.org/aspectj/doc/released/faq.php#q:benefits

Aspects are often described as being “on top” or “woven” with your other code, that is, at run time or build time.

http://asm.ow2.org/users.html

Thus, your code will usually not “know” about any such aspects, given this paradigm for implementing aspects.

However, if you need traceable aspects, you can implement some “like” functions using standard java dependency and dependency injection, that is, by loading injected modules at runtime that implement some cross-cutting functionality that will implement the aspect .. But, I suspect, if you are really doing a serious aspect of oriented code, this approach does not meet your aspect-oriented requirements.

+2
source

I do not think you can, though, it would be technology dependent. As far as I know, there is no way with aspectj or cglib to track and access tips woven around the class. You can create your advice in such a way that it adds a reference to itself in some local stream structure, which can be accessed by an accessible class. However, it would seem that it exceeded the purpose of the aspects as a solution to the problems associated with cross problems if you connect your target classes with them.

+2
source

I assume that in order to get some limited information, weaver needs to be changed to save some log of your work in an extended class so that you can read it later. But don't expect much - AFAIK aspects may not exist, since there are no runtime types at all. I wonder if there is any framework that does this?

0
source

All Articles