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;
}
Aggregations