Examples of TargetSource


Examples of org.springframework.aop.TargetSource

    }

    // Create proxy here if we have a custom TargetSource.
    // Suppresses unnecessary default instantiation of the target bean:
    // The TargetSource will handle target instances in a custom fashion.
    TargetSource targetSource = getCustomTargetSource(beanClass, beanName);
    if (targetSource != null) {
      this.targetSourcedBeans.add(beanName);
      Object[] specificInterceptors = getAdvicesAndAdvisorsForBean(beanClass, beanName, targetSource);
      return createProxy(beanClass, beanName, specificInterceptors, targetSource);
    }
View Full Code Here

Examples of org.springframework.aop.TargetSource

    // We can't create fancy target sources for directly registered singletons.
    if (this.customTargetSourceCreators != null &&
        this.beanFactory != null && this.beanFactory.containsBean(beanName)) {
      for (int i = 0; i < this.customTargetSourceCreators.length; i++) {
        TargetSourceCreator tsc = this.customTargetSourceCreators[i];
        TargetSource ts = tsc.getTargetSource(beanClass, beanName);
        if (ts != null) {
          // Found a matching TargetSource.
          if (logger.isDebugEnabled()) {
            logger.debug("TargetSourceCreator [" + tsc +
                " found custom TargetSource for bean with name '" + beanName + "'");
View Full Code Here

Examples of org.springframework.aop.TargetSource

      }
    }

    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(ClassUtils.getAllInterfacesForClass(targetSource.getTargetClass()));
    }

    this.proxy = getProxy(proxyFactory);
  }
View Full Code Here

Examples of org.springframework.aop.TargetSource

  /**
   * Creates lazy proxies for the <code>JMXConnector</code> and <code>MBeanServerConnection</code>
   */
  private void createLazyConnection() {
    this.connectorTargetSource = new JMXConnectorLazyInitTargetSource();
    TargetSource connectionTargetSource = new MBeanServerConnectionLazyInitTargetSource();

    this.connector = (JMXConnector)
        new ProxyFactory(JMXConnector.class, this.connectorTargetSource).getProxy(this.beanClassLoader);
    this.connection = (MBeanServerConnection)
        new ProxyFactory(MBeanServerConnection.class, connectionTargetSource).getProxy(this.beanClassLoader);
View Full Code Here

Examples of org.springframework.aop.TargetSource

* @author Juergen Hoeller
*/
public class LazyCreationTargetSourceTests extends TestCase {

  public void testCreateLazy() {
    TargetSource targetSource = new AbstractLazyCreationTargetSource() {
      protected Object createObject() {
        return new InitCountingBean();
      }
      public Class getTargetClass() {
        return InitCountingBean.class;
      }
    };

    InitCountingBean proxy = (InitCountingBean) ProxyFactory.getProxy(targetSource);
    assertEquals("Init count should be 0", 0, InitCountingBean.initCount);
    assertEquals("Target class incorrect", InitCountingBean.class, targetSource.getTargetClass());
    assertEquals("Init count should still be 0 after getTargetClass()", 0, InitCountingBean.initCount);

    proxy.doSomething();
    assertEquals("Init count should now be 1", 1, InitCountingBean.initCount);

View Full Code Here

Examples of org.springframework.aop.TargetSource

    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    bf.registerBeanDefinition("ts", tsBd);
    bf.registerBeanDefinition("person", bd);

    TestTargetSource cpts = (TestTargetSource) bf.getBean("ts");
    TargetSource serialized = (TargetSource) SerializationTestUtils.serializeAndDeserialize(cpts);
    assertTrue("Changed to SingletonTargetSource on deserialization",
        serialized instanceof SingletonTargetSource);
    SingletonTargetSource sts = (SingletonTargetSource) serialized;
    assertNotNull(sts.getTarget());
  }
View Full Code Here

Examples of org.springframework.aop.TargetSource

    pf.addAdvice(new DebugInterceptor());
    pf.setExposeProxy(true);
    final ITestBean proxy = (ITestBean) createProxy(pf);
    Advised config = (Advised) proxy;
    // This class just checks proxy is bound before getTarget() call
    config.setTargetSource(new TargetSource() {
      public Class getTargetClass() {
        return TestBean.class;
      }

      public boolean isStatic() {
View Full Code Here

Examples of org.springframework.aop.TargetSource

     * be returned from this method.
     */
    public static Object getRealBean(Object proxy) throws Exception
    {
        Advised advised = (Advised) proxy;
        TargetSource targetSource = advised.getTargetSource();
        Object real = targetSource.getTarget();
       
        // Possibly we could add a method on the ScopedBeanTargetSource class to test
        // whether the target bean exists. Then here we could cast TargetSource to
        // ScopedBeanTargetSource and return null if the target does not exist. This
        // might be useful, but let's leave that until someone actually has a use-case
View Full Code Here

Examples of org.springframework.aop.TargetSource

    protected Class getRealClassInternal(Object o) {
        if (AopUtils.isAopProxy(o)) {
            Advised advised = (Advised)o;
            try {
                TargetSource targetSource = advised.getTargetSource();
               
                Object target = null;
               
                try {
                    target = targetSource.getTarget();
                } catch (BeanCreationException ex) {
                    // some scopes such as 'request' may not
                    // be active on the current thread yet
                    return getRealClassFromClassInternal(targetSource.getTargetClass());
                }
               
                if (target == null) {
                    Class targetClass = AopUtils.getTargetClass(o);
                    if (targetClass != null) {
View Full Code Here

Examples of org.springframework.aop.TargetSource

    }

    // Create proxy here if we have a custom TargetSource.
    // Suppresses unnecessary default instantiation of the target bean:
    // The TargetSource will handle target instances in a custom fashion.
    TargetSource targetSource = getCustomTargetSource(beanClass, beanName);
    if (targetSource != null) {
      this.targetSourcedBeans.add(beanName);
      Object[] specificInterceptors = getAdvicesAndAdvisorsForBean(beanClass, beanName, targetSource);
      Object proxy = createProxy(beanClass, beanName, specificInterceptors, targetSource);
      this.proxyTypes.put(cacheKey, proxy.getClass());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.