Package org.aopalliance.intercept

Examples of org.aopalliance.intercept.MethodInvocation


      this.targetClass = targetClass;
    }

    public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
      Object retVal = null;
      MethodInvocation invocation = new CglibMethodInvocation(proxy, this.target, method, args,
          this.targetClass, this.adviceChain, methodProxy);
      // If we get here, we need to create a MethodInvocation.
      retVal = invocation.proceed();
      retVal = massageReturnTypeIfNecessary(proxy, this.target, method, retVal);
      return retVal;
    }
View Full Code Here


    public DynamicAdvisedInterceptor(AdvisedSupport advised) {
      this.advised = advised;
    }

    public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
      MethodInvocation invocation = null;
      Object oldProxy = null;
      boolean setProxyContext = false;
      Class targetClass = null;
      Object target = null;
      try {
        Object retVal = null;
        if (this.advised.exposeProxy) {
          // Make invocation available if necessary.
          oldProxy = AopContext.setCurrentProxy(proxy);
          setProxyContext = true;
        }
        // May be <code>null</code>. Get as late as possible to minimize the time we
        // "own" the target, in case it comes from a pool.
        target = getTarget();
        if (target != null) {
          targetClass = target.getClass();
        }
        List chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, targetClass);
        // Check whether we only have one InvokerInterceptor: that is,
        // no real advice, but just reflective invocation of the target.
        if (chain.isEmpty() && Modifier.isPublic(method.getModifiers())) {
          // We can skip creating a MethodInvocation: just invoke the target directly.
          // Note that the final invoker must be an InvokerInterceptor, so we know
          // it does nothing but a reflective operation on the target, and no hot
          // swapping or fancy proxying.
          retVal = methodProxy.invoke(target, args);
        }
        else {
          // We need to create a method invocation...
          invocation = new CglibMethodInvocation(proxy, target, method, args,
              targetClass, chain, methodProxy);
          // If we get here, we need to create a MethodInvocation.
          retVal = invocation.proceed();
        }

        retVal = massageReturnTypeIfNecessary(proxy, target, method, retVal);
        return retVal;
      }
View Full Code Here

    // consistent with return of MethodInvocationProceedingJoinPoint
    ProxyMethodInvocation pmi = null;
    Object targetObject = null;
    Object thisObject = null;
    try {
      MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation();
      targetObject = mi.getThis();
      if (!(mi instanceof ProxyMethodInvocation)) {
        throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
      }
      pmi = (ProxyMethodInvocation) mi;
      thisObject = pmi.getProxy();
View Full Code Here

   * (in an around advice).
   * @return current AspectJ joinpoint, or through an exception if we're not in a
   * Spring AOP invocation.
   */
  public static JoinPoint currentJoinPoint() {
    MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation();
    if (!(mi instanceof ProxyMethodInvocation)) {
      throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
    }
    ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
    JoinPoint jp = (JoinPoint) pmi.getUserAttribute(JOIN_POINT_KEY);
View Full Code Here

  /**
   * Get the current join point match at the join point we are being dispatched on.
   */
  protected JoinPointMatch getJoinPointMatch() {
    MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation();
    if (!(mi instanceof ProxyMethodInvocation)) {
      throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
    }
    return getJoinPointMatch((ProxyMethodInvocation) mi);
  }
View Full Code Here

  public void before() throws Throwable{
    MockitoAnnotations.initMocks(this);
    doAnswer(new Answer<Object>() {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable {
        MethodInvocation methodInvocation = (MethodInvocation) invocation.getArguments()[0];
        return methodInvocation.proceed();
      }
    }).when(loguedInterceptor).invoke(any(MethodInvocation.class));
    AopModule aop = new AopModule();
    aop.setLoguedInterceptor(loguedInterceptor);
    injector = Guice.createInjector(new ValidationModule(), new ServerModule(), new Module(), aop, new JpaPersistModule("appEngine"));
View Full Code Here

    ctrl.verify();
  }

  public void testEvenPublicationInterceptor() throws Throwable {
    MockControl invCtrl = MockControl.createControl(MethodInvocation.class);
    MethodInvocation invocation = (MethodInvocation) invCtrl.getMock();

    MockControl ctxCtrl = MockControl.createControl(ApplicationContext.class);
    ApplicationContext ctx = (ApplicationContext) ctxCtrl.getMock();

    EventPublicationInterceptor interceptor =
        new EventPublicationInterceptor();
    interceptor.setApplicationEventClass(MyEvent.class);
    interceptor.setApplicationEventPublisher(ctx);
    interceptor.afterPropertiesSet();

    invocation.proceed();
    invCtrl.setReturnValue(new Object());

    invocation.getThis();
    invCtrl.setReturnValue(new Object());
    ctx.publishEvent(new MyEvent(new Object()));
    ctxCtrl.setDefaultMatcher(new AlwaysMatcher());

    ctxCtrl.replay();
View Full Code Here

    // let's see if the remote invocation object works

    final RemoteBean rb = new RemoteBean();
    final Method setNameMethod = rb.getClass().getDeclaredMethod("setName", new Class[] {String.class});

    MethodInvocation mi = new MethodInvocation() {
      public Method getMethod() {
        return setNameMethod;
      }
      public Object[] getArguments() {
        return new Object[] {"bla"};
View Full Code Here

  public void testNotInvoked() throws Throwable {
    MyThrowsHandler th = new MyThrowsHandler();
    ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
    Object ret = new Object();
    MockControl mc = MockControl.createControl(MethodInvocation.class);
    MethodInvocation mi = (MethodInvocation) mc.getMock();
    mi.proceed();
    mc.setReturnValue(ret, 1);
    mc.replay();
    assertEquals(ret, ti.invoke(mi));
    assertEquals(0, th.getCalls());
    mc.verify();
View Full Code Here

    MyThrowsHandler th = new MyThrowsHandler();
    ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
    assertEquals(2, ti.getHandlerMethodCount());
    Exception ex = new Exception();
    MockControl mc = MockControl.createControl(MethodInvocation.class);
    MethodInvocation mi = (MethodInvocation) mc.getMock();
    mi.proceed();
    mc.setThrowable(ex);
    mc.replay();
    try {
      ti.invoke(mi);
      fail();
View Full Code Here

TOP

Related Classes of org.aopalliance.intercept.MethodInvocation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.