Skip to content

Commit

Permalink
respect existing qualifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Jul 25, 2010
1 parent d17c720 commit 86299d9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
Expand Up @@ -29,6 +29,7 @@
import javax.enterprise.context.Dependent;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.spi.AfterBeanDiscovery;
import javax.enterprise.inject.spi.AfterDeploymentValidation;
import javax.enterprise.inject.spi.Annotated;
Expand Down Expand Up @@ -332,17 +333,17 @@ private <X> Bean<X> createGenericBean(Bean<X> originalBean, Annotation genericCo

private <X, T> Bean<T> createGenericProducerMethod(Bean<T> originalBean, Annotation genericConfiguration, AnnotatedMethod<X> method, BeanManager beanManager)
{
Set<Annotation> qualifiers = getQualifiers(genericProducers.get(genericConfiguration.annotationType()).get(genericConfiguration).getAnnotations(), beanManager);
Set<Annotation> qualifiers = getQualifiers(genericProducers.get(genericConfiguration.annotationType()).get(genericConfiguration).getAnnotations(), originalBean, beanManager);
return new GenericProducerMethod<T, X>(originalBean, genericConfiguration, method, qualifiers, syntheticProvider, beanManager);
}

private <X, T> Bean<T> createGenericProducerField(Bean<T> originalBean, Annotation genericConfiguration, AnnotatedField<X> field, BeanManager beanManager)
{
Set<Annotation> qualifiers = getQualifiers(genericProducers.get(genericConfiguration.annotationType()).get(genericConfiguration).getAnnotations(), beanManager);
Set<Annotation> qualifiers = getQualifiers(genericProducers.get(genericConfiguration.annotationType()).get(genericConfiguration).getAnnotations(), originalBean, beanManager);
return new GenericProducerField<T, X>(originalBean, genericConfiguration, field, qualifiers, syntheticProvider, beanManager);
}

private static Set<Annotation> getQualifiers(Set<Annotation> annotations, BeanManager beanManager)
private static Set<Annotation> getQualifiers(Set<Annotation> annotations, Bean<?> originalBean, BeanManager beanManager)
{
Set<Annotation> qualifiers = new HashSet<Annotation>();
for (Annotation annotation : annotations)
Expand All @@ -352,6 +353,13 @@ private static Set<Annotation> getQualifiers(Set<Annotation> annotations, BeanMa
qualifiers.add(annotation);
}
}
for (Annotation annotation : originalBean.getQualifiers())
{
if (!annotation.annotationType().equals(Default.class))
{
qualifiers.add(annotation);
}
}
return qualifiers;
}

Expand Down
Expand Up @@ -47,7 +47,7 @@ public Message getMessage()
return message;
}

@Produces
@Produces @Qux
public String getBarMessage()
{
return "bar" + getInjectedMessage().value();
Expand Down
Expand Up @@ -55,10 +55,10 @@ public static Archive<?> deploy()
@Foo(2)
private Bar bar2;

@Inject @Foo(1)
@Inject @Qux @Foo(1)
private String bar1Message;

@Inject @Foo(2)
@Inject @Qux @Foo(2)
private String bar2Message;

@Inject @Foo(1)
Expand Down
@@ -0,0 +1,43 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.weld.extensions.test.bean.generic.field;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.inject.Qualifier;

/**
* A qualifier
*
* @author pmuir
*
*/

@Retention(RUNTIME)
@Target({METHOD, FIELD, PARAMETER, TYPE})
@Qualifier
public @interface Qux
{

}

0 comments on commit 86299d9

Please sign in to comment.