use of jodd.proxetta.impl.ProxyProxetta 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;
}
use of jodd.proxetta.impl.ProxyProxetta in project jodd by oblac.
the class GenericsInDefaultTest method testClassesWithGenericsAsReturnValueProxyDefault.
@Test
public void testClassesWithGenericsAsReturnValueProxyDefault() {
try {
ProxyAspect aspect = new ProxyAspect(DelegateAdvice.class);
ProxyProxetta proxetta = ProxyProxetta.withAspects(aspect);
ProxyProxettaBuilder builder = proxetta.builder(Foo.class);
builder.newInstance();
} catch (Exception ex) {
ex.printStackTrace();
fail(ex.toString());
}
}
use of jodd.proxetta.impl.ProxyProxetta in project jodd by oblac.
the class GenericsTest method testClassesWithGenericsAsReturnValueProxy.
@Test
public void testClassesWithGenericsAsReturnValueProxy() {
try {
ProxyAspect aspect = new ProxyAspect(DelegateAdvice.class);
ProxyProxetta proxetta = ProxyProxetta.withAspects(aspect);
ProxyProxettaBuilder builder = proxetta.builder(Foo.class);
builder.newInstance();
} catch (Exception ex) {
ex.printStackTrace();
fail(ex.toString());
}
}
use of jodd.proxetta.impl.ProxyProxetta in project jodd by oblac.
the class ProxyInfoTest method testProxyInfo_createNotRightAfterTheMethod.
@Test
public void testProxyInfo_createNotRightAfterTheMethod() {
ProxyProxetta proxetta = ProxyProxetta.withAspects(aspects());
//proxetta.setDebugFolder(SystemUtil.userHome());
DateDao dateDateProxy = (DateDao) proxetta.builder(DateDao.class).newInstance();
JDateTime jDateTime = dateDateProxy.currentTime();
assertNotNull(jDateTime);
}
use of jodd.proxetta.impl.ProxyProxetta in project jodd by oblac.
the class ReturnTest method testWrapperWithProxyReturns.
@Test
public void testWrapperWithProxyReturns() throws Exception {
ProxyProxetta proxetta = ProxyProxetta.withAspects(new ProxyAspect(ReflectionReplacementAdvice.class, new AllMethodsPointcut()));
ProxyProxettaBuilder builder = proxetta.builder(Retro.class, ".Retro2");
// proxetta.setDebugFolder("d:\\");
Class proxyClass = builder.define();
Object proxy = proxyClass.newInstance();
Field field = proxyClass.getField("$__target$0");
Retro retro = new Retro();
retro.flag = true;
field.set(proxy, retro);
retro = (Retro) proxy;
assertNotNull(retro);
assertEquals("retro", retro.method1());
assertEquals(2, retro.method2());
assertEquals(3, retro.method3());
assertEquals(4, retro.method4());
assertEquals(5, retro.method5());
assertEquals(true, retro.method6());
assertEquals(7.7, retro.method7(), 0.005);
assertEquals(8.8, retro.method8(), 0.005);
assertEquals(9, retro.method9().length);
assertEquals('r', retro.method11());
retro.method10();
}
Aggregations