org.simpleflatmapper.reflect.meta.AnnotationToPropertyUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-reflect Show documentation
Show all versions of sfm-reflect Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
The newest version!
package org.simpleflatmapper.reflect.meta;
import org.simpleflatmapper.util.Consumer;
import org.simpleflatmapper.util.ProducerServiceLoader;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.ServiceLoader;
public final class AnnotationToPropertyUtil {
private AnnotationToPropertyUtil() { }
private static final AnnotationToPropertyService ANNOTATION_TO_PROPERTY_SERVICE = findAnnotationToProperty();
private static AnnotationToPropertyService findAnnotationToProperty() {
final ArrayList providers = new ArrayList();
ProducerServiceLoader.produceFromServiceLoader(ServiceLoader.load(AnnotationToPropertyServiceProducer.class), new Consumer() {
@Override
public void accept(AnnotationToPropertyService t) {
providers.add(t);
}
});
return aggregateAnnotationToProperty(providers.toArray(new AnnotationToPropertyService[0]));
}
public static AnnotationToPropertyService getAnnotationToPropertyService() {
return ANNOTATION_TO_PROPERTY_SERVICE;
}
private static AnnotationToPropertyService aggregateAnnotationToProperty(AnnotationToPropertyService[] registered) {
if (registered.length == 0) {
return new DefaultAnnotationToPropertyService();
} else if (registered.length == 1) {
return registered[0];
} else {
return new ArrayAnnotationToPropertyService(registered);
}
}
private static class DefaultAnnotationToPropertyService implements AnnotationToPropertyService {
@Override
public void generateProperty(Annotation annotation, Consumer