private final Map<Set<Annotation>, Bean<CouchbaseOperations>> couchbaseOperationsMap = new HashMap<Set<Annotation>, Bean<CouchbaseOperations>>();
|
|
<T> void processBean(@Observes ProcessBean<T> processBean) {
|
Bean<T> bean = processBean.getBean();
|
for (Type type : bean.getTypes()) {
|
if (type instanceof Class<?> && CouchbaseOperations.class.isAssignableFrom((Class<?>) type)) {
|
couchbaseOperationsMap.put(bean.getQualifiers(), ((Bean<CouchbaseOperations>) bean));
|
}
|
}
|
}
|
|
protected <X> void processAnnotatedType(@Observes ProcessAnnotatedType<X> processAnnotatedType) {
|
|
AnnotatedType<X> annotatedType = processAnnotatedType.getAnnotatedType();
|
Class<X> repositoryType = annotatedType.getJavaClass();
|
|
if (isRepository(repositoryType)) {
|
|
Set<Annotation> qualifiers = getQualifiers(repositoryType);
|
|
// Store the repository type using its qualifiers.
|
repositoryTypes.put(repositoryType, qualifiers);
|
}
|
}
|
|
void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBeanDiscovery, BeanManager beanManager) {
|
for (Map.Entry<Class<?>, Set<Annotation>> entry : getRepositoryTypes()) {
|
Class<?> repositoryType = entry.getKey();
|
Set<Annotation> qualifiers = entry.getValue();
|
Bean<CouchbaseOperations> couchbaseOperationsBean = this.couchbaseOperationsMap.get(qualifiers);
|
|
// couchbaseOperationsBean is null
|
}
|
}
|
|
/**
|
* Determines the qualifiers of the given type.
|
*/
|
private Set<Annotation> getQualifiers(final Class<?> type) {
|
|
Set<Annotation> qualifiers = new HashSet<Annotation>();
|
Annotation[] annotations = type.getAnnotations();
|
for (Annotation annotation : annotations) {
|
Class<? extends Annotation> annotationType = annotation.annotationType();
|
if (annotationType.isAnnotationPresent(Qualifier.class)) {
|
qualifiers.add(annotation);
|
}
|
}
|
|
// Add @Default qualifier if no qualifier is specified.
|
if (qualifiers.isEmpty()) {
|
qualifiers.add(DefaultAnnotationLiteral.INSTANCE);
|
}
|
|
// Add @Any qualifier.
|
qualifiers.add(AnyAnnotationLiteral.INSTANCE);
|
return qualifiers;
|
}
|