Package jodd.proxetta.impl

Examples of jodd.proxetta.impl.ProxyProxettaBuilder


   * Applies proxetta on bean class before bean registration.
   */
  @Override
  protected BeanDefinition createBeanDefinitionForRegistration(String name, Class type, Scope scope, WiringMode wiringMode) {
    if (proxetta != null) {
      ProxyProxettaBuilder builder = proxetta.builder();

      builder.setTarget(type);

      type = builder.define();
    }

    return super.createBeanDefinitionForRegistration(name, type, scope, wiringMode);
  }
View Full Code Here


      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;
View Full Code Here

      e.printStackTrace();
    }
*/
    ProxyProxetta proxyProxetta = ProxyProxetta.withAspects(a1);
    proxyProxetta.setClassNameSuffix("$$$Proxetta");
    ProxyProxettaBuilder pb = proxyProxetta.builder();
    pb.setTarget(Foo.class);
    Foo foo = (Foo) pb.newInstance();

    Class fooProxyClass = foo.getClass();
    assertNotNull(fooProxyClass);

    Method[] methods = fooProxyClass.getMethods();
View Full Code Here

  @Test
  public void testProxyClassNames() {
    ProxyProxetta proxyProxetta = ProxyProxetta.withAspects(new ProxyAspect(FooProxyAdvice.class, new AllMethodsPointcut()));
    proxyProxetta.setVariableClassName(true);

    ProxyProxettaBuilder builder = proxyProxetta.builder();
    builder.setTarget(Foo.class);
    Foo foo = (Foo) builder.newInstance();

    assertNotNull(foo);
    assertEquals(Foo.class.getName() + "$$Proxetta", StringUtil.substring(foo.getClass().getName(), 0, -1));

    builder = proxyProxetta.builder();
    builder.setTarget(Foo.class);
    foo = (Foo) builder.newInstance();

    assertNotNull(foo);
    assertEquals(Foo.class.getName() + "$$Proxetta", StringUtil.substring(foo.getClass().getName(), 0, -1));

    proxyProxetta.setClassNameSuffix("$$Ppp");
    builder = proxyProxetta.builder();
    builder.setTarget(Foo.class);
    foo = (Foo) builder.newInstance();

    assertNotNull(foo);
    assertEquals(Foo.class.getName() + "$$Ppp", StringUtil.substring(foo.getClass().getName(), 0, -1));

    proxyProxetta.setClassNameSuffix("$$Proxetta");
    proxyProxetta.setVariableClassName(false);
    builder = proxyProxetta.builder(Foo.class, ".Too");
    foo = (Foo) builder.newInstance();

    assertNotNull(foo);
    assertEquals(Foo.class.getPackage().getName() + ".Too$$Proxetta", foo.getClass().getName());

    builder = proxyProxetta.builder();
    builder.setTarget(Foo.class);
    builder.setTargetProxyClassName("foo.");
    foo = (Foo) builder.newInstance();

    assertNotNull(foo);
    assertEquals("foo.Foo$$Proxetta", foo.getClass().getName());

    proxyProxetta.setClassNameSuffix(null);
    builder = proxyProxetta.builder();
    builder.setTargetProxyClassName("foo.Fff");
    builder.setTarget(Foo.class);
    foo = (Foo) builder.newInstance();

    assertNotNull(foo);
    assertEquals("foo.Fff", foo.getClass().getName());

  }
View Full Code Here

  }

  @Test
  public void testInnerOverride() {
    ProxyProxetta proxyProxetta = ProxyProxetta.withAspects(new ProxyAspect(FooProxyAdvice.class, new AllMethodsPointcut()));
    ProxyProxettaBuilder builder = proxyProxetta.builder();
    builder.setTarget(Two.class);
    builder.setTargetProxyClassName("foo.");

    Two two = (Two) builder.newInstance();

    assertNotNull(two);
    assertEquals("foo.Two$$Proxetta", two.getClass().getName());
  }
View Full Code Here

  @Test
  public void testJdk() throws Exception {
    ProxyProxetta proxyProxetta = ProxyProxetta.withAspects(new ProxyAspect(StatCounterAdvice.class, new AllMethodsPointcut()));
    proxyProxetta.setVariableClassName(false);

    ProxyProxettaBuilder builder = proxyProxetta.builder();
    builder.setTarget(Object.class);
    try {
      builder.define();
      fail("Default class loader should not load java.*");
    } catch (RuntimeException rex) {
      // ignore
    }

    builder = proxyProxetta.builder();
    builder.setTarget(Object.class);
    builder.setTargetProxyClassName("foo.");
    Object object = builder.newInstance();

    assertNotNull(object);
    assertEquals("foo.Object$$Proxetta", object.getClass().getName());

    System.out.println("----------list");

    StatCounter.counter = 0;

    builder = proxyProxetta.builder(ArrayList.class, "foo.");
    List list = (List) builder.newInstance();
    assertNotNull(list);
    assertEquals("foo.ArrayList$$Proxetta", list.getClass().getName());

    assertEquals(1, StatCounter.counter);
    list.add(new Integer(1));
    assertTrue(StatCounter.counter == 3 || StatCounter.counter == 2);

    System.out.println("----------set");

    builder = proxyProxetta.builder(HashSet.class, "foo.");
    Set set = (Set) builder.newInstance();

    assertNotNull(set);
    assertEquals("foo.HashSet$$Proxetta", set.getClass().getName());

    assertTrue(StatCounter.counter == 4 || StatCounter.counter == 3);
View Full Code Here

  @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");
View Full Code Here

  @Test
  public void testNullReturns() throws Exception {
    ProxyProxetta proxetta = ProxyProxetta.withAspects(
        new ProxyAspect(ReturnNullAdvice.class, new AllMethodsPointcut()));

    ProxyProxettaBuilder builder = proxetta.builder(Retro.class, ".Retro3");

//    proxetta.setDebugFolder("d:\\");

    Class proxyClass = builder.define();

    Object proxy = proxyClass.newInstance();

    Retro retro = (Retro) proxy;
View Full Code Here

          }
    });

    ProxyProxetta proxyProxetta = ProxyProxetta.withAspects(proxyAspect);
    proxyProxetta.setClassNameSuffix("$$$Proxetta888");
    ProxyProxettaBuilder pb = proxyProxetta.builder();
    pb.setTarget(Foo.class);
    Foo foo = (Foo) pb.newInstance();

    assertNotNull(foo);

    MethodInfo mi = valueHolder.getValue();
View Full Code Here

  /**
   * Generates new class.
   */
  public Class defineProxy(Class target) {
    ProxyProxettaBuilder builder = proxetta.builder();
    builder.setTarget(target);
    return builder.define();
  }
View Full Code Here

TOP

Related Classes of jodd.proxetta.impl.ProxyProxettaBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.