Re: [aspectwerkz-user] defining a new aspect at run-time

Alexandre Vasseur <[email protected]> Mon, 6 Jun 2005 08:31:50 +0200
Newsgroups gmane.comp.java.aspectwerkz.user
Message-ID <[email protected]>
You should definitely use a deployment scope. Your pointcut is very
generic "call( bsh stuff)" and hence it will be quite expensive if you
don't use one.

I would f.e. use:
// in aop.xml visible from classloader "loader" used thereafter
<deployment-scope name="bsh" expression="within(.... place likely to
call stuff...)"/>

// get tge deployment scope (systemID refers to your xml)
DeploymentScope scope = SystemDefinition.getDefinitionFor(loader,
systemId).getDeploymentScope("bsh");

// invoke:
Deployer.deploy(Class aspect, String xmlDef, DeploymentScope scope);

Alex

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.
> 
>