Search in sources :

Example 1 with ProxyProxettaBuilder

use of jodd.proxetta.impl.ProxyProxettaBuilder in project jodd by oblac.

the class ProxettaAwarePetiteContainer method createBeanDefinitionForRegistration.

/**
	 * Applies proxetta on bean class before bean registration.
	 */
@Override
protected BeanDefinition createBeanDefinitionForRegistration(String name, Class type, Scope scope, WiringMode wiringMode) {
    if (proxetta != null) {
        Class originalType = type;
        ProxyProxettaBuilder builder = proxetta.builder();
        builder.setTarget(type);
        type = builder.define();
        return new ProxettaBeanDefinition(name, type, scope, wiringMode, originalType, proxetta.getAspects());
    }
    return super.createBeanDefinitionForRegistration(name, type, scope, wiringMode);
}
Also used : ProxyProxettaBuilder(jodd.proxetta.impl.ProxyProxettaBuilder)

Example 2 with ProxyProxettaBuilder

use of jodd.proxetta.impl.ProxyProxettaBuilder 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 3 with ProxyProxettaBuilder

use of jodd.proxetta.impl.ProxyProxettaBuilder 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 4 with ProxyProxettaBuilder

use of jodd.proxetta.impl.ProxyProxettaBuilder 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 5 with ProxyProxettaBuilder

use of jodd.proxetta.impl.ProxyProxettaBuilder 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

ProxyProxettaBuilder (jodd.proxetta.impl.ProxyProxettaBuilder)14 ProxyProxetta (jodd.proxetta.impl.ProxyProxetta)10 Test (org.junit.Test)9 AllMethodsPointcut (jodd.proxetta.pointcuts.AllMethodsPointcut)5 Field (java.lang.reflect.Field)2 Retro (jodd.proxetta.data.Retro)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 ProxettaBeanDefinition (jodd.petite.proxetta.ProxettaBeanDefinition)1 ProxyAspect (jodd.proxetta.ProxyAspect)1 Foo (jodd.proxetta.data.Foo)1 FooAnn (jodd.proxetta.data.FooAnn)1 ReflectionReplacementAdvice (jodd.proxetta.data.ReflectionReplacementAdvice)1 ReturnNullAdvice (jodd.proxetta.data.ReturnNullAdvice)1