Search in sources :

Example 1 with Aspect

use of io.vertigo.core.component.aop.Aspect in project vertigo by KleeGroup.

the class ComponentLoader method createAspect.

private static Aspect createAspect(final Container container, final AspectConfig aspectConfig) {
    // création de l'instance du composant
    final Aspect aspect = DIInjector.newInstance(aspectConfig.getAspectClass(), container);
    // ---
    Assertion.checkNotNull(aspect.getAnnotationType());
    return aspect;
}
Also used : Aspect(io.vertigo.core.component.aop.Aspect)

Example 2 with Aspect

use of io.vertigo.core.component.aop.Aspect in project vertigo by KleeGroup.

the class ComponentAspectUtil method createAspectsByMethod.

/**
 * create all "join points" for a component.
 * Join points are identifed by a method
 *
 * @return Map des aspects par méthode
 */
static Map<Method, List<Aspect>> createAspectsByMethod(final Class<?> implClass, final Collection<Aspect> aspects) {
    Assertion.checkNotNull(implClass);
    Assertion.checkNotNull(aspects);
    // -----
    // 1 - Annotated class
    final List<Aspect> classBasedInterceptors = Stream.of(implClass.getAnnotations()).filter(annotation -> annotation.annotationType().isAnnotationPresent(AspectAnnotation.class)).map(annotation -> findAspect(annotation, aspects)).collect(Collectors.toList());
    // 2 - Annotated methods
    final Map<Method, List<Aspect>> joinPoints = new HashMap<>();
    for (final Method method : implClass.getMethods()) {
        final List<Aspect> methodBasedInterceptors = Stream.of(method.getAnnotations()).filter(annotation -> annotation.annotationType().isAnnotationPresent(AspectAnnotation.class)).map(annotation -> findAspect(annotation, aspects)).collect(Collectors.toList());
        if (!classBasedInterceptors.isEmpty() && !Object.class.equals(method.getDeclaringClass())) {
            // we add all class based interceptors on "no-object" methods
            methodBasedInterceptors.addAll(classBasedInterceptors);
        }
        if (!methodBasedInterceptors.isEmpty()) {
            // there is at least on aspect on this method
            joinPoints.put(method, methodBasedInterceptors);
        }
    }
    return joinPoints;
}
Also used : List(java.util.List) Stream(java.util.stream.Stream) Collection(java.util.Collection) Map(java.util.Map) Assertion(io.vertigo.lang.Assertion) Annotation(java.lang.annotation.Annotation) Aspect(io.vertigo.core.component.aop.Aspect) HashMap(java.util.HashMap) Method(java.lang.reflect.Method) Collectors(java.util.stream.Collectors) AspectAnnotation(io.vertigo.core.component.aop.AspectAnnotation) HashMap(java.util.HashMap) List(java.util.List) Method(java.lang.reflect.Method) Aspect(io.vertigo.core.component.aop.Aspect) AspectAnnotation(io.vertigo.core.component.aop.AspectAnnotation)

Aggregations

Aspect (io.vertigo.core.component.aop.Aspect)2 AspectAnnotation (io.vertigo.core.component.aop.AspectAnnotation)1 Assertion (io.vertigo.lang.Assertion)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1