Java – determines which aspects are hooked to a given class

Is it possible to determine which aspects hook to a given class and gain access to its instances?

It's like:

Foo foo = new Foo();
List<Object> aspects = getAllAspectsOf(foo);

Solution

First of all, you may not be able to use the existing aspect API for any such monitoring, because the aspect wrapper intercepts the call, and its specific purpose is to bind not to any specific component, so there is no natural way to detect the intercepted aspect

That is – there may be a way to include aspects in a policy class, but maintaining it is very heavy

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

Aspects are often described as "above your other code" or "weaving", that is, at run time or build time

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

Therefore, given this example of aspect implementation, your code is usually not "aware" of any such aspect - oriented features

However, if you want traceable aspects, you can use standard Java and dependency injection to implement some aspect "like" functions - that is, to implement some cross functions that an aspect will implement by loading the injected modules at runtime... However, I doubt that if you are really doing serious aspect oriented code, Then this method will not meet your aspect - oriented requirements

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>