@SuppressWarnings("unchecked")
public <X> Set<ProducerFieldBean<?>> defineProducerFields(InjectionTargetBean<X> bean, AnnotatedType<X> annotatedType)
{
DefinitionUtil definitionUtil = webBeansContext.getDefinitionUtil();
Set<ProducerFieldBean<?>> producerBeans = new HashSet<ProducerFieldBean<?>>();
Set<AnnotatedField<? super X>> annotatedFields = annotatedType.getFields();
for(AnnotatedField<? super X> annotatedField: annotatedFields)
{
if(annotatedField.isAnnotationPresent(Produces.class))
{
Type genericType = annotatedField.getBaseType();
if(ClassUtil.isParametrizedType(genericType))
{
if(!ClassUtil.checkParametrizedType((ParameterizedType)genericType))
{
throw new WebBeansConfigurationException("Producer annotated field : " + annotatedField + " can not be Wildcard type or Type variable");
}
}
Annotation[] anns = AnnotationUtil.getAnnotationsFromSet(annotatedField.getAnnotations());
Field field = annotatedField.getJavaMember();
//Producer field for resource
Annotation resourceAnnotation = AnnotationUtil.hasOwbInjectableResource(anns);
//Producer field for resource
if(resourceAnnotation != null)
{
//Check for valid resource annotation
//WebBeansUtil.checkForValidResources(annotatedField.getDeclaringType().getJavaClass(), field.getType(), field.getName(), anns);
if(!Modifier.isStatic(field.getModifiers()))
{
ResourceReference<X,Annotation> resourceRef = new ResourceReference<X, Annotation>(bean.getBeanClass(), field.getName(),
(Class<X>)field.getType(), resourceAnnotation);
//Can not define EL name
if(annotatedField.isAnnotationPresent(Named.class))
{
throw new WebBeansConfigurationException("Resource producer annotated field : " + annotatedField + " can not define EL name");
}
ResourceBean<X,Annotation> resourceBean = new ResourceBean((Class<X>)field.getType(),bean, resourceRef);
resourceBean.getTypes().addAll(annotatedField.getTypeClosure());
definitionUtil.defineQualifiers(resourceBean, anns);
resourceBean.setImplScopeType(new DependentScopeLiteral());
resourceBean.setProducerField(field);
producerBeans.add(resourceBean);
}
}
else
{
ProducerFieldBean<X> producerFieldBean = new ProducerFieldBean<X>(bean, (Class<X>)ClassUtil.getClass(annotatedField.getBaseType()));
producerFieldBean.setProducerField(field);
if (ClassUtil.getClass(annotatedField.getBaseType()).isPrimitive())
{
producerFieldBean.setNullable(false);
}
definitionUtil.defineSerializable(producerFieldBean);
definitionUtil.defineStereoTypes(producerFieldBean, anns);
webBeansContext.getWebBeansUtil().setBeanEnableFlagForProducerBean(bean,
producerFieldBean,
anns);
Set<Type> types = annotatedField.getTypeClosure();
producerFieldBean.getTypes().addAll(types);
definitionUtil.defineScopeType(producerFieldBean, anns, "Annotated producer field: " + annotatedField + "must declare default @Scope annotation", false);
webBeansContext.getWebBeansUtil().checkUnproxiableApiType(producerFieldBean,
producerFieldBean.getScope());
WebBeansUtil.checkProducerGenericType(producerFieldBean,annotatedField.getJavaMember());
definitionUtil.defineQualifiers(producerFieldBean, anns);
definitionUtil.defineName(producerFieldBean, anns, WebBeansUtil.getProducerDefaultName(annotatedField.getJavaMember().getName()));
producerBeans.add(producerFieldBean);
}
}
}