[
https://issues.apache.org/jira/browse/OWB-1004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14128932#comment-14128932
]
Antonin Stefanutti commented on OWB-1004:
-----------------------------------------
That's what [~arne] pointed out. We want to be able to use a single annotation
as a qualifier with binding parameters and use these parameters as metadata.
Let say we're using Java 8, and we're writing a static version of what we want,
we would write:
{code}
@Qualifier
@Repeatable(ContextNames.class)
public interface @ContextName {
String value;
}
public @interface ContextNames {
ContextName[] value();
}
{code}
And then:
{code}
@ContextName("ctx1")
class CamelContext1 {
}
@ContextName("ctx2")
class CamelContext2 {
}
@Uri("")
@Produces
@ContextName("ctx1")
@ContextName("ctx2")
static ProducerTemplate producerTemplate(InjectionPoint ip, @Any
Instance<CamelContext> instance) {
}
{code}
Now, we'd want to be able to replicate that principle, in a generic way, with a
CDI extension, e.g.:
{code}
void producerTemplates(@Observes ProcessBeanAttributes<ProducerTemplate> pba) {
pba.setBeanAttributes(new BeanAttributes() {
public Set<Annotation> getQualifiers() {
Set<Annotation> annotations = new
HashSet<>(pba.getBeanAttributes().getQualifiers());
annotations.addAll(new ContextNameLiteral("ctx1"));
annotations.addAll(new ContextNameLiteral("ctx2"));
return qualifiers;
}
);
}
{code}
In the _hard-coded_ example, I would expect the
{{pba.getBeanAttributes().getQualifiers()}} to return two repeated
{{@ContextName}} annotations. Consequently, we should be able to add repeatable
qualifiers.
The container annotation is kept for compatibility reasons but I don't see any
reasons why that concern should transpire to the CDI SPI.
> Enable repeatable qualifiers with binding attributes
> ----------------------------------------------------
>
> Key: OWB-1004
> URL: https://issues.apache.org/jira/browse/OWB-1004
> Project: OpenWebBeans
> Issue Type: Improvement
> Components: Core
> Affects Versions: 2.0.0
> Reporter: Antonin Stefanutti
>
> While having multiple annotations of the same type declared on a member or
> type is not permitted in the Java language prior to Java 8, the CDI
> specification does not set any particular restriction in its SPI that enables
> to alter bean metadata, e.g. in {{Annotated.getAnnotations()}} and
> {{BeanAttributes.getQualifiers()}}, in a way to add multiple annotations of
> the same type.
> Having multiple CDI qualifiers of the same type can prove to be useful when
> this type declares binding attributes.
> Unfortunately, in such situation, the following exception is thrown by OWB
> version 2.0-SNASHOT:
> {code}
> javax.enterprise.inject.spi.DefinitionException:
> java.lang.IllegalArgumentException: Manager.resolveDecorators() method
> parameter qualifiers array argument can not define duplicate qualifier
> annotation with name : @org.apache.camel.cdi.ContextName
> at
> org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:284)
> at
> org.apache.webbeans.lifecycle.AbstractLifeCycle.bootstrapApplication(AbstractLifeCycle.java:138)
> at
> org.apache.webbeans.lifecycle.AbstractLifeCycle.startApplication(AbstractLifeCycle.java:104)
> at
> org.apache.webbeans.arquillian.standalone.OwbStandaloneContainer.deploy(OwbStandaloneContainer.java:122)
> {code}
> IMO, preventing the ability to add multiple annotations of the same type via
> the CDI SPI restricts powerful use cases (I can share more details on these
> use cases if needed). Last but not least, having this ability built-in in the
> Java 8 language is another incentive to provide that support.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)