View Javadoc

1   /*************************************************
2    * Copyright (c) Shen Li. All rights reserved.  *
3    * http://joyaop.sourceforge.net                *
4    * -------------------------------------------- *
5    * Distributable under LGPL license.            *
6    * See terms of license at gnu.org.             *
7    ************************************************/
8   package net.sf.joyaop.impl.aspect;
9   
10  import net.sf.joyaop.AbstractInterceptor;
11  import net.sf.joyaop.framework.RuntimeAspect;
12  import net.sf.joyaop.impl.InvocationImpl;
13  import net.sf.joyaop.impl.RuntimeAspectInstance;
14  
15  /***
16   * @author Shen Li
17   */
18  public class AbstractGenericInterceptorAspectImpl extends BaseInterceptorAspectImpl {
19      public void setAspectClass(Class aspectClass) {
20          if (!AbstractInterceptor.class.isAssignableFrom(aspectClass)) {
21              throw new IllegalArgumentException("Class " + aspectClass.getName() + " doesn't implement " + AbstractInterceptor.class.getName());
22          }
23          super.setAspectClass(aspectClass);
24      }
25  
26      public RuntimeAspectInstance createRuntimeAspectInstance(Class originalClass) {
27          return new AbstractGenericInterceptorAspectInstance(this, originalClass);
28      }
29  
30      public static class AbstractGenericInterceptorAspectInstance extends RuntimeAspectInstance {
31          public AbstractGenericInterceptorAspectInstance(RuntimeAspect aspect, Class originalClass) {
32              super(aspect, originalClass);
33          }
34  
35          public Object invoke(InvocationImpl invocation) throws Throwable {
36              return ((AbstractInterceptor) getImplementation()).execute();
37          }
38  
39          public boolean allowRecursiveInvocation() {
40              return false;
41          }
42      }
43  }