Search in sources :

Example 1 with MapEventTransformerFactory

use of com.oracle.coherence.spring.annotation.MapEventTransformerFactory in project coherence-spring by coherence-community.

the class MapEventTransformerService method getMapEventTransformer.

/**
 * Create a {@link MapEventTransformer} for the specified injection point.
 * @param injectionPoint  the injection point to inject a {@link MapEventTransformer} into
 * @return a {@link MapEventTransformer} for the specified injection point
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
MapEventTransformer getMapEventTransformer(InjectionPoint injectionPoint) {
    final List<Annotation> bindings = CoherenceAnnotationUtils.getAnnotationsMarkedWithMarkerAnnotation(injectionPoint, MapEventTransformerBinding.class);
    for (Annotation annotation : bindings) {
        final Class<? extends Annotation> annotationType = annotation.annotationType();
        final MapEventTransformerFactory factory = CoherenceAnnotationUtils.getSingleBeanWithAnnotation(this.applicationContext, annotationType);
        return factory.create(annotation);
    }
    throw new IllegalStateException("Unsatisfied dependency - no MapEventTransformerFactory bean found for bindings " + bindings);
}
Also used : MapEventTransformerFactory(com.oracle.coherence.spring.annotation.MapEventTransformerFactory) Annotation(java.lang.annotation.Annotation)

Example 2 with MapEventTransformerFactory

use of com.oracle.coherence.spring.annotation.MapEventTransformerFactory in project coherence-spring by coherence-community.

the class MapEventTransformerService method resolve.

/**
 * Resolve a {@link 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 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((annotation) -> annotation.annotationType().isAnnotationPresent(MapEventTransformerBinding.class)).findFirst();
    Optional<Annotation> optionalExtractor = annotations.stream().filter((annotation) -> annotation.annotationType().isAnnotationPresent(ExtractorBinding.class)).findFirst();
    if (optionalTransformer.isPresent()) {
        final Annotation annotation = optionalTransformer.get();
        final Class<? extends Annotation> annotationType = annotation.annotationType();
        final MapEventTransformerFactory factory = CoherenceAnnotationUtils.getSingleBeanWithAnnotation(this.applicationContext, annotationType);
        return factory.create(annotation);
    } else if (optionalExtractor.isPresent()) {
        // there is one or more ExtractorBinding annotations
        ValueExtractor<Object, Object> extractor = this.extractorFactory.resolve(annotations);
        return new ExtractorEventTransformer(extractor);
    }
    // there are no transformer or extractor annotations.
    return null;
}
Also used : ExtractorEventTransformer(com.tangosol.util.transformer.ExtractorEventTransformer) ExtractorBinding(com.oracle.coherence.spring.annotation.ExtractorBinding) MapEventTransformerBinding(com.oracle.coherence.spring.annotation.MapEventTransformerBinding) MapEventTransformerFactory(com.oracle.coherence.spring.annotation.MapEventTransformerFactory) CoherenceAnnotationUtils(com.oracle.coherence.spring.configuration.support.CoherenceAnnotationUtils) InjectionPoint(org.springframework.beans.factory.InjectionPoint) Set(java.util.Set) List(java.util.List) ValueExtractor(com.tangosol.util.ValueExtractor) MapEventTransformer(com.tangosol.util.MapEventTransformer) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) ExtractorEventTransformer(com.tangosol.util.transformer.ExtractorEventTransformer) MapEventTransformerFactory(com.oracle.coherence.spring.annotation.MapEventTransformerFactory) ValueExtractor(com.tangosol.util.ValueExtractor) Annotation(java.lang.annotation.Annotation)

Aggregations

MapEventTransformerFactory (com.oracle.coherence.spring.annotation.MapEventTransformerFactory)2 Annotation (java.lang.annotation.Annotation)2 ExtractorBinding (com.oracle.coherence.spring.annotation.ExtractorBinding)1 MapEventTransformerBinding (com.oracle.coherence.spring.annotation.MapEventTransformerBinding)1 CoherenceAnnotationUtils (com.oracle.coherence.spring.configuration.support.CoherenceAnnotationUtils)1 MapEventTransformer (com.tangosol.util.MapEventTransformer)1 ValueExtractor (com.tangosol.util.ValueExtractor)1 ExtractorEventTransformer (com.tangosol.util.transformer.ExtractorEventTransformer)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 InjectionPoint (org.springframework.beans.factory.InjectionPoint)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1