Example usage for org.apache.wicket.spring SpringBeanLocator SpringBeanLocator

List of usage examples for org.apache.wicket.spring SpringBeanLocator SpringBeanLocator

Introduction

In this page you can find the example usage for org.apache.wicket.spring SpringBeanLocator SpringBeanLocator.

Prototype

public SpringBeanLocator(final Class<?> beanType, Field beanField, final ISpringContextLocator locator) 

Source Link

Document

Constructor

Usage

From source file:org.xaloon.wicket.component.inject.spring.CdiProxyFieldValueFactory.java

License:Apache License

public Object getFieldValue(Field field, Object fieldOwner) {
    if (supportsField(field)) {
        String beanName = getBeanName(field);
        if (StringUtils.isEmpty(beanName)) {
            return null;
        }//  ww w  .  ja v  a2 s . c  o m
        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;
    }
    return null;
}