use of org.apache.deltaspike.core.util.bean.BeanBuilder in project deltaspike by apache.
the class PartialBeanBindingExtension method createPartialProducersDefinedIn.
private List<Bean> createPartialProducersDefinedIn(Bean partialBean, AfterBeanDiscovery afterBeanDiscovery, BeanManager beanManager, Class currentClass) {
List<Bean> result = new ArrayList<Bean>();
while (currentClass != null && !Object.class.getName().equals(currentClass.getName())) {
for (Class interfaceClass : currentClass.getInterfaces()) {
if (interfaceClass.getName().startsWith("java.") || interfaceClass.getName().startsWith("javax.")) {
continue;
}
result.addAll(createPartialProducersDefinedIn(partialBean, afterBeanDiscovery, beanManager, interfaceClass));
}
for (Method currentMethod : currentClass.getDeclaredMethods()) {
if (currentMethod.isAnnotationPresent(Produces.class)) {
if (currentMethod.getParameterTypes().length > 0) {
afterBeanDiscovery.addDefinitionError(new IllegalStateException("Producer-methods in partial-beans currently don't support injection-points. " + "Please remove the parameters from " + currentMethod.toString() + " in " + currentClass.getName()));
}
DeltaSpikePartialProducerLifecycle lifecycle = new DeltaSpikePartialProducerLifecycle(partialBean.getBeanClass(), currentMethod);
Class<? extends Annotation> scopeClass = extractScope(currentMethod.getDeclaredAnnotations(), beanManager);
Class<?> producerResultType = currentMethod.getReturnType();
boolean passivationCapable = Serializable.class.isAssignableFrom(producerResultType) || producerResultType.isPrimitive();
Set<Annotation> qualifiers = extractQualifiers(currentMethod.getDeclaredAnnotations(), beanManager);
BeanBuilder<?> beanBuilder = new BeanBuilder(beanManager).beanClass(producerResultType).types(Object.class, producerResultType).qualifiers(qualifiers).passivationCapable(passivationCapable).scope(scopeClass).id(createPartialProducerId(currentClass, currentMethod, qualifiers)).beanLifecycle(lifecycle);
result.add(beanBuilder.create());
}
}
currentClass = currentClass.getSuperclass();
}
return result;
}
use of org.apache.deltaspike.core.util.bean.BeanBuilder in project deltaspike by apache.
the class BeanBuilderTest method assertNonNullInjectionPointsFromBeanBuilder.
@Test
public void assertNonNullInjectionPointsFromBeanBuilder() {
final BeanBuilder beanBuilder = new BeanBuilder(beanManager);
final AnnotatedType<?> at = beanManager.createAnnotatedType(WithInjectionPoint.class);
final Bean<?> newInjectionBean = beanBuilder.readFromType(at).create();
for (final InjectionPoint ip : newInjectionBean.getInjectionPoints()) {
Assert.assertNotNull(ip);
}
}
use of org.apache.deltaspike.core.util.bean.BeanBuilder in project deltaspike by apache.
the class BeanBuilderTest method assertNonNullInjectionPointsWhenOverriding.
@Test
public void assertNonNullInjectionPointsWhenOverriding() {
final BeanBuilder beanBuilder = new BeanBuilder(beanManager);
final AnnotatedType<?> at = beanManager.createAnnotatedType(WithInjectionPoint.class);
beanBuilder.readFromType(at);
// It's not easy to actually create these in the state we need, so we have to get the InjectionPonits,
// create new ones with the correct info, null out the bean, set them as the new injection points
// then move on.
final Set<InjectionPoint> origInjectionPoints = beanBuilder.getInjectionPoints();
beanBuilder.injectionPoints(beanBuilder.getInjectionPoints());
final Set<InjectionPoint> newInjectionPoints = new HashSet<InjectionPoint>();
for (InjectionPoint ip : origInjectionPoints) {
newInjectionPoints.add(new ImmutableInjectionPoint((AnnotatedField) ip.getAnnotated(), ip.getQualifiers(), null, ip.isTransient(), ip.isDelegate()));
}
beanBuilder.injectionPoints(newInjectionPoints);
final Bean<?> newInjectionBean = beanBuilder.create();
for (final InjectionPoint ip : newInjectionBean.getInjectionPoints()) {
Assert.assertNotNull(ip);
}
}
Aggregations