use of org.apache.deltaspike.core.api.literal.AnyLiteral in project deltaspike by apache.
the class BeanBuilder method readFromType.
/**
* <p>
* Read the {@link AnnotatedType}, creating a bean from the class and it's
* annotations.
* </p>
* <p/>
* <p>
* By default the bean lifecycle will wrap the result of calling
* {@link BeanManager#createInjectionTarget(AnnotatedType)}.
* </p>
* <p/>
* <p>
* {@link BeanBuilder} does <em>not</em> support reading members of the class
* to create producers or observer methods.
* </p>
*
* @param type the type to read
*/
public BeanBuilder<T> readFromType(AnnotatedType<T> type) {
this.beanClass = type.getJavaClass();
if (beanLifecycle == null) {
setDefaultBeanLifecycle(type);
}
this.qualifiers = new HashSet<Annotation>();
this.stereotypes = new HashSet<Class<? extends Annotation>>();
this.types = new HashSet<Type>();
for (Annotation annotation : type.getAnnotations()) {
if (beanManager.isQualifier(annotation.annotationType())) {
this.qualifiers.add(annotation);
} else if (beanManager.isScope(annotation.annotationType())) {
this.scope = annotation.annotationType();
} else if (beanManager.isStereotype(annotation.annotationType())) {
this.stereotypes.add(annotation.annotationType());
}
if (annotation instanceof Named) {
this.name = ((Named) annotation).value();
if (name == null || name.length() == 0) {
name = createDefaultBeanName(type);
}
}
if (annotation instanceof Alternative) {
this.alternative = true;
}
}
if (type.isAnnotationPresent(Typed.class)) {
Typed typed = type.getAnnotation(Typed.class);
this.types.addAll(Arrays.asList(typed.value()));
} else {
for (Class<?> c = type.getJavaClass(); c != Object.class && c != null; c = c.getSuperclass()) {
this.types.add(c);
}
Collections.addAll(this.types, type.getJavaClass().getInterfaces());
this.types.add(Object.class);
}
if (qualifiers.isEmpty()) {
qualifiers.add(new DefaultLiteral());
}
qualifiers.add(new AnyLiteral());
this.id = ImmutableBeanWrapper.class.getName() + ":" + Annotateds.createTypeId(type);
return this;
}
use of org.apache.deltaspike.core.api.literal.AnyLiteral in project deltaspike by apache.
the class HandlerMethodStorageImpl method getHandlersForException.
@Override
public Collection<HandlerMethod<? extends Throwable>> getHandlersForException(Type exceptionClass, BeanManager bm, Set<Annotation> handlerQualifiers, boolean isBefore) {
final Collection<HandlerMethod<? extends Throwable>> returningHandlers = new TreeSet<HandlerMethod<? extends Throwable>>(new ExceptionHandlerComparator());
final HierarchyDiscovery h = new HierarchyDiscovery(exceptionClass);
final Set<Type> closure = h.getTypeClosure();
for (Type hierarchyType : closure) {
if (allHandlers.get(hierarchyType) != null) {
for (HandlerMethod<?> handler : allHandlers.get(hierarchyType)) {
if (handler.isBeforeHandler() && isBefore) {
if (handler.getQualifiers().contains(new AnyLiteral())) {
returningHandlers.add(handler);
} else {
if (!handlerQualifiers.isEmpty() && handlerQualifiers.equals(handler.getQualifiers())) {
returningHandlers.add(handler);
}
}
} else if (!handler.isBeforeHandler() && !isBefore) {
if (handler.getQualifiers().contains(new AnyLiteral())) {
returningHandlers.add(handler);
} else {
if (!handlerQualifiers.isEmpty() && handlerQualifiers.equals(handler.getQualifiers())) {
returningHandlers.add(handler);
}
}
}
}
}
}
log.fine(String.format("Found handlers %s for exception type %s, qualifiers %s", returningHandlers, exceptionClass, handlerQualifiers));
return Collections.unmodifiableCollection(returningHandlers);
}
use of org.apache.deltaspike.core.api.literal.AnyLiteral in project deltaspike by apache.
the class AnnotatedTypeBuilderTest method modifyAnnotationsOnConstructorParameter.
@Test
public void modifyAnnotationsOnConstructorParameter() throws NoSuchMethodException {
final AnnotatedTypeBuilder<Cat> builder = new AnnotatedTypeBuilder<Cat>();
builder.readFromType(Cat.class, true);
builder.removeFromConstructorParameter(Cat.class.getConstructor(String.class, String.class), 1, Default.class);
builder.addToConstructorParameter(Cat.class.getConstructor(String.class, String.class), 1, new AnyLiteral());
final AnnotatedType<Cat> catAnnotatedType = builder.create();
Set<AnnotatedConstructor<Cat>> catCtors = catAnnotatedType.getConstructors();
assertThat(catCtors.size(), is(2));
for (AnnotatedConstructor<Cat> ctor : catCtors) {
if (ctor.getParameters().size() == 2) {
List<AnnotatedParameter<Cat>> ctorParams = ctor.getParameters();
assertThat(ctorParams.get(1).getAnnotations().size(), is(1));
assertThat((AnyLiteral) ctorParams.get(1).getAnnotations().toArray()[0], is(new AnyLiteral()));
}
}
}
use of org.apache.deltaspike.core.api.literal.AnyLiteral in project deltaspike by apache.
the class BeanProvider method getBeanDefinitions.
private static <T> Set<Bean<T>> getBeanDefinitions(Class<T> type, boolean optional, boolean includeDefaultScopedBeans, BeanManager beanManager) {
Set<Bean<?>> beans = beanManager.getBeans(type, new AnyLiteral());
if (beans == null || beans.isEmpty()) {
if (optional) {
return Collections.emptySet();
}
throw new IllegalStateException("Could not find beans for Type=" + type);
}
if (!includeDefaultScopedBeans) {
beans = filterDefaultScopedBeans(beans);
}
Set<Bean<T>> result = new HashSet<Bean<T>>();
for (Bean<?> bean : beans) {
//noinspection unchecked
@SuppressWarnings("unchecked") Bean<T> beanT = (Bean<T>) bean;
result.add(beanT);
}
return result;
}
Aggregations