use of io.vertx.up.annotations.Qualifier in project vertx-zero by silentbalanceyh.
the class AffluxThread method scanQualifier.
private void scanQualifier(final Field field, final List<Class<?>> instanceCls) {
// Field must annotated with @Qualifier
final Annotation annotation = field.getAnnotation(Qualifier.class);
Fn.flingUp(null == annotation, LOGGER, QualifierMissedException.class, this.getClass(), field.getName(), field.getDeclaringClass().getName());
// All implementation class must be annotated with @Named
final boolean match = instanceCls.stream().allMatch(item -> item.isAnnotationPresent(Named.class));
final Set<String> names = instanceCls.stream().map(Class::getName).collect(Collectors.toSet());
Fn.flingUp(!match, LOGGER, NamedImplementionException.class, this.getClass(), names, field.getType().getName());
// Named value must be reflect with @Qualifier
final String value = Instance.invoke(annotation, "value");
final Optional<Class<?>> verified = instanceCls.stream().filter(item -> {
final Annotation target = item.getAnnotation(Named.class);
final String targetValue = Instance.invoke(target, "value");
return value.equals(targetValue) && !Ut.isNil(targetValue);
}).findAny();
Fn.flingUp(!verified.isPresent(), LOGGER, NamedNotFoundException.class, this.getClass(), names, value);
// Passed all specification
this.fieldMap.put(field.getName(), verified.get());
}
Aggregations