Package org.aopalliance.intercept

Examples of org.aopalliance.intercept.MethodInterceptor


        this.bind(ConfigurationState.class).toProvider(ConfigurationStateProvider.class);
        this.bind(ValidatorFactory.class).toProvider(ValidatorFactoryProvider.class);
        this.bind(Validator.class).toProvider(ValidatorProvider.class);

        // AOP stuff
        MethodInterceptor validateMethodInterceptor = new ValidateMethodInterceptor();
        this.binder().requestInjection(validateMethodInterceptor);
        this.bindInterceptor(Matchers.any(), Matchers.annotatedWith(Validate.class), validateMethodInterceptor);
    }
View Full Code Here


/*if[AOP]*/
  public void testToConstructorAndMethodInterceptors() throws NoSuchMethodException {
    final Constructor<D> constructor = D.class.getConstructor(Stage.class);
    final AtomicInteger count = new AtomicInteger();
    final MethodInterceptor countingInterceptor = new MethodInterceptor() {
      public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        count.incrementAndGet();
        return methodInvocation.proceed();
      }
    };
View Full Code Here

    private ApplicationContext applicationContext;

    @Bean
    Authentication currentUser() {
        return ProxyFactory.getProxy(Authentication.class, new MethodInterceptor() {
            @Override
            public Object invoke(MethodInvocation invocation) throws Throwable {
                SecurityContext securityContext = SecurityContextHolder.getContext();
                Authentication authentication = securityContext.getAuthentication();
                if (authentication == null) {
View Full Code Here

  public <T> void hear(TypeLiteral<T> literal, TypeEncounter<T> encounter) {
    Class<? super T> klass = literal.getRawType();

    do {
      for (Method method : klass.getDeclaredMethods()) {
        final MethodInterceptor interceptor = InstrumentedInterceptor.forMethod(metricsSystem, klass, method);
        if (interceptor != null) {
          encounter.bindInterceptor(Matchers.only(method).and(new NotSynthetic()), interceptor);
        }
      }
    } while ((klass = klass.getSuperclass()) != null);
View Full Code Here

    {
        final Class[] interfaces = new Class[]{stack.getServiceInterface()};
        final ClassLoader classLoader = invokingModule.getClassResolver().getClassLoader();
        final Object parameter = parameters.get( 0 );
        Defense.isAssignable( parameter, MethodInterceptor.class, "Implementation Object" );
        MethodInterceptor methodInterceptor = ( MethodInterceptor )parameter;
        final InvocationHandler invocationHandler = new MethodInterceptorInvocationHandler( methodInterceptor, stack );
        stack.push( Proxy.newProxyInstance( classLoader, interfaces, invocationHandler ) );
    }
View Full Code Here

     */
    public void createInterceptor(InterceptorStack stack, Module invokingModule, Object parameters)
    {
        final Object parameter = ((List) parameters).get( 0 );
        Defense.isAssignable( parameter, MethodInterceptor.class, "Implementation Object" );
        MethodInterceptor methodInterceptor = ( MethodInterceptor )parameter;
        createInterceptor(stack, invokingModule, methodInterceptor);
    }
View Full Code Here

        bind( ConfigurationState.class ).toProvider( ConfigurationStateProvider.class ).in( Singleton.class );
        bind( ValidatorFactory.class ).toProvider( ValidatorFactoryProvider.class ).in( Singleton.class );
        bind( Validator.class ).toProvider( ValidatorProvider.class );

        // AOP stuff
        MethodInterceptor validateMethodInterceptor = new ValidateMethodInterceptor();
        requestInjection( validateMethodInterceptor );
        bindInterceptor( any(), annotatedWith( Validate.class ), validateMethodInterceptor );
    }
View Full Code Here

   * creates a proxy that dispatches invocations to the currently bound {@link ProcessInstance}
   *
   * @return shareable {@link ProcessInstance}
   */
  private Object createSharedProcessInstance()   {
    ProxyFactory proxyFactoryBean = new ProxyFactory(ProcessInstance.class, new MethodInterceptor() {
      public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        String methodName = methodInvocation.getMethod().getName() ;

        logger.info("method invocation for " + methodName+ ".");
        if(methodName.equals("toString"))
View Full Code Here

  }

  private Object createDirtyCheckingProxy(final String name, final Object scopedObject) throws Throwable {
    ProxyFactory proxyFactoryBean = new ProxyFactory(scopedObject);
    proxyFactoryBean.setProxyTargetClass(this.proxyTargetClass);
    proxyFactoryBean.addAdvice(new MethodInterceptor() {
      public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        Object result = methodInvocation.proceed();
        persistVariable(name, scopedObject);
        return result;
      }
View Full Code Here

    return Proxy.newProxyInstance(getClass().getClassLoader(), advised.getTargetSource().getInterfaces(), this);
  }

  @Override
  public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
    MethodInterceptor methodInterceptor = advised.getMethodInterceptor();
    if (advised.getMethodMatcher() != null
        && advised.getMethodMatcher().matches(method, advised.getTargetSource().getTarget().getClass())) {
      return methodInterceptor.invoke(new ReflectiveMethodInvocation(advised.getTargetSource().getTarget(),
          method, args));
    } else {
      return method.invoke(advised.getTargetSource().getTarget(), args);
    }
  }
View Full Code Here

TOP

Related Classes of org.aopalliance.intercept.MethodInterceptor

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.