public static ProxyAspect of(final Class<? extends ProxyAdvice> advice, final ProxyPointcut pointcut) { return new ProxyAspect(advice, pointcut); }
/** * Returns {@link WrapperProxetta} used for building loggable prepared statements. * Initializes proxetta when called for the first time. */ protected BaseLoggableFactory(final Class<T> targetClass) { this.targetClass = targetClass; this.proxetta = Proxetta.wrapperProxetta().withAspect(ProxyAspect.of(LoggableAdvice.class, methodInfo -> { int argumentsCount = methodInfo.getArgumentsCount(); char argumentType = 0; if (argumentsCount >= 1) { argumentType = methodInfo.getArgument(1).getOpcode(); } return methodInfo.getReturnType().getOpcode() == 'V' && // void-returning method argumentType == 'I' && // first argument type methodInfo.isPublicMethod() && methodInfo.getMethodName().startsWith("set") && // set* (argumentsCount == 2 || argumentsCount == 3); // number of arguments })); }
ProxyAspectData(WorkData wd, ProxyAspect aspect, int aspectIndex) { this.aspect = aspect; this.advice = aspect.getAdvice(); this.pointcut = aspect.getPointcut(); this.aspectIndex = aspectIndex; this.wd = wd; adviceClassReader = getCachedAdviceClassReader(advice); readAdviceData(); }
protected ProxyAspect createTxProxyAspects(final Class<? extends Annotation>[] annotations) { return new ProxyAspect( AnnotationTxAdvice.class, ((ProxyPointcut) MethodInfo::isPublicMethod) .and(MethodWithAnnotationPointcut.of(annotations)) ); }
@Test void testClassesWithGenericsAsReturnValueProxyDefault() { try { ProxyAspect aspect = ProxyAspect.of(DelegateAdvice.class, new AllMethodsPointcut()); ProxyProxetta proxetta = Proxetta.proxyProxetta().withAspects(aspect); ProxyProxettaFactory builder = proxetta.proxy().setTarget(Foo.class); builder.newInstance(); } catch (Exception ex) { ex.printStackTrace(); fail(ex.toString()); } } }
public MethrefProxetta() { ProxyAspect aspects = new ProxyAspect(MethrefAdvice.class, new AllMethodsPointcut()); proxetta = Proxetta.proxyProxetta().withAspect(aspects); proxetta.setClassNameSuffix(METHREF_CLASSNAME_SUFFIX); }
@Test void testWrapperProxetta_unopen() throws InvocationTargetException, IllegalAccessException { ProxyAspect proxyAspect = ProxyAspect.of(LogProxyAdvice.class, MethodWithAnnotationPointcut.of(Transaction.class)); final Object service = Proxetta.wrapperProxetta() .withAspect(proxyAspect) .setCreateTargetInDefaultCtor(true) .proxy() .setTarget(Test568Service.class) .newInstance(); // no need to inject since setCreateTargetInstanceInDefaultCtor is set // ProxettaUtil.injectTargetIntoWrapper(new Test568Service(), service); Method method = jodd.util.ClassUtil.findMethod(service.getClass(), "findMember"); String result = (String) method.invoke(service, Long.valueOf(1)); assertEquals("1", result); }
private ProxyAspect[] aspects() { ProxyAspect aspect_performance = new ProxyAspect( PerformanceMeasureProxyAdvice.class, new AllTopMethodsPointcut()); return new ProxyAspect[] {aspect_performance}; }
@Test void testProxyProxetta_open() { ProxyAspect proxyAspect = ProxyAspect.of(LogProxyAdvice.class, MethodWithAnnotationPointcut.of(Transaction.class)); Test568OpenService service = (Test568OpenService) Proxetta.proxyProxetta() .withAspect(proxyAspect) .proxy() .setTarget(Test568OpenService.class) .newInstance(); String result = service.findMember(2L); assertEquals("2", result); } }
public PathrefProxetta() { ProxyAspect aspects = new ProxyAspect(PathrefAdvice.class, new AllMethodsPointcut()); proxetta = Proxetta.proxyProxetta().withAspect(aspects); proxetta.setClassNameSuffix(PATHREF_CLASSNAME_SUFFIX); }
@Test void testProxyClassNames() { ProxyProxetta proxyProxetta = Proxetta.proxyProxetta().withAspect(ProxyAspect.of(FooProxyAdvice.class, new AllMethodsPointcut())); proxyProxetta.setVariableClassName(true);
public static ProxyProxetta createProxyProxetta() { ProxyPointcut pointcut_logged = new MethodWithAnnotationPointcut(Logged.class); ProxyAspect aspect_logged = new ProxyAspect(LogProxyAdvice.class, pointcut_logged); ProxyProxetta proxetta = Proxetta.proxyProxetta().withAspect(aspect_logged); //proxetta.setDebugFolder(SystemUtil.userHome() + "\\inka\\proxetta"); return proxetta; }
@Test void testMethodAnnotationsProxy() { ProxyProxetta proxetta = Proxetta .proxyProxetta() .withAspect( ProxyAspect.of(HeroProxyAdvice.class, ((ProxyPointcut) MethodInfo::isTopLevelMethod).and(AllRealMethodsPointcut.get()) )) //.setDebugFolder(FileUtil.file("~")) ; ProxettaFactory proxettaFactory = proxetta.proxy(); proxettaFactory.setTarget(Hero.class); proxetta.setVariableClassName(true); Hero hero = (Hero) proxettaFactory.newInstance(); assertEquals("BatmanHero37W88.3CatWoman99speeeeedXRAYnull", hero.name()); }
public static ProxyProxetta createProxyProxetta() { ProxyPointcut pointcut_logged = new MethodWithAnnotationPointcut(Logged.class); ProxyAspect aspect_logged = new ProxyAspect(LogProxyAdvice.class, pointcut_logged); //proxetta.setDebugFolder(SystemUtil.userHome() + "\\inka\\proxetta"); return Proxetta.proxyProxetta().withAspects(aspect_logged); }
/** * Returns {@link WrapperProxetta} used for building loggable prepared statements. * Initializes proxetta when called for the first time. */ protected BaseLoggableFactory(final Class<T> targetClass) { this.targetClass = targetClass; this.proxetta = Proxetta.wrapperProxetta().withAspect(ProxyAspect.of(LoggableAdvice.class, methodInfo -> { int argumentsCount = methodInfo.getArgumentsCount(); char argumentType = 0; if (argumentsCount >= 1) { argumentType = methodInfo.getArgument(1).getOpcode(); } return methodInfo.getReturnType().getOpcode() == 'V' && // void-returning method argumentType == 'I' && // first argument type methodInfo.isPublicMethod() && methodInfo.getMethodName().startsWith("set") && // set* (argumentsCount == 2 || argumentsCount == 3); // number of arguments })); }
@Test void testCollector() throws NoSuchFieldException, IllegalAccessException { ProxyProxetta proxetta = Proxetta.proxyProxetta().withAspects( new ProxyAspect(CollectorAdvice.class, new AllTopMethodsPointcut()) ); // proxetta.setDebugFolder("d:\\"); Foo foo = (Foo) proxetta.proxy().setTarget(Foo.class).newInstance(); Field field = foo.getClass().getDeclaredField("$__methods$0"); field.setAccessible(true); List<String> list = (List<String>) field.get(foo); assertNotNull(list); assertEquals(0, list.size()); foo.m1(); assertEquals(1, list.size()); assertEquals("m1", list.get(0)); foo.m1(); assertEquals(2, list.size()); assertEquals("m1", list.get(0)); assertEquals("m1", list.get(1)); } }
@Test void testClassesWithGenericArraysAsReturnValueProxy() { try { ProxyAspect aspect = new ProxyAspect(DelegateAdvice.class, new AllMethodsPointcut()); ProxyProxetta proxetta = Proxetta.proxyProxetta().withAspect(aspect); ProxyProxettaFactory builder = proxetta.proxy().setTarget(Foo.class); builder.newInstance(); } catch (Exception e) { e.printStackTrace(); fail(e.toString()); } } }
@Test void testClassesWithGenericsAsReturnValueProxy() { try { ProxyAspect aspect = new ProxyAspect(DelegateAdvice.class, new AllMethodsPointcut()); ProxyProxetta proxetta = Proxetta.proxyProxetta().withAspects(aspect); ProxyProxettaFactory builder = proxetta.proxy().setTarget(Foo.class); builder.newInstance(); } catch (Exception ex) { ex.printStackTrace(); fail(ex.toString()); } }