[jboss-user] [JBoss AOP] - InterfaceIntroduction with Dynamic AOP

HannesR do-not-reply at jboss.com
Mon Feb 5 18:10:51 EST 2007


I was trying to add an interface introduction to a class during runtime, i.e. by dynamic AOP, but so far without success.
I was able to do it by "static" AOP, i.e. adding the respective tags in the xml files as described in the reference manual or the tutorial.

The important excerpt from my (static) xml-file:

<introduction class="MainClass">
  |     <mixin>
  |     	<interfaces>
  |     		Printable
  |     	</interfaces>
  |     	<class>Printer</class>
  |     	<construction>new Printer(this)</construction>
  |    	</mixin>
  | </introduction>

Intending to use dynamic AOP, I tried it with the following:

MainClass myMainClass = new MainClass();
  | String[] interfaces = {"Printable"};
  | // use InterfaceIntroduction-Constructor found in the API for jboss-aop_1.5.3.GA	
  | InterfaceIntroduction ii = new InterfaceIntroduction("SomeArbitraryName","MainClass", interfaces, "Printer", "new Printer(this)");
  | AspectManager.instance().addInterfaceIntroduction(ii);
  | // use reflection to invoke the method "print" which is implemented by Printer.
  | // this worked using "static" AOP. However it throws an exception now. Therefore
  | // something must have gone wrong :-(
  | try {
  | 	myMainClass.getClass().getMethod("print", null).invoke(myMainClass, null);
  | } catch (Exception e) {
  | 	e.printStackTrace();
  | }

I don't know whether I have to prepare anything for my issue, but I tried both without and with the following: <prepare expr="all(MainClass)"/>

I tried both running in loadtime mode as well as in HotSwap-mode.

Any ideas what I made wrong? Is it possible at all to add an interface introduction using Dynamic AOP?

Thanks in advance for your help!

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4011647#4011647

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4011647

More information about the jboss-user mailing list