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;
}
Aggregations