Search in sources :

Example 1 with ProxyProxetta

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;
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) Field(java.lang.reflect.Field) ProxyProxettaBuilder(jodd.proxetta.impl.ProxyProxettaBuilder) ProxettaBeanDefinition(jodd.petite.proxetta.ProxettaBeanDefinition)

Example 2 with ProxyProxetta

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());
    }
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) ProxyProxettaBuilder(jodd.proxetta.impl.ProxyProxettaBuilder) ProxyAspect(jodd.proxetta.ProxyAspect) Test(org.junit.Test)

Example 3 with ProxyProxetta

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());
    }
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) ProxyProxettaBuilder(jodd.proxetta.impl.ProxyProxettaBuilder) Test(org.junit.Test)

Example 4 with ProxyProxetta

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);
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) JDateTime(jodd.datetime.JDateTime) DateDao(jodd.proxetta.data.DateDao) Test(org.junit.Test)

Example 5 with ProxyProxetta

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();
}
Also used : ProxyProxetta(jodd.proxetta.impl.ProxyProxetta) Field(java.lang.reflect.Field) AllMethodsPointcut(jodd.proxetta.pointcuts.AllMethodsPointcut) ProxyProxettaBuilder(jodd.proxetta.impl.ProxyProxettaBuilder) ReflectionReplacementAdvice(jodd.proxetta.data.ReflectionReplacementAdvice) Retro(jodd.proxetta.data.Retro) Test(org.junit.Test)

Aggregations

ProxyProxetta (jodd.proxetta.impl.ProxyProxetta)19 Test (org.junit.Test)15 ProxyProxettaBuilder (jodd.proxetta.impl.ProxyProxettaBuilder)10 AllMethodsPointcut (jodd.proxetta.pointcuts.AllMethodsPointcut)5 ProxyAspect (jodd.proxetta.ProxyAspect)4 Field (java.lang.reflect.Field)3 AllRealMethodsPointcut (jodd.proxetta.pointcuts.AllRealMethodsPointcut)3 List (java.util.List)2 PetiteConfig (jodd.petite.PetiteConfig)2 ProxettaAwarePetiteContainer (jodd.petite.proxetta.ProxettaAwarePetiteContainer)2 Foo (jodd.proxetta.data.Foo)2 Hero (jodd.proxetta.data.Hero)2 Retro (jodd.proxetta.data.Retro)2 WrapperProxettaBuilder (jodd.proxetta.impl.WrapperProxettaBuilder)2 AllTopMethodsPointcut (jodd.proxetta.pointcuts.AllTopMethodsPointcut)2 Before (org.junit.Before)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1