[aspectwerkz-user] Re: defining a new aspect at run-time
Jonas Bonér <[email protected]> Sun, 5 Jun 2005 09:03:05 +0200
| Newsgroups | gmane.comp.java.aspectwerkz.user |
|---|---|
| Message-ID | <[email protected]> |
Hello, I am glad that you like AspectWerkz. What you're trying to do should work. We have test cases that covers the usage. Your problem might be a class loader issue, by default, the deployer only deploys the aspect in the same class loader as the aspect itself, what this means is that, if your user code is higher up in the classloader hierarchy then it will not be weaved. Try to pass in the classloader that your user code lives in as an argument to the deployer API. For example you could try with context classloader or similar (I don't know how your app looks so it's hard to tell exactly). By the way, you know that you had to define a deployment scope, which has scope that is a superset of the scope of the aspect. - Jonas On 6/3/05, [email protected] <[email protected]> wrote: > Hi all, > > After spending some time evaluating aspectJ and aspectwerkz, I decided the > latter was a better fit for my purpose because of its dynamic nature. I was > able to set it up to use native hotswap etc. > > Now I would like to introduce a new aspect at run-time: > > xmlDef="<aspect > class='test.com.ubs.firc.support.aspect.GenericMethodDecorator'> " + > "<pointcut name='allMethods' expression='call(* > bsh.This.toString())'/>" + > "<advice name='decorate' type='around' bind-to='allMethods'/>" + > "</aspect>"; > > h = Deployer.deploy(GenericMethodDecorator.class, xmlDef); > > > Debugging through the AspectWerkz code, this seems impossible. One can only > "change" the definition of an existing aspect, but not introduce a new one > (because JoinPointFactory.COMPILATION_INFO_REPOSITORY is empty). I have no > aop.xml, no aspects or aspect config files whatsoever are declared at > startup. However, I'm sure it worked at some point. Why it worked I have no > idea. After to two lines above, I started trying to get a hold on the aspect > instance calling various 'aspectOf' methods in the Aspects class. The one > that eventually gave me the correct aspect instance was > > a = Aspects.aspectOf(bsh.This.class.getClassLoader(), > "test.com.ubs.firc.support.aspect.GenericMethodDecorator"); > > Anyway, is it in principle possible to do what I'm trying to do? I'm willing > to hack into the AspectWerkz source code if need be.... > > Thanks, > Boris > > Visit our website at http://www.ubs.com > > This message contains confidential information and is intended only > for the individual named. If you are not the named addressee you > should not disseminate, distribute or copy this e-mail. Please > notify the sender immediately by e-mail if you have received this > e-mail by mistake and delete this e-mail from your system. > > E-mail transmission cannot be guaranteed to be secure or error-free > as information could be intercepted, corrupted, lost, destroyed, > arrive late or incomplete, or contain viruses. The sender therefore > does not accept liability for any errors or omissions in the contents > of this message which arise as a result of e-mail transmission. If > verification is required please request a hard-copy version. This > message is provided for informational purposes and should not be > construed as a solicitation or offer to buy or sell any securities or > related financial instruments. > > -- /Jonas