Java Code Examples for javax.inject.Qualifier

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project eclipse.platform.runtime, under directory /bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/.

Source file: ObjectDescriptor.java

  19 
vote

private Annotation[] qualifiers(Annotation[] allAnnotations){
  if (allAnnotations.length == 0)   return null;
  Annotation[] result;
  List<Annotation> qualifiers=new ArrayList<Annotation>();
  for (  Annotation annotation : allAnnotations) {
    if (annotation.annotationType().isAnnotationPresent(Qualifier.class))     qualifiers.add(annotation);
  }
  if (qualifiers.isEmpty())   return null;
  result=new Annotation[qualifiers.size()];
  qualifiers.toArray(result);
  return result;
}
 

Example 2

From project framework, under directory /impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/.

Source file: CustomBean.java

  19 
vote

@SuppressWarnings("serial") public Set<Annotation> getQualifiers(){
  Set<Annotation> result=new HashSet<Annotation>();
  result.add(new AnnotationLiteral<Default>(){
  }
);
  result.add(new AnnotationLiteral<Any>(){
  }
);
  for (  Annotation annotation : beanClass.getAnnotations()) {
    if (annotation.getClass().isAnnotationPresent(Qualifier.class)) {
      result.add(annotation);
    }
  }
  return result;
}
 

Example 3

From project guice-automatic-injection, under directory /core/src/main/java/de/devsurf/injection/guice/annotations/features/.

Source file: AutoBindingFeature.java

  19 
vote

@SuppressWarnings("unchecked") protected Map<String,Annotation> filter(final Map<String,Annotation> annotations){
  Map<String,Annotation> filtered=new HashMap<String,Annotation>(annotations);
  for (  Entry<String,Annotation> entry : annotations.entrySet()) {
    String key=entry.getKey();
    if (qualifiers.contains(key)) {
      continue;
    }
    if (others.contains(key)) {
      filtered.remove(key);
      continue;
    }
    Class<? extends Annotation> annotation;
    try {
      annotation=(Class<? extends Annotation>)Class.forName(key);
      if (annotation.isAnnotationPresent(GuiceAnnotation.class)) {
        filtered.remove(key);
        others.add(key);
        continue;
      }
      if (annotation.isAnnotationPresent(Qualifier.class)) {
        qualifiers.add(key);
        continue;
      }
      if (annotation.isAnnotationPresent(BindingAnnotation.class)) {
        qualifiers.add(key);
        continue;
      }
      filtered.remove(key);
      others.add(key);
    }
 catch (    ClassNotFoundException e) {
    }
  }
  return filtered;
}
 

Example 4

From project jms, under directory /impl/src/main/java/org/jboss/seam/jms/bridge/.

Source file: RouteImpl.java

  19 
vote

public Route addQualifiers(Collection<Annotation> q){
  if (q != null) {
    for (    Annotation qualifier : q) {
      if (!qualifier.annotationType().isAnnotationPresent(Qualifier.class)) {
        throw new IllegalArgumentException("not a qualifier: " + qualifier);
      }
      qualifiers.add(qualifier);
    }
  }
  return this;
}
 

Example 5

From project jms, under directory /impl/src/main/java/org/jboss/seam/jms/.

Source file: Seam3JmsExtension.java

  19 
vote

private static Set<Annotation> getQualifiersFrom(Set<Annotation> annotations){
  Set<Annotation> q=new HashSet<Annotation>();
  log.debug("Annotations in getQualifiersFrom: " + annotations);
  for (  Annotation a : annotations) {
    if (a.annotationType().isAnnotationPresent(Qualifier.class)) {
      q.add(a);
    }
 else {
      log.infof("Skipping annotation %s",a);
    }
  }
  return q;
}
 

Example 6

From project juzu, under directory /core/src/main/java/juzu/impl/inject/.

Source file: BeanDescriptor.java

  19 
vote

public BeanDescriptor(Class<?> declaredType,Scope scope,List<Annotation> qualifiers,Class<?> implementationType) throws NullPointerException, IllegalArgumentException {
  if (declaredType == null) {
    throw new NullPointerException("No null declared type accepted");
  }
  if (qualifiers != null) {
    for (    Annotation qualifier : qualifiers) {
      if (qualifier.annotationType().getAnnotation(Qualifier.class) == null) {
        throw new IllegalArgumentException("Qualifier annotation " + qualifier + " is not annotated with @Qualifier");
      }
    }
  }
  this.declaredType=declaredType;
  this.scope=scope;
  this.qualifiers=qualifiers;
  this.implementationType=implementationType;
}
 

Example 7

From project juzu, under directory /core/src/main/java/juzu/impl/inject/.

Source file: BeanDescriptor.java

  19 
vote

private static Collection<Annotation> determineQualifiers(Collection<Annotation> qualifiers,Class<?> implementation){
  Collection<Annotation> overridenQualifiers=null;
  try {
    Method get=implementation.getMethod("get");
    for (    Annotation annotation : get.getAnnotations()) {
      if (annotation.annotationType().getAnnotation(Qualifier.class) != null) {
        if (overridenQualifiers == null) {
          overridenQualifiers=new ArrayList<Annotation>();
        }
        overridenQualifiers.add(annotation);
      }
    }
  }
 catch (  NoSuchMethodException e) {
    throw new UndeclaredThrowableException(e);
  }
  if (overridenQualifiers != null) {
    qualifiers=overridenQualifiers;
  }
  return qualifiers;
}
 

Example 8

From project juzu, under directory /core/src/main/java/juzu/impl/inject/spi/guice/.

Source file: BeanBinding.java

  19 
vote

BeanBinding(Class<T> type,Scope scope,Iterable<Annotation> declaredQualifiers,Class<? extends T> beanType){
  Class<? extends Annotation> scopeType=null;
  Map<Class<?>,Annotation> qualifiers=null;
  if (declaredQualifiers != null) {
    for (    Annotation declaredQualifier : declaredQualifiers) {
      if (qualifiers == null) {
        qualifiers=new HashMap<Class<?>,Annotation>();
      }
      qualifiers.put(declaredQualifier.annotationType(),declaredQualifier);
    }
  }
  if (beanType != null) {
    for (    Annotation ann : beanType.getDeclaredAnnotations()) {
      if (ann.annotationType().getAnnotation(Qualifier.class) != null) {
        if (qualifiers == null) {
          qualifiers=new HashMap<Class<?>,Annotation>();
        }
        qualifiers.put(ann.annotationType(),ann);
      }
      if (ann.annotationType().getAnnotation(javax.inject.Scope.class) != null) {
        scopeType=ann.annotationType();
      }
    }
  }
  if (scope != null) {
    scopeType=scope.getAnnotationType();
  }
  this.type=type;
  this.qualifiers=qualifiers != null ? qualifiers.values() : null;
  this.scopeType=scopeType;
}
 

Example 9

From project openwebbeans, under directory /webbeans-impl/src/main/java/org/apache/webbeans/annotation/.

Source file: AnnotationManager.java

  19 
vote

/** 
 * Returns true if the annotation is defined in xml or annotated with {@link javax.inject.Qualifier} false otherwise.
 * @param clazz type of the annotation
 * @return true if the annotation is defined in xml or annotated with{@link javax.inject.Qualifier} false otherwise
 */
public boolean isQualifierAnnotation(Class<? extends Annotation> clazz){
  Asserts.nullCheckForClass(clazz);
  if (clazz.isAnnotationPresent(Qualifier.class)) {
    return true;
  }
 else   if (beanManagerImpl.getAdditionalQualifiers().contains(clazz)) {
    return true;
  }
  return false;
}
 

Example 10

From project rewrite, under directory /integration-cdi/src/main/java/org/ocpsoft/rewrite/cdi/util/.

Source file: Reflections.java

  19 
vote

/** 
 * Checks the bindingType to make sure the annotation was declared properly as a binding type (annotated with @BindingType) and that it has a runtime retention policy.
 * @param binding The binding type to check
 * @return true only if the annotation is really a binding type
 */
@Deprecated public static boolean isBindings(Annotation binding){
  boolean isBindingAnnotation=false;
  if (binding.annotationType().isAnnotationPresent(Qualifier.class) && binding.annotationType().isAnnotationPresent(Retention.class) && binding.annotationType().getAnnotation(Retention.class).value().equals(RetentionPolicy.RUNTIME)) {
    isBindingAnnotation=true;
  }
  return isBindingAnnotation;
}
 

Example 11

From project solder, under directory /api/src/main/java/org/jboss/solder/reflection/.

Source file: Reflections.java

  19 
vote

/** 
 * Checks the bindingType to make sure the annotation was declared properly as a binding type (annotated with @BindingType) and that it has a runtime retention policy.
 * @param binding The binding type to check
 * @return true only if the annotation is really a binding type
 */
@Deprecated public static boolean isBindings(Annotation binding){
  boolean isBindingAnnotation=false;
  if (binding.annotationType().isAnnotationPresent(Qualifier.class) && binding.annotationType().isAnnotationPresent(Retention.class) && binding.annotationType().getAnnotation(Retention.class).value().equals(RetentionPolicy.RUNTIME)) {
    isBindingAnnotation=true;
  }
  return isBindingAnnotation;
}
 

Example 12

From project spring-data-commons, under directory /spring-data-commons-core/src/main/java/org/springframework/data/repository/cdi/.

Source file: CdiRepositoryExtensionSupport.java

  19 
vote

/** 
 * Determines the qualifiers of the given type.
 */
@SuppressWarnings("serial") private Set<Annotation> getQualifiers(final Class<?> type){
  Set<Annotation> qualifiers=new HashSet<Annotation>();
  Annotation[] annotations=type.getAnnotations();
  for (  Annotation annotation : annotations) {
    Class<? extends Annotation> annotationType=annotation.annotationType();
    if (annotationType.isAnnotationPresent(Qualifier.class)) {
      qualifiers.add(annotation);
    }
  }
  if (qualifiers.isEmpty()) {
    qualifiers.add(new AnnotationLiteral<Default>(){
    }
);
  }
  qualifiers.add(new AnnotationLiteral<Any>(){
  }
);
  return qualifiers;
}
 

Example 13

From project spring-js, under directory /src/test/java/org/springframework/beans/factory/support/.

Source file: InjectAnnotationAutowireContextTests.java

  19 
vote

@Test public void testAutowiredFieldDoesNotResolveWithBaseQualifierAndNonDefaultValueAndMultipleMatchingCandidates(){
  GenericApplicationContext context=new GenericApplicationContext();
  ConstructorArgumentValues cavs1=new ConstructorArgumentValues();
  cavs1.addGenericArgumentValue("the real juergen");
  RootBeanDefinition person1=new RootBeanDefinition(Person.class,cavs1,null);
  person1.addQualifier(new AutowireCandidateQualifier(Qualifier.class,"juergen"));
  ConstructorArgumentValues cavs2=new ConstructorArgumentValues();
  cavs2.addGenericArgumentValue("juergen imposter");
  RootBeanDefinition person2=new RootBeanDefinition(Person.class,cavs2,null);
  person2.addQualifier(new AutowireCandidateQualifier(Qualifier.class,"juergen"));
  context.registerBeanDefinition("juergen1",person1);
  context.registerBeanDefinition("juergen2",person2);
  context.registerBeanDefinition("autowired",new RootBeanDefinition(QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean.class));
  AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
  try {
    context.refresh();
    fail("expected BeanCreationException");
  }
 catch (  BeanCreationException e) {
    assertTrue(e instanceof UnsatisfiedDependencyException);
    assertEquals("autowired",e.getBeanName());
  }
}