Package javax.inject

Examples of javax.inject.Named


    public void assertCreatedAnnotationEqualToLiteral()
    {
        Map<String, String> memberValue = new HashMap<String, String>();
        memberValue.put("value", "test");

        Named named1 = AnnotationInstanceProvider.of(Named.class, memberValue);
        Named named2 = new NamedLiteral("test");

        assertTrue(named2.equals(named1));
        assertTrue(named1.equals(named2));
    }
View Full Code Here


    public void assertCreatedAnnotationNotEqualToLiteralWithDifferentMemberValues()
    {
        Map<String, String> memberValue = new HashMap<String, String>();
        memberValue.put("value", "test1");

        Named named1 = AnnotationInstanceProvider.of(Named.class, memberValue);
        Named named2 = new NamedLiteral("test");

        assertFalse(named1.equals(named2));
    }
View Full Code Here

    }

    @Test
    public void assertHashCodeSameAsLiteral()
    {
        Named a1 = AnnotationInstanceProvider.of(Named.class);
        Named a2 = new NamedLiteral();

        assertThat(a2.hashCode(), is(a1.hashCode()));
    }
View Full Code Here

            {
                for (Object type : types)
                {
                    if (type instanceof Class)
                    {
                        Named namedAnnotation = ((Class<?>) type).getAnnotation(Named.class);

                        if (namedAnnotation == null)
                        {
                            continue;
                        }

                        String result = namedAnnotation.value();
                        if (!"".equals(result))
                        {
                            return result;
                        }
                        return Introspector.decapitalize(((Class<?>) type).getSimpleName());
View Full Code Here

        private CallbackEntry(Class beanClass, Class<? extends Annotation> callbackMarker)
        {
            this.targetBeanClass = beanClass;

            Named named = this.targetBeanClass.getAnnotation(Named.class);

            if (named != null && !"".equals(named.value()))
            {
                this.beanName = named.value();
            }
            else
            {
                //fallback to the default (which might exist) -> TODO check meta-data of Bean<T>
                this.beanName = Introspector.decapitalize(targetBeanClass.getSimpleName());
View Full Code Here

    boolean required;
    if (annot != null) {
      name = annot.name();
      required = annot.required();
    } else {
      Named named = field.getAnnotation(Named.class);
      name = named != null ? named.value() : "";
      required = false;
    }

    if (Strings.isEmpty(name))
    {
View Full Code Here

     */
    private String getName(Object instance) {
        String name = instance.getClass().getSimpleName().substring(0, 1).toLowerCase()
                + instance.getClass().getSimpleName().substring(1);

        Named named = instance.getClass().getAnnotation(Named.class);
        if (named != null && named.value() != null && !named.value().trim().equals("")) {
            name = named.value();
        }
        return name;
    }
View Full Code Here

    if (producerMember.isAnnotationPresent(Specializes.class)) {
      makeSpecialized(injectionContext);
    }

    if (producerMember.isAnnotationPresent(Named.class)) {
      final Named namedAnnotation = producerMember.getAnnotation(Named.class);

      this.beanName = namedAnnotation.value().equals("")
          ? ReflectionUtil.getPropertyFromAccessor(producerMember.getName()) : namedAnnotation.value();
    }

    injectionContext.addInjectorRegistrationListener(producerMember.getDeclaringClass(),
        new InjectorRegistrationListener() {
          @Override
View Full Code Here

         {
            LOG.debug(logMessagePrefix + ": Primitive types are not supported");
         }
         return 1;
      }
      Named named = null;
      Class<?> qualifier = null;
      for (int i = 0, length = annotations.length; i < length; i++)
      {
         Annotation a = annotations[i];
         if (a instanceof Named)
         {
            named = (Named)a;
            break;
         }
         else if (a.annotationType().isAnnotationPresent(Qualifier.class))
         {
            qualifier = a.annotationType();
            break;
         }
      }
      if (type.isInterface() && type.equals(Provider.class))
      {
         if (!(genericType instanceof ParameterizedType))
         {
            if (LOG.isDebugEnabled())
            {
               LOG.debug(logMessagePrefix + ": The generic type is not of type ParameterizedType");
            }
            return 2;
         }
         ParameterizedType aType = (ParameterizedType)genericType;
         Type[] typeVars = aType.getActualTypeArguments();
         Class<?> expectedType = (Class<?>)typeVars[0];
         final ComponentAdapter<?> adapter;
         if (named != null)
         {
            adapter = holder.getComponentAdapter(named.value(), expectedType);
         }
         else if (qualifier != null)
         {
            adapter = holder.getComponentAdapter(qualifier, expectedType);
         }
         else
         {
            adapter = holder.getComponentAdapterOfType(expectedType);
         }

         if (adapter == null)
         {
            if (LOG.isDebugEnabled())
            {
               LOG.debug(logMessagePrefix + ": We have no value to set so we skip it");
            }
            return 3;
         }
         return new Provider<Object>()
         {
            public Object get()
            {
               return adapter.getComponentInstance();
            }
         };
      }
      else
      {
         if (named != null)
         {
            return holder.getComponentInstance(named.value(), type);
         }
         else if (qualifier != null)
         {
            return holder.getComponentInstance(qualifier, type);
         }
View Full Code Here

    if (producerMember.isAnnotationPresent(Specializes.class)) {
      makeSpecialized(injectionContext);
    }

    if (producerMember.isAnnotationPresent(Named.class)) {
      final Named namedAnnotation = producerMember.getAnnotation(Named.class);

      this.beanName = namedAnnotation.value().equals("")
          ? ReflectionUtil.getPropertyFromAccessor(producerMember.getName()) : namedAnnotation.value();
    }

    injectionContext.addInjectorRegistrationListener(producerMember.getDeclaringClass(),
        new InjectorRegistrationListener() {
          @Override
View Full Code Here

TOP

Related Classes of javax.inject.Named

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.