Package org.springframework.aop.framework

Examples of org.springframework.aop.framework.ProxyFactory


    proxy.doSomething();
    assertGetTransactionAndCommitCount(4);
  }

  public void testWithSingleMethodOverrideInverted() {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTarget(new TestWithSingleMethodOverrideInverted());
    proxyFactory.addAdvice(this.ti);

    TestWithSingleMethodOverrideInverted proxy = (TestWithSingleMethodOverrideInverted) proxyFactory.getProxy();

    proxy.doSomething();
    assertGetTransactionAndCommitCount(1);

    proxy.doSomethingElse();
View Full Code Here


    proxy.doSomething();
    assertGetTransactionAndCommitCount(4);
  }

  public void testWithMultiMethodOverride() {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTarget(new TestWithMultiMethodOverride());
    proxyFactory.addAdvice(this.ti);

    TestWithMultiMethodOverride proxy = (TestWithMultiMethodOverride) proxyFactory.getProxy();

    proxy.doSomething();
    assertGetTransactionAndCommitCount(1);

    proxy.doSomethingElse();
View Full Code Here

    assertGetTransactionAndCommitCount(4);
  }


  public void testWithRollback() {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTarget(new TestWithRollback());
    proxyFactory.addAdvice(this.ti);

    TestWithRollback proxy = (TestWithRollback) proxyFactory.getProxy();

    try {
      proxy.doSomethingErroneous();
      fail("Should throw IllegalStateException");
    }
View Full Code Here

      assertGetTransactionAndRollbackCount(2);
    }
  }

  public void testWithInterface() {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTarget(new TestWithInterfaceImpl());
    proxyFactory.addInterface(TestWithInterface.class);
    proxyFactory.addAdvice(this.ti);

    TestWithInterface proxy = (TestWithInterface) proxyFactory.getProxy();

    proxy.doSomething();
    assertGetTransactionAndCommitCount(1);

    proxy.doSomethingElse();
View Full Code Here

    proxy.doSomething();
    assertGetTransactionAndCommitCount(4);
  }

  public void testCrossClassInterfaceMethodLevelOnJdkProxy() throws Exception {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTarget(new SomeServiceImpl());
    proxyFactory.addInterface(SomeService.class);
    proxyFactory.addAdvice(this.ti);

    SomeService someService = (SomeService) proxyFactory.getProxy();

    someService.bar();
    assertGetTransactionAndCommitCount(1);

    someService.foo();
View Full Code Here

    someService.fooBar();
    assertGetTransactionAndCommitCount(3);
  }

  public void testCrossClassInterfaceOnJdkProxy() throws Exception {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setTarget(new OtherServiceImpl());
    proxyFactory.addInterface(OtherService.class);
    proxyFactory.addAdvice(this.ti);

    OtherService otherService = (OtherService) proxyFactory.getProxy();

    otherService.foo();
    assertGetTransactionAndCommitCount(1);
  }
View Full Code Here

    TestBean1 tb = new TestBean1();
    CallCountingTransactionManager ptm = new CallCountingTransactionManager();
    AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource();
    TransactionInterceptor ti = new TransactionInterceptor(ptm, tas);

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setInterfaces(new Class[] {ITestBean.class});
    proxyFactory.addAdvice(ti);
    proxyFactory.setTarget(tb);
    ITestBean proxy = (ITestBean) proxyFactory.getProxy();
    proxy.getAge();
    assertEquals(1, ptm.commits);

    ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
    serializedProxy.getAge();
View Full Code Here

public class HelloServiceProxyFactory implements FactoryBean {
   
    public Object getObject() throws Exception {

        return new ProxyFactory(HelloService.class, new HelloServiceInterceptor()).getProxy();
    }
View Full Code Here

{

   public Object locateBean(String beanName, Class targetType)
   {
      TargetSource targetSource = new LocatorTargetSource(beanName, targetType);
      ProxyFactory proxyFactory = new ProxyFactory();
      proxyFactory.addInterface(targetType);
      proxyFactory.setTargetSource(targetSource);
      return proxyFactory.getProxy();
   }
View Full Code Here

   * @param beanKey the key associated with this bean in the beans map
   * @return the <code>ObjectName</code> under which the bean was registered
   * with the <code>MBeanServer</code>
   */
  private ObjectName registerLazyInit(String beanName, String beanKey) throws JMException {
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setProxyTargetClass(true);
    proxyFactory.setFrozen(true);

    if (isMBean(this.beanFactory.getType(beanName))) {
      // A straight MBean... Let's create a simple lazy-init CGLIB proxy for it.
      LazyInitTargetSource targetSource = new LazyInitTargetSource();
      targetSource.setTargetBeanName(beanName);
      targetSource.setBeanFactory(this.beanFactory);
      proxyFactory.setTargetSource(targetSource);

      Object proxy = proxyFactory.getProxy(this.beanClassLoader);
      ObjectName objectName = getObjectName(proxy, beanKey);
      if (logger.isDebugEnabled()) {
        logger.debug("Located MBean '" + beanKey + "': registering with JMX server as lazy-init MBean [" +
            objectName + "]");
      }
      doRegister(proxy, objectName);
      return objectName;
    }

    else {
      // A simple bean... Let's create a lazy-init ModelMBean proxy with notification support.
      NotificationPublisherAwareLazyTargetSource targetSource = new NotificationPublisherAwareLazyTargetSource();
      targetSource.setTargetBeanName(beanName);
      targetSource.setBeanFactory(this.beanFactory);
      proxyFactory.setTargetSource(targetSource);

      Object proxy = proxyFactory.getProxy(this.beanClassLoader);
      ObjectName objectName = getObjectName(proxy, beanKey);
      if (logger.isDebugEnabled()) {
        logger.debug("Located simple bean '" + beanKey + "': registering with JMX server as lazy-init MBean [" +
            objectName + "]");
      }
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.