[
https://issues.apache.org/jira/browse/OWB-273?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12832062#action_12832062
]
YING WANG commented on OWB-273:
-------------------------------
Thanks a lot, Gurkan. So the only way to enable an alternative producer bean is
to annotate
both its class and producer method and enble the class in beans.xml?
I also create a few test cases around alternative/producer/diposes and found
some test cases
throws exceptions. Could you please help review and see if they are bugs or
valid exceptions?
1. AlternativeTest1, includes DefaultBeanProducer and AlternativeBeanProducer1
and I have moved @Alternative from the producer method to the class level. And
AlternativeBeanProducer1 is NOT selected.
Result: AmbiguousResolutionException.
Ying's comments: Shouldn't the producer bean in AlternativeBeanProducer1 be
disabled?
According to 5.1.2, a bean is enabled if it is not a producer method of a
disabled bean.
2. AlternativeTest2, includes DefaultBeanProducer and AlternativeBeanProducer2
and have @Alternative annotated at class and producer method. And
AlternativeBeanProducer2 is NOT selected.
Result: DefaultBeanProducer is used(expected). However the disposes
method is not invoked.
Ying's comments: Not sure why disposes of DefaultBeanProducer is not invoked.
3. AlternativeTest3, includes DefaultBeanProducer and AlternativeBeanProducer3
and has disposes method defined in both. AlternativeBeanProducer3 is NOT
selected.
Result: Producer method component of the disposal method : dumpBean3 in
class :
org.apache.webbeans.newtests.alternatives2.AlternativeBeanProducer3 must
be in the same class!
Ying's comments: Shouldn't both producer and dispose methods in
AlternativeBeanProducer3
be ignored since the AlternativeBeanProducer3 is disabled? the
spec
did not mention much about how disposes method works in a
alternative bean.
4. AlternativeTest4, includes DefaultBeanProducerWithoutDisposes,
AlternativeBeanProducer3
and AlternativeBeanProducer4 . Have disposes method defined in 2 alternative
classes.
AlternativeBeanProducer3 and AlternativeBeanProducer4 are NOT selected.
Result: UnsatisfiedResolutionException: Producer method component of
the disposal
method : dumpBean3 in class :
org.apache.webbeans.newtests.alternatives2.AlternativeBeanProducer3.
annot find bean interface
org.apache.webbeans.newtests.alternatives2.IProducedBean
with qualifier
[...@org.apache.webbeans.newtests.alternatives2.qualifierproducerbased()]
Ying's comments: same as 3.
5. AlternativeTest5, same as above except AlternativeBeanProducer4 is enabled.
Result: same as 4.
> Given class is not annotated with @Alternative Exception when try to enable
> alternative producer/producer field beans
> ---------------------------------------------------------------------------------------------------------------------
>
> Key: OWB-273
> URL: https://issues.apache.org/jira/browse/OWB-273
> Project: OpenWebBeans
> Issue Type: Bug
> Components: Injection and Lookup
> Affects Versions: M3
> Reporter: YING WANG
> Assignee: Gurkan Erdogdu
> Priority: Minor
> Attachments: alternative2.jar
>
>
> I have an alternative producer bean as follow. It seems that the
> AlternativesManager.addClazzAlternative( ) requires @Alternative to be
> annotated at the class level even if it is an alternative producer and throws
> the following exception.
> It is not necessary to add @Alternative at both class level and method level
> for a producer/producer field beans, right?
> =====EXCEPTION=======================================================================================
>
> org.apache.webbeans.exception.WebBeansConfigurationException: Given class :
> com.jcdi.test.alternative.producerbased.AlternativeBeanProducer2 is not
> annotated with @Alternative
> at
> org.apache.webbeans.inject.AlternativesManager.addClazzAlternative(AlternativesManager.java:89)
> at
> org.apache.webbeans.xml.WebBeansXMLConfigurator.addAlternative(WebBeansXMLConfigurator.java:622)
> at
> org.apache.webbeans.xml.WebBeansXMLConfigurator.configureAlternativesElement(WebBeansXMLConfigurator.java:587)
> at
> org.apache.webbeans.xml.WebBeansXMLConfigurator.configureSpecSpecific(WebBeansXMLConfigurator.java:323)
> at
> org.apache.webbeans.xml.WebBeansXMLConfigurator.configureSpecSpecific(WebBeansXMLConfigurator.java:221)
> at
> org.apache.webbeans.xml.WebBeansXMLConfigurator.configure(WebBeansXMLConfigurator.java:157)
> at
> org.apache.webbeans.config.BeansDeployer.deployFromXML(BeansDeployer.java:384)
> at
> org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:139)
> at
> org.apache.webbeans.lifecycle.WebApplicationLifeCycle.applicationStarted(WebApplicationLifeCycle.java:196)
> at
> org.apache.webbeans.servlet.WebBeansConfigurationListener.contextInitialized(WebBeansConfigurationListener.java:60)
> ===THE ALTERNATIVE PRODUCER
> BEAN===============================================================
> public class AlternativeBeanProducer2 {
> public @Produces @Alternative @QualifierProducerBased IProducedBean
> generateBean2(@New AlternativeBeanClass1 beanClass) {
> return new AbstractProducedBean(beanClass, this);
> }
> /*
> public void dumpBean2(
> @Disposes @QualifierProducer IProducedBean bean, ILog
> log) {
> log.log(bean + " is dumped by
> AlternativeBeanProducer2");
> }
> */
>
> }
> ========================================================================
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.