Package org.springframework.aop.framework

Examples of org.springframework.aop.framework.ProxyFactory


class RepositoryInvocationTestUtils {

  @SuppressWarnings("unchecked")
  public static <T> T getVerifyingRepositoryProxy(T target, VerifyingMethodInterceptor interceptor) {

    ProxyFactory factory = new ProxyFactory();
    factory.setInterfaces(target.getClass().getInterfaces());
    factory.setTarget(target);
    factory.addAdvice(interceptor);

    return (T) factory.getProxy();
  }
View Full Code Here


    validate(information, customImplementation);

    Object target = getTargetRepository(information);

    // Create proxy
    ProxyFactory result = new ProxyFactory();
    result.setTarget(target);
    result.setInterfaces(new Class[] { repositoryInterface, Repository.class });

    for (RepositoryProxyPostProcessor processor : postProcessors) {
      processor.postProcess(result, information);
    }

    if (IS_JAVA_8) {
      result.addAdvice(new DefaultMethodInvokingMethodInterceptor());
    }

    result.addAdvice(new QueryExecutorMethodInterceptor(information, customImplementation, target));

    return (T) result.getProxy(classLoader);
  }
View Full Code Here

    private DataSource dataSource;

    public Handle decorate(IDBI idbi, Handle handle) {

        ProxyFactory pf = new ProxyFactory();
        pf.setProxyTargetClass(false);
        pf.setInterfaces(new Class[] {Handle.class});
        pf.setTarget(handle);
        pf.addAdvice(new SQLExceptionTranslatingThrowsAdvice(dataSource));

        Handle proxy = (Handle)pf.getProxy();

        return proxy;
    }
View Full Code Here

    if (this.target == null) {
      throw new IllegalArgumentException("'target' is required");
    }
   
    ProxyFactory proxyFactory = new ProxyFactory();

    if (this.preInterceptors != null) {
      for (int i = 0; i < this.preInterceptors.length; i++) {
        proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(this.preInterceptors[i]));
      }
    }

    if (this.pointcut != null) {
      Advisor advice = new DefaultPointcutAdvisor(this.pointcut, this.resourceInterceptor);
      proxyFactory.addAdvisor(advice);
    }
    else {
      // rely on default pointcut
      proxyFactory.addAdvisor(new ResourceAdvisor(this.resourceInterceptor));
      // Could just do the following, but it's usually less efficient because of AOP advice chain caching.
      // proxyFactory.addInterceptor(transactionInterceptor);
    }

    if (this.postInterceptors != null) {
      for (int i = 0; i < this.postInterceptors.length; i++) {
        proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(this.postInterceptors[i]));
      }
    }

    proxyFactory.copyFrom(this);

    TargetSource targetSource = createTargetSource(this.target);
    proxyFactory.setTargetSource(targetSource);

    if (this.proxyInterfaces != null) {
      proxyFactory.setInterfaces(this.proxyInterfaces);
    }
    else if (!isProxyTargetClass()) {
      // Rely on AOP infrastructure to tell us what interfaces to proxy.
      proxyFactory.setInterfaces(AopUtils.getAllInterfacesForClass(targetSource.getTargetClass()));
    }
   
    this.proxy = proxyFactory.getProxy();
  }
View Full Code Here

  public void testSuccessfulInvocations() throws Exception {

    TestBean target = new TestBean();

    JavaSpaceInterceptor si = new JavaSpaceInterceptor(template);
    ProxyFactory pf = new ProxyFactory(new Class[] { ITestBean.class });
    pf.addAdvice(new PerformanceMonitorInterceptor());
    pf.addAdvice(si);

    ITestBean proxy = (ITestBean) pf.getProxy();

    String oldName = proxy.getName();

    for (int i = 0; i < 2; i++) {
      String name = "john" + i;
View Full Code Here

  }

  private void testThrowable(Throwable t) throws Throwable {

    JavaSpaceInterceptor si = new JavaSpaceInterceptor(template);
    ProxyFactory pf = new ProxyFactory(new Class[] { ITestBean.class });
    pf.addAdvice(new PerformanceMonitorInterceptor());
    pf.addAdvice(si);

    ITestBean proxy = (ITestBean) pf.getProxy();

    try {
      proxy.exceptional(t);
      fail("Should have aborted with exception");
    }
View Full Code Here

  }

  public void testAsynchInterceptor() throws Throwable {
    JavaSpaceInterceptor si = new JavaSpaceInterceptor(template);
    si.setSynchronous(false);
    ProxyFactory pf = new ProxyFactory(new Class[] { ITestBean.class });
    pf.addAdvice(new PerformanceMonitorInterceptor());
    pf.addAdvice(si);

    ITestBean proxy = (ITestBean) pf.getProxy();
    Object result;
    try {
      result = proxy.getName();
      fail("cglib can't proxy final classes");
    }
View Full Code Here

  }

  public void testLazyTest() throws Throwable {
    JavaSpaceInterceptor si = new JavaSpaceInterceptor(template);
    si.setSynchronous(false);
    ProxyFactory pf = new ProxyFactory(new Class[] { ITestBean.class });
    pf.addAdvice(new PerformanceMonitorInterceptor());
    pf.addAdvice(si);
    ITestBean proxy = (ITestBean) pf.getProxy();

    // nothing before the call
    assertNull(template.getSpace().readIfExists(new MethodResultEntry(), template.getCurrentTransaction(), 100));
    ITestBean lazyResult = proxy.getSpouse();
    System.out.println("spouse name is " + lazyResult.getClass());
View Full Code Here

  /**
   * @see junit.framework.TestCase#setUp()
   */
  protected void onSetUp() throws Exception {
    obj = new Object();
    factory = new ProxyFactory(obj);
    //factory.addInterceptor(new EntryMixin());
    factory.addAdvisor(new EntryMixinAdvisor());
    factory.setProxyTargetClass(true);
    proxy = factory.getProxy();
  }
View Full Code Here

  private Object getProxy(Object target, Object[] properties, String[] ognl, String[] mappedNames) {
    TouchingNameMatchMethodAdvisor advisor = new TouchingNameMatchMethodAdvisor();
    advisor.setMappedNames(mappedNames);
    advisor.getTouchingAdvice().setProperties(properties);
    advisor.getTouchingAdvice().setOgnl(ognl);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvisor(advisor);
    return pf.getProxy();
  }
View Full Code Here

TOP

Related Classes of org.springframework.aop.framework.ProxyFactory

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.