Search in sources :

Example 1 with ProxettaBeanDefinition

use of jodd.petite.proxetta.ProxettaBeanDefinition in project jodd by oblac.

the class ScopedProxyManager method createScopedProxyBean.

/**
	 * Creates scoped proxy bean for given bean definition.
	 */
protected Object createScopedProxyBean(PetiteContainer petiteContainer, BeanDefinition refBeanDefinition) {
    Class beanType = refBeanDefinition.type;
    Class proxyClass = proxyClasses.get(beanType);
    if (proxyClass == null) {
        if (refBeanDefinition instanceof ProxettaBeanDefinition) {
            // special case, double proxy!
            ProxettaBeanDefinition pbd = (ProxettaBeanDefinition) refBeanDefinition;
            ProxyProxetta proxetta = ProxyProxetta.withAspects(ArraysUtil.insert(pbd.proxyAspects, aspect, 0));
            proxetta.setClassNameSuffix("$ScopedProxy");
            proxetta.setVariableClassName(true);
            ProxyProxettaBuilder builder = proxetta.builder(pbd.originalTarget);
            proxyClass = builder.define();
            proxyClasses.put(beanType, proxyClass);
        } else {
            ProxyProxetta proxetta = ProxyProxetta.withAspects(aspect);
            proxetta.setClassNameSuffix("$ScopedProxy");
            proxetta.setVariableClassName(true);
            ProxyProxettaBuilder builder = proxetta.builder(beanType);
            proxyClass = builder.define();
            proxyClasses.put(beanType, proxyClass);
        }
    }
    Object proxy;
    try {
        proxy = proxyClass.newInstance();
        Field field = proxyClass.getField("$__petiteContainer$0");
        field.set(proxy, petiteContainer);
        field = proxyClass.getField("$__name$0");
        field.set(proxy, refBeanDefinition.name);
    } catch (Exception ex) {
        throw new PetiteException(ex);
    }
    return proxy;
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) Field(java.lang.reflect.Field) ProxyProxettaBuilder(jodd.proxetta.impl.ProxyProxettaBuilder) ProxettaBeanDefinition(jodd.petite.proxetta.ProxettaBeanDefinition)

Aggregations

Field (java.lang.reflect.Field)1 ProxettaBeanDefinition (jodd.petite.proxetta.ProxettaBeanDefinition)1 ProxyProxetta (jodd.proxetta.impl.ProxyProxetta)1 ProxyProxettaBuilder (jodd.proxetta.impl.ProxyProxettaBuilder)1