Search in sources :

Example 1 with ExtractorBinding

use of io.micronaut.coherence.annotation.ExtractorBinding in project micronaut-coherence by micronaut-projects.

the class MapEventTransformerFactories method resolve.

/**
 * Resolve a {@link com.tangosol.util.MapEventTransformer} from the
 * specified qualifier annotations.
 *
 * @param annotations  the qualifier annotations to use to create the transformer
 * @param <K>          the type of the keys of the entry to be transformed
 * @param <V>          the type of the values of the entry to be transformed
 * @param <U>          the type of the transformed values
 *
 * @return a {@link com.tangosol.util.MapEventTransformer} from the
 *         specified qualifier annotations
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public <K, V, U> MapEventTransformer<K, V, U> resolve(Set<Annotation> annotations) {
    Optional<Annotation> optionalTransformer = annotations.stream().filter(a -> a.annotationType().isAnnotationPresent(MapEventTransformerBinding.class)).findFirst();
    Optional<Annotation> optionalExtractor = annotations.stream().filter(a -> a.annotationType().isAnnotationPresent(ExtractorBinding.class)).findFirst();
    if (optionalTransformer.isPresent()) {
        Annotation annotation = optionalTransformer.get();
        Class<? extends Annotation> type = annotation.annotationType();
        MapEventTransformerFactory factory = ctx.findBean(MapEventTransformerFactory.class, new FactoryQualifier<>(type)).orElse(null);
        if (factory != null) {
            return factory.create(annotation);
        } else {
            throw new IllegalStateException("Unsatisfied dependency - no MapEventTransformerFactory bean found annotated with " + annotation);
        }
    } else if (optionalExtractor.isPresent()) {
        // there is one or more ExtractorBinding annotations
        ValueExtractor<Object, Object> extractor = extractorFactory.resolve(annotations);
        return new ExtractorEventTransformer(extractor);
    }
    // there are no transformer or extractor annotations.
    return null;
}
Also used : ExtractorEventTransformer(com.tangosol.util.transformer.ExtractorEventTransformer) Set(java.util.Set) Inject(javax.inject.Inject) List(java.util.List) ValueExtractor(com.tangosol.util.ValueExtractor) ApplicationContext(io.micronaut.context.ApplicationContext) MapEventTransformer(com.tangosol.util.MapEventTransformer) Factory(io.micronaut.context.annotation.Factory) Annotation(java.lang.annotation.Annotation) Prototype(io.micronaut.context.annotation.Prototype) Optional(java.util.Optional) ExtractorBinding(io.micronaut.coherence.annotation.ExtractorBinding) MapEventTransformerBinding(io.micronaut.coherence.annotation.MapEventTransformerBinding) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata) InjectionPoint(io.micronaut.inject.InjectionPoint) ExtractorEventTransformer(com.tangosol.util.transformer.ExtractorEventTransformer) ValueExtractor(com.tangosol.util.ValueExtractor) Annotation(java.lang.annotation.Annotation)

Aggregations

MapEventTransformer (com.tangosol.util.MapEventTransformer)1 ValueExtractor (com.tangosol.util.ValueExtractor)1 ExtractorEventTransformer (com.tangosol.util.transformer.ExtractorEventTransformer)1 ExtractorBinding (io.micronaut.coherence.annotation.ExtractorBinding)1 MapEventTransformerBinding (io.micronaut.coherence.annotation.MapEventTransformerBinding)1 ApplicationContext (io.micronaut.context.ApplicationContext)1 Factory (io.micronaut.context.annotation.Factory)1 Prototype (io.micronaut.context.annotation.Prototype)1 AnnotationMetadata (io.micronaut.core.annotation.AnnotationMetadata)1 InjectionPoint (io.micronaut.inject.InjectionPoint)1 Annotation (java.lang.annotation.Annotation)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Inject (javax.inject.Inject)1