Re: [Nanning-developer] removing pointcuts

Andreas Frei <[email protected]> Tue, 04 May 2004 15:11:42 +0200
Newsgroups gmane.comp.java.nanning.devel
Message-ID <[email protected]>
I added some code to remove interceptors from a Mixin and a pointcut 
from an AspectInstance.

It works for me, haven't done tests with everything else ;-)

Would it also possible to get a Proxy from the AspectInstance with a 
given Classloader. Currently there is only AI.getProxy(). With this I 
can specify which classloader has to be used to load the proxy in. This 
way I can have the nanning.jar in an indepentent classloader.

I am using your nanning in a container, a bit slow but it works quite 
fine. How is the status of this project?

regards,
Andreas

new AI.getProxy(Classloader cl) method
-----------------------------------
     public Object getProxy()
     {
         //        if (proxy == null) {
         //            proxy = 
Proxy.newProxyInstance(getClass().getClassLoader(),
         //                                           (Class[]) 
interfaces.toArray(new Class[0]),
         //                    this);
         //        }
         //        proxy = executeConstructionInterceptors(proxy);

         return getProxy(null);
     }

     //>>/andfrei
     /**
      * Return a Proxy Instance inside the given classloader.
      *
      * @param cl
      * @return
      */
     public Object getProxy(ClassLoader cl)
     {
         if (proxy == null)
         {
             Set interfaces = getInterfaceClasses();

             if (cl == null) cl = getClass().getClassLoader();

             proxy = Proxy.newProxyInstance(cl, (Class[]) interfaces
                     .toArray(new Class[0]), this);
         }
         proxy = executeConstructionInterceptors(proxy);
         return proxy;
     }

remove interceptors from a Mixin
--------------------------------
     public void removeInterceptor(Method method, MethodInterceptor 
interceptor)
     {

         if (methodInterceptors != null)
         {
             List interceptors = (List) methodInterceptors.get(method);
             if (interceptors != null)
             {
                 interceptors.remove(interceptor);

                 if (interceptors.isEmpty())
                     methodInterceptors.remove(method);
             }

             if (methodInterceptors.isEmpty())
                 methodInterceptors = null;

         }

     }

remove a pointcut from an AspectInstance:
-----------------------------------------
     public void clear(AspectInstance instance, MethodInterceptor 
interceptor, Class interceptorClass)
     {
         List mixins = instance.getMixins();
         for (Iterator iterator = mixins.iterator(); iterator.hasNext();) {
             Mixin mixin = (Mixin) iterator.next();
             Method[] methods = mixin.getAllMethods();
             for (int i = 0; i < methods.length; i++) {
                 Method method = methods[i];
                 if (adviseMethod(instance, mixin, method)) {
                     if (interceptor != null) {
                         mixin.removeInterceptor(method, interceptor);
                     } else if (interceptorClass != null) {
                         try {
                             mixin.removeInterceptor(method, 
(MethodInterceptor) interceptorClass.newInstance());
                         } catch (Exception e) {
                             throw new AspectException(e);
                         }
                     } else {
                         throw new AssertionException("interceptor or 
class needs to be specified");
                     }
                 }
             }
         }
     }

Jon Tirsen wrote:
> I don't think there currently is such an API, no. Why do you need to 
> remove interceptors?
> It should be really easy to add though.
> 
> Andreas Frei wrote:
> 
>> Hi
>>
>> How can I remove advised poincuts in an AspectInstance? Is there an 
>> API for removing a MethodInterceptor?
>>
>> thanks,
>> Andreas
>>
>>
>> -------------------------------------------------------
>> This SF.Net email is sponsored by: Oracle 10g
>> Get certified on the hottest thing ever to hit the market... Oracle 
>> 10g. Take an Oracle 10g class now, and we'll give you the exam FREE.
>> http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
>> _______________________________________________
>> Nanning-developer mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/nanning-developer
> 
> 
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by: Oracle 10g
> Get certified on the hottest thing ever to hit the market... Oracle 10g. 
> Take an Oracle 10g class now, and we'll give you the exam FREE.
> http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
> _______________________________________________
> Nanning-developer mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/nanning-developer
> 


-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click