Examples of SpringBeanLocator


Examples of org.apache.wicket.spring.SpringBeanLocator

   * @throws Exception
   */
  @Test
  public void testFactory() throws Exception
  {
    SpringBeanLocator locator;
    Object proxy;

    Field field = obj.getClass().getDeclaredField("nobean");
    proxy = factory.getFieldValue(field, obj);
    assertNull(proxy);

    field = obj.getClass().getDeclaredField("beanByClass");
    proxy = factory.getFieldValue(field, obj);
    locator = (SpringBeanLocator)((ILazyInitProxy)proxy).getObjectLocator();
    assertTrue(locator.getBeanType().equals(Bean.class));
    assertTrue(locator.getSpringContextLocator() == mockCtxLocator);
    assertThat(factory.getFieldValue(field, obj), instanceOf(ILazyInitProxy.class));

    field = obj.getClass().getDeclaredField("beanByName");
    proxy = factory.getFieldValue(field, obj);
    locator = (SpringBeanLocator)((ILazyInitProxy)proxy).getObjectLocator();
    assertTrue(locator.getBeanName().equals("somebean"));
    assertTrue(locator.getBeanType().equals(Bean2.class));
    assertTrue(locator.getSpringContextLocator() == mockCtxLocator);
    assertThat(factory.getFieldValue(field, obj), instanceOf(ILazyInitProxy.class));
  }
View Full Code Here

Examples of org.apache.wicket.spring.SpringBeanLocator

   * @throws Exception
   */
  @Test
  public void testFactory() throws Exception
  {
    SpringBeanLocator locator = null;
    Object proxy = null;

    Field field = obj.getClass().getDeclaredField("nobean");
    proxy = factory.getFieldValue(field, obj);
    assertNull(proxy);

    field = obj.getClass().getDeclaredField("beanByClass");
    proxy = factory.getFieldValue(field, obj);
    locator = (SpringBeanLocator)((ILazyInitProxy)proxy).getObjectLocator();
    assertTrue(locator.getBeanType().equals(Bean.class));
    assertTrue(locator.getSpringContextLocator() == mockCtxLocator);
    assertTrue(factory.getFieldValue(field, obj) instanceof ILazyInitProxy);

    field = obj.getClass().getDeclaredField("beanByName");
    proxy = factory.getFieldValue(field, obj);
    locator = (SpringBeanLocator)((ILazyInitProxy)proxy).getObjectLocator();
    assertTrue(locator.getBeanName().equals("somebean"));
    assertTrue(locator.getBeanType().equals(Bean2.class));
    assertTrue(locator.getSpringContextLocator() == mockCtxLocator);
    assertTrue(factory.getFieldValue(field, obj) instanceof ILazyInitProxy);
  }
View Full Code Here

Examples of org.apache.wicket.spring.SpringBeanLocator

      if (beanName == null)
      {
        return null;
      }

      SpringBeanLocator locator = new SpringBeanLocator(beanName, field.getType(),
        contextLocator);

      // only check the cache if the bean is a singleton
      Object cachedValue = cache.get(locator);
      if (cachedValue != null)
      {
        return cachedValue;
      }

      final Object target;
      if (wrapInProxies)
      {
        target = LazyInitProxyFactory.createProxy(field.getType(), locator);
      }
      else
      {
        target = locator.locateProxyTarget();
      }

      // only put the proxy into the cache if the bean is a singleton
      if (locator.isSingletonBean())
      {
        cache.put(locator, target);
      }
      return target;
    }
View Full Code Here

Examples of org.apache.wicket.spring.SpringBeanLocator

      if (beanName == null)
      {
        return null;
      }

      SpringBeanLocator locator = new SpringBeanLocator(beanName, field.getType(),
        contextLocator);

      // only check the cache if the bean is a singleton
      Object cachedValue = cache.get(locator);
      if (cachedValue != null)
      {
        return cachedValue;
      }

      Object target;
      try
      {
        // check whether there is a bean with the provided properties
        target = locator.locateProxyTarget();
      }
      catch (IllegalStateException isx)
      {
        if (required)
        {
          throw isx;
        }
        else
        {
          return null;
        }
      }

      if (wrapInProxies)
      {
        target = LazyInitProxyFactory.createProxy(field.getType(), locator);
      }

      // only put the proxy into the cache if the bean is a singleton
      if (locator.isSingletonBean())
      {
        Object tmpTarget = cache.putIfAbsent(locator, target);
        if (tmpTarget != null)
        {
          target = tmpTarget;
View Full Code Here

Examples of org.apache.wicket.spring.SpringBeanLocator

  public Object getFieldValue(final Field field, final Object fieldOwner)
  {
    if (supportsField(field))
    {
      SpringBeanLocator locator = new SpringBeanLocator(getBeanName(field), field.getType(),
        contextLocator);

      // only check the cache if the bean is a singleton
      Object cachedValue = cache.get(locator);
      if (cachedValue != null)
      {
        return cachedValue;
      }

      final Object target;
      if (wrapInProxies)
      {
        target = LazyInitProxyFactory.createProxy(field.getType(), locator);
      }
      else
      {
        target = locator.locateProxyTarget();
      }

      // only put the proxy into the cache if the bean is a singleton
      if (locator.isSingletonBean())
      {
        cache.put(locator, target);
      }
      return target;
    }
View Full Code Here

Examples of org.apache.wicket.spring.SpringBeanLocator

      if (beanName == null)
      {
        return null;
      }

      SpringBeanLocator locator = new SpringBeanLocator(beanName, field.getType(),
        contextLocator);

      // only check the cache if the bean is a singleton
      Object cachedValue = cache.get(locator);
      if (cachedValue != null)
      {
        return cachedValue;
      }

      final Object target;
      if (wrapInProxies)
      {
        target = LazyInitProxyFactory.createProxy(field.getType(), locator);
      }
      else
      {
        target = locator.locateProxyTarget();
      }

      // only put the proxy into the cache if the bean is a singleton
      if (locator.isSingletonBean())
      {
        cache.put(locator, target);
      }
      return target;
    }
View Full Code Here

Examples of org.apache.wicket.spring.SpringBeanLocator

      if (beanName == null)
      {
        return null;
      }

      SpringBeanLocator locator = new SpringBeanLocator(beanName, field.getType(),
        contextLocator);

      // only check the cache if the bean is a singleton
      Object cachedValue = cache.get(locator);
      if (cachedValue != null)
      {
        return cachedValue;
      }

      Object target;
      try
      {
        // check whether there is a bean with the provided properties
        target = locator.locateProxyTarget();
      }
      catch (IllegalStateException isx)
      {
        if (required)
        {
          throw isx;
        }
        else
        {
          return null;
        }
      }

      if (wrapInProxies)
      {
        target = LazyInitProxyFactory.createProxy(field.getType(), locator);
      }

      // only put the proxy into the cache if the bean is a singleton
      if (locator.isSingletonBean())
      {
        Object tmpTarget = cache.putIfAbsent(locator, target);
        if (tmpTarget != null)
        {
          target = tmpTarget;
View Full Code Here

Examples of org.apache.wicket.spring.SpringBeanLocator

  {

    if (field.isAnnotationPresent(SpringBean.class))
    {
      SpringBean annot = field.getAnnotation(SpringBean.class);
      SpringBeanLocator locator = new SpringBeanLocator(annot.name(), field.getType(),
          contextLocator);

      // only check the cache if the bean is a singleton
      if (locator.isSingletonBean() && cache.containsKey(locator))
      {
        return cache.get(locator);
      }

      Object proxy = LazyInitProxyFactory.createProxy(field.getType(), locator);
      // only put the proxy into the cache if the bean is a singleton
      if (locator.isSingletonBean())
      {
        cache.put(locator, proxy);
      }
      return proxy;
    }
View Full Code Here

Examples of org.apache.wicket.spring.SpringBeanLocator

   * @throws Exception
   */
  @Test
  public void testFactory() throws Exception
  {
    SpringBeanLocator locator;
    Object proxy;

    Field field = obj.getClass().getDeclaredField("nobean");
    proxy = factory.getFieldValue(field, obj);
    assertNull(proxy);

    field = obj.getClass().getDeclaredField("beanByClass");
    proxy = factory.getFieldValue(field, obj);
    locator = (SpringBeanLocator)((ILazyInitProxy)proxy).getObjectLocator();
    assertTrue(locator.getBeanType().equals(Bean.class));
    assertTrue(locator.getSpringContextLocator() == mockCtxLocator);
    assertTrue(factory.getFieldValue(field, obj) instanceof ILazyInitProxy);

    field = obj.getClass().getDeclaredField("beanByName");
    proxy = factory.getFieldValue(field, obj);
    locator = (SpringBeanLocator)((ILazyInitProxy)proxy).getObjectLocator();
    assertTrue(locator.getBeanName().equals("somebean"));
    assertTrue(locator.getBeanType().equals(Bean2.class));
    assertTrue(locator.getSpringContextLocator() == mockCtxLocator);
    assertTrue(factory.getFieldValue(field, obj) instanceof ILazyInitProxy);
  }
View Full Code Here

Examples of org.apache.wicket.spring.SpringBeanLocator

    }

    // we must inject bean with name "mrBean"
    AnnotatedBeanNotRequiredDifferentName page;
    tester.startPage(page = new AnnotatedBeanNotRequiredDifferentName());
    SpringBeanLocator locator = (SpringBeanLocator)((ILazyInitProxy)page.getBean()).getObjectLocator();

    assertTrue(locator.getBeanName().equals("mrBean"));
  }
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.