Hello Weld-Experts,
I wonder if the BeanManager is the only way to access the Bean<?> Interface of Weld/CDI ManagedBean objects.
In my DAO scenario the only way I managed to guess the Entity type of a parameterized EntityHome was the following:
MyEntityHome extends EntityHome<MyEntity> {
...
}
EntityHome<E> {
...
private Class<E> entityClass;
...
private Class<E> getEntityClass() {
if (entityClass == null) {
Set<Bean<?>> beans BeanManager.getBeans(getClass().getGenericSuperclass());
for (Bean<?> bean : beans) {
Type type = bean.getBeanClass().getGenericSuperclass();
if (type instanceof ParameterizedType) {
ParameterizedType paramType = (ParameterizedType) type;
entityClass = (Class<E>) paramType.getActualTypeArguments()[0];
} else {
log.error("NO PARAMETERIZED CLASS: Could not guess entity");
}
break;
}
}
return entityClass;
}
...
}
Anybody with a smarter way to do this?
MiguelZ