Java 类javax.enterprise.inject.spi.Annotated 实例源码

项目:Biliomi    文件:AppDataProducer.java   
@Produces
@AppData("PRODUCER")
public String getAppDataValueAsString(InjectionPoint injectionPoint) {
  Annotated annotated = injectionPoint.getAnnotated();
  String key = null;
  String value = null;

  if (annotated.isAnnotationPresent(AppData.class)) {
    AppData annotation = annotated.getAnnotation(AppData.class);
    key = annotation.value();
    value = properties.getProperty(key);
  }

  if (value == null) {
    throw new IllegalArgumentException("No AppData value found for key " + key);
  }

  return value;
}
项目:Biliomi    文件:UserSettingsProducer.java   
@Produces
@CoreSetting("PRODUCER")
public String getUserSetting(InjectionPoint injectionPoint) {
  Annotated annotated = injectionPoint.getAnnotated();

  if (annotated.isAnnotationPresent(CoreSetting.class)) {
    String settingPath = annotated.getAnnotation(CoreSetting.class).value();
    Object object = yamlCoreSettings;
    String[] split = settingPath.split("\\.");
    int c = 0;

    while (c < split.length) {
      try {
        object = PropertyUtils.getProperty(object, split[c]);
        c++;
      } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
        LogManager.getLogger(getClass()).error("Failed retrieving setting " + settingPath, e);
        return null;
      }
    }

    return String.valueOf(object);
  }

  return null;
}
项目:Biliomi    文件:LocalizationProducer.java   
@Produces
public I18nMap createL10nMap(InjectionPoint injectionPoint) {
  Annotated annotated = injectionPoint.getAnnotated();
  String baseName;

  if (annotated.isAnnotationPresent(I18nData.class)) {
    baseName = annotated.getAnnotation(I18nData.class).value().getSimpleName();
  } else {
    baseName = injectionPoint.getBean().getBeanClass().getSimpleName();
  }

  File langFile = new File(langBase, baseName + ".properties");
  I18NMapImpl l10NMap = new I18NMapImpl(commonLang);

  try (InputStream stream = new FileInputStream(langFile)) {
    l10NMap.load(stream);
  } catch (IOException e) {
    // I18n data will be injected in all components,
    // but a component is not required to have a language definition
    // This implementation will return an empty I18nMap containing only able to supply common strings
  }

  return l10NMap;
}
项目:cito    文件:PathParamProducerTest.java   
@Test
public void pathParam() {
    final InjectionPoint ip = mock(InjectionPoint.class);
    final PathParser parser = new PathParser("/{there}");
    final Message msg = mock(Message.class);
    final DestinationChanged dc = mock(DestinationChanged.class);
    final Frame frame = mock(Frame.class);
    when(msg.frame()).thenReturn(frame);
    when(frame.destination()).thenReturn(Optional.of("/here"));
    final Annotated annotated = mock(Annotated.class);
    when(ip.getAnnotated()).thenReturn(annotated);
    when(annotated.getAnnotation(PathParam.class)).thenReturn(createPathParam("there"));

    final String param = PathParamProducer.pathParam(ip, parser, msg, dc);
    assertEquals("here", param);

    verify(msg).frame();
    verify(frame).destination();
    verify(ip).getAnnotated();
    verify(annotated).getAnnotation(PathParam.class);
    verifyNoMoreInteractions(ip, msg, dc, frame, annotated);
}
项目:cito    文件:PathParamProducerTest.java   
@Test
public void pathParam_message() {
    final InjectionPoint ip = mock(InjectionPoint.class);
    final PathParser parser = new PathParser("/{there}");
    final Message msg = mock(Message.class);
    final Frame frame = mock(Frame.class);
    when(msg.frame()).thenReturn(frame);
    when(frame.destination()).thenReturn(Optional.of("/here"));
    final Annotated annotated = mock(Annotated.class);
    when(ip.getAnnotated()).thenReturn(annotated);
    when(annotated.getAnnotation(PathParam.class)).thenReturn(createPathParam("there"));

    final String param = PathParamProducer.pathParam(ip, parser, msg, null);
    assertEquals("here", param);

    verify(msg).frame();
    verify(frame).destination();
    verify(ip).getAnnotated();
    verify(annotated).getAnnotation(PathParam.class);
    verifyNoMoreInteractions(ip, msg, frame, annotated);
}
项目:cito    文件:PathParamProducerTest.java   
@Test
public void pathParam_destination() {
    final InjectionPoint ip = mock(InjectionPoint.class);
    final PathParser parser = new PathParser("/{there}");
    final DestinationChanged dc = mock(DestinationChanged.class);
    when(dc.getDestination()).thenReturn("/here");
    final Annotated annotated = mock(Annotated.class);
    when(ip.getAnnotated()).thenReturn(annotated);
    when(annotated.getAnnotation(PathParam.class)).thenReturn(createPathParam("there"));

    final String param = PathParamProducer.pathParam(ip, parser, null, dc);
    assertEquals("here", param);

    verify(dc).getDestination();
    verify(ip).getAnnotated();
    verify(annotated).getAnnotation(PathParam.class);
    verifyNoMoreInteractions(ip, dc, annotated);
}
项目:servicelink    文件:URIExposer.java   
@Produces
@LegacyLink
public String exposeLegacyLink(InjectionPoint ip) {
    Annotated field = ip.getAnnotated();
    LegacyLink link = field.getAnnotation(LegacyLink.class);
    String linkName = link.name();
    if (linkName.isEmpty()) {
        linkName = ip.getMember().getName().toUpperCase();
    }
    int portNumber = link.portNumber();
    String resource = link.path();
    if (resource.isEmpty()) {
        return URIProvider.computeURIWithEnvironmentEntries(linkName, portNumber);
    } else {
        return URIProvider.computeURIWithEnvironmentEntries(linkName, portNumber, resource);
    }
}
项目:servicelink    文件:URIExposer.java   
@Produces
@Link
public String expose(InjectionPoint ip) {
    Annotated field = ip.getAnnotated();
    Link link = field.getAnnotation(Link.class);
    String linkName = link.name();
    if (linkName.isEmpty()) {
        linkName = ip.getMember().getName().toUpperCase();
    }
    int portNumber = link.portNumber();
    String resource = link.path();
    if (resource.isEmpty()) {
        return URIProvider.computeUri(linkName, portNumber);
    } else {
        return URIProvider.computeUri(linkName, portNumber, resource);
    }
}
项目:property-inject    文件:PropertyFactory.java   
String getPropertyName(final InjectionPoint point, final String propertyName) {
    if (!propertyName.isEmpty()) {
        return propertyName;
    }

    Member member = point.getMember();
    final String name;

    if (member instanceof Executable) {
        Annotated annotated = point.getAnnotated();
        int p = ((AnnotatedParameter<?>) annotated).getPosition();
        name = member.getName() + ".arg" + p;
    } else {
        name = member.getName();
    }

    return name;
}
项目:Camel    文件:CamelContextProducer.java   
private static CamelContextNameStrategy nameStrategy(Annotated annotated) {
    if (annotated.isAnnotationPresent(ContextName.class)) {
        return new ExplicitCamelContextNameStrategy(annotated.getAnnotation(ContextName.class).value());
    } else if (annotated.isAnnotationPresent(Named.class)) {
        // TODO: support stereotype with empty @Named annotation
        String name = annotated.getAnnotation(Named.class).value();
        if (name.isEmpty()) {
            if (annotated instanceof AnnotatedField) {
                name = ((AnnotatedField) annotated).getJavaMember().getName();
            } else if (annotated instanceof AnnotatedMethod) {
                name = ((AnnotatedMethod) annotated).getJavaMember().getName();
                if (name.startsWith("get")) {
                    name = decapitalize(name.substring(3));
                }
            } else {
                name = decapitalize(getRawType(annotated.getBaseType()).getSimpleName());
            }
        }
        return new ExplicitCamelContextNameStrategy(name);
    } else {
        // Use a specific naming strategy for Camel CDI as the default one increments the suffix for each CDI proxy created
        return new CdiCamelContextNameStrategy();
    }
}
项目:ocelot    文件:TopicsMessagesObserversTest.java   
/**
 * Test of sendObjectToTopic method, of class TopicsMessagesBroadcaster.
 *
 * @throws org.ocelotds.marshalling.exceptions.JsonMarshallingException
 */
@Test
public void testSendObjectToTopicNotAnnotated() throws JsonMarshallingException {
    System.out.println("sendObjectToTopic");
    EventMetadata metadata = mock(EventMetadata.class);
    InjectionPoint injectionPoint = mock(InjectionPoint.class);
    Annotated annotated = mock(Annotated.class);

    when(metadata.getInjectionPoint()).thenReturn(injectionPoint);
    when(injectionPoint.getAnnotated()).thenReturn(annotated);
    when(annotated.getAnnotation(JsTopicEvent.class)).thenReturn(null);

    // no JsTopicEvent
    instance.sendObjectToTopic(PAYLOAD, metadata);
    verify(instance, never()).sendMessageToTopic(any(MessageToClient.class));
}
项目:ocelot    文件:TopicsMessagesObserversTest.java   
/**
 * Test of sendObjectToTopic method, of class TopicsMessagesBroadcaster.
 *
 * @throws org.ocelotds.marshalling.exceptions.JsonMarshallingException
 */
@Test
public void testSendObjectToTopicWithoutMarshaller() throws JsonMarshallingException {
    System.out.println("sendObjectToTopic");
    EventMetadata metadata = mock(EventMetadata.class);
    InjectionPoint injectionPoint = mock(InjectionPoint.class);
    Annotated annotated = mock(Annotated.class);
    JsTopicEvent jte = mock(JsTopicEvent.class);

    when(metadata.getInjectionPoint()).thenReturn(injectionPoint);
    when(injectionPoint.getAnnotated()).thenReturn(annotated);
    when(annotated.getAnnotation(JsTopicEvent.class)).thenReturn(jte);
    when(annotated.getAnnotation(JsonMarshaller.class)).thenReturn(null);
    when(jte.value()).thenReturn(TOPIC);

    // JsTopicEvent, no marshaller
    instance.sendObjectToTopic(PAYLOAD, metadata);

    ArgumentCaptor<MessageToClient> captureMtC = ArgumentCaptor.forClass(MessageToClient.class);
    ArgumentCaptor<Object> captureObject = ArgumentCaptor.forClass(Object.class);
    verify(topicsMessagesBroadcaster).sendMessageToTopic(captureMtC.capture(), captureObject.capture());

    assertThat(captureMtC.getValue().getResponse()).isEqualTo(PAYLOAD);
    assertThat(captureObject.getValue()).isEqualTo(PAYLOAD);
}
项目:ocelot    文件:TopicsMessagesObserversTest.java   
/**
 * Test of sendObjectToTopic method, of class TopicsMessagesBroadcaster.
 *
 * @throws org.ocelotds.marshalling.exceptions.JsonMarshallingException
 */
@Test
public void testSendObjectToTopicJsonPayload() throws JsonMarshallingException {
    System.out.println("sendObjectToTopic");
    EventMetadata metadata = mock(EventMetadata.class);
    InjectionPoint injectionPoint = mock(InjectionPoint.class);
    Annotated annotated = mock(Annotated.class);
    JsTopicEvent jte = mock(JsTopicEvent.class);

    when(metadata.getInjectionPoint()).thenReturn(injectionPoint);
    when(injectionPoint.getAnnotated()).thenReturn(annotated);
    when(annotated.getAnnotation(JsTopicEvent.class)).thenReturn(jte);
    when(annotated.getAnnotation(JsonMarshaller.class)).thenReturn(null);
    when(jte.value()).thenReturn(TOPIC);
    when(jte.jsonPayload()).thenReturn(true);

    // JsTopicEvent, jsonPayload <,no marshaller
    instance.sendObjectToTopic(PAYLOAD, metadata);

    ArgumentCaptor<MessageToClient> captureMtC = ArgumentCaptor.forClass(MessageToClient.class);
    ArgumentCaptor<Object> captureObject = ArgumentCaptor.forClass(Object.class);
    verify(topicsMessagesBroadcaster).sendMessageToTopic(captureMtC.capture(), captureObject.capture());

    assertThat(captureMtC.getValue().getJson()).isEqualTo(PAYLOAD);
    assertThat(captureObject.getValue()).isEqualTo(PAYLOAD);
}
项目:ocelot    文件:TopicsMessagesObserversTest.java   
/**
 * Test of sendObjectToTopic method, of class TopicsMessagesBroadcaster.
 *
 * @throws org.ocelotds.marshalling.exceptions.JsonMarshallingException
 */
@Test
public void testSendObjectToTopicJsonPayloadFailed() throws JsonMarshallingException {
    System.out.println("sendObjectToTopic");
    EventMetadata metadata = mock(EventMetadata.class);
    InjectionPoint injectionPoint = mock(InjectionPoint.class);
    Annotated annotated = mock(Annotated.class);
    JsTopicEvent jte = mock(JsTopicEvent.class);

    when(metadata.getInjectionPoint()).thenReturn(injectionPoint);
    when(injectionPoint.getAnnotated()).thenReturn(annotated);
    when(annotated.getAnnotation(JsTopicEvent.class)).thenReturn(jte);
    when(annotated.getAnnotation(JsonMarshaller.class)).thenReturn(null);
    when(jte.value()).thenReturn(TOPIC);
    when(jte.jsonPayload()).thenReturn(true);

    // JsTopicEvent, jsonPayload <,no marshaller
    instance.sendObjectToTopic(new Long(5), metadata);

    verify(topicsMessagesBroadcaster, never()).sendMessageToTopic(any(MessageToClient.class), anyObject());
}
项目:ocelot    文件:TopicsMessagesObserversTest.java   
/**
 * Test of sendObjectToTopic method, of class TopicsMessagesBroadcaster.
 *
 * @throws org.ocelotds.marshalling.exceptions.JsonMarshallingException
 * @throws org.ocelotds.marshalling.exceptions.JsonMarshallerException
 */
@Test
public void testSendObjectToTopicWithMarshallerFail() throws JsonMarshallingException, JsonMarshallerException {
    System.out.println("sendObjectToTopic");
    EventMetadata metadata = mock(EventMetadata.class);
    InjectionPoint injectionPoint = mock(InjectionPoint.class);
    Annotated annotated = mock(Annotated.class);
    JsTopicEvent event = mock(JsTopicEvent.class);

    when(metadata.getInjectionPoint()).thenReturn(injectionPoint);
    when(injectionPoint.getAnnotated()).thenReturn(annotated);
    when(annotated.getAnnotation(JsTopicEvent.class)).thenReturn(event);
    when(annotated.getAnnotation(JsonMarshaller.class)).thenReturn(mock(JsonMarshaller.class));
    when(argumentServices.getJsonResultFromSpecificMarshaller(any(JsonMarshaller.class), anyObject())).thenThrow(JsonMarshallingException.class).thenThrow(JsonMarshallerException.class).thenThrow(Throwable.class);
    when(event.value()).thenReturn(TOPIC);

    // JsTopicEvent, marshaller
    instance.sendObjectToTopic(PAYLOAD, metadata);
    instance.sendObjectToTopic(PAYLOAD, metadata);
    instance.sendObjectToTopic(PAYLOAD, metadata);

    verify(topicsMessagesBroadcaster, never()).sendMessageToTopic(any(MessageToClient.class), anyObject());
}
项目:ocelot    文件:LoggerProducerTest.java   
/**
     * Test of getLogger method, of class LoggerProducer.
     */
    @Test
    public void testGetLogger() {
        System.out.println("getLogger");
        String expResult = LoggerProducerTest.class.getName();
        Member member = mock(Member.class);
        Annotated annotated = mock(Annotated.class);
        Class cls = LoggerProducerTest.class;
        OcelotLogger ol = mock(OcelotLogger.class);

        when(member.getDeclaringClass()).thenReturn(cls);
        when(injectionPoint.getMember()).thenReturn(member);
        when(injectionPoint.getAnnotated()).thenReturn(annotated);
        when(annotated.getAnnotation(eq(OcelotLogger.class))).thenReturn(ol);
        when(ol.name()).thenReturn("").thenReturn("SECURITY");

        Logger result = instance.getLogger(injectionPoint);
        assertThat(result.getName()).isEqualTo(expResult);

        result = instance.getLogger(injectionPoint);
        assertThat(result.getName()).isEqualTo("SECURITY");
}
项目:javaee_projects    文件:CacheExposer.java   
@Produces
public <K, V> Cache<K, V> exposeCache(InjectionPoint ip) {
    Annotated annotated = ip.getAnnotated();
    CacheContext annotation = annotated.getAnnotation(CacheContext.class);
    //single cache defined in DD, no annotation
    if (doesConventionApply(annotation)) {
        return (Cache<K, V>) this.caches.values().iterator().next();
    }
    //annotation defined, name is used to lookup cache
    if (annotation != null) {
        String cacheName = annotation.value();
        Cache<K, V> cache = (Cache<K, V>) this.caches.get(cacheName);
        if (cache == null) {
            throw new IllegalStateException("Unsatisfied cache dependency error. Cache with name: " + cacheName + " does not exist");
        }
        return cache;
    }
    String fieldName = ip.getMember().getDeclaringClass().getName() + "." + ip.getMember().getName();
    if (this.caches.isEmpty()) {
        throw new IllegalStateException("No caches defined " + fieldName);
    } else {
        throw new IllegalStateException("Ambiguous caches exception: " + this.caches.keySet() + " for field name " + fieldName);
    }
}
项目:camel-cdi    文件:CamelContextProducer.java   
private static CamelContextNameStrategy nameStrategy(Annotated annotated) {
    if (annotated.isAnnotationPresent(ContextName.class)) {
        return new ExplicitCamelContextNameStrategy(annotated.getAnnotation(ContextName.class).value());
    } else if (annotated.isAnnotationPresent(Named.class)) {
        // TODO: support stereotype with empty @Named annotation
        String name = annotated.getAnnotation(Named.class).value();
        if (name.isEmpty()) {
            if (annotated instanceof AnnotatedField) {
                name = ((AnnotatedField) annotated).getJavaMember().getName();
            } else if (annotated instanceof AnnotatedMethod) {
                name = ((AnnotatedMethod) annotated).getJavaMember().getName();
                if (name.startsWith("get"))
                    name = decapitalize(name.substring(3));
            } else {
                name = decapitalize(getRawType(annotated.getBaseType()).getSimpleName());
            }
        }
        return new ExplicitCamelContextNameStrategy(name);
    } else {
        // Use a specific naming strategy for Camel CDI as the default one increments the suffix for each CDI proxy created
        return new CdiCamelContextNameStrategy();
    }
}
项目:vraptor4    文件:EnvironmentPropertyProducer.java   
@Produces @Property
public String get(InjectionPoint ip) {
    Annotated annotated = ip.getAnnotated();
    Property property = annotated.getAnnotation(Property.class);
    String key = property.value();
    if (isNullOrEmpty(key)) {
        key = ip.getMember().getName();
    }

    String defaultValue = property.defaultValue();
    if(!isNullOrEmpty(defaultValue)){
        return environment.get(key, defaultValue);
    }

    return environment.get(key);
}
项目:cdi    文件:MybatisExtensionTest.java   
private <T> void projectInjectionTarget(MybatisExtension extension, Type type) {
  ProcessInjectionTarget<T> event = mock(ProcessInjectionTarget.class);
  InjectionTarget<T> injectTarget = mock(InjectionTarget.class);
  Set<InjectionPoint> injectionPoints = new HashSet<InjectionPoint>();

  InjectionPoint injectionPoint = mock(InjectionPoint.class);
  Annotated annotated = mock(Annotated.class);

  when(injectionPoint.getAnnotated()).thenReturn(annotated);

  when(annotated.getBaseType()).thenReturn(type);
  when(annotated.getAnnotations()).thenReturn(new HashSet<Annotation>());

  injectionPoints.add(injectionPoint);

  when(event.getInjectionTarget()).thenReturn(injectTarget);
  when(injectTarget.getInjectionPoints()).thenReturn(injectionPoints);

  extension.processInjectionTarget(event);
}
项目:deltaspike    文件:AnnotatedTypeBuilder.java   
protected void mergeAnnotationsOnElement(Annotated annotated,
                                         boolean overwriteExisting,
                                         AnnotationBuilder typeAnnotations)
{
    for (Annotation annotation : annotated.getAnnotations())
    {
        if (typeAnnotations.getAnnotation(annotation.annotationType()) != null)
        {
            if (overwriteExisting)
            {
                typeAnnotations.remove(annotation.annotationType());
                typeAnnotations.add(annotation);
            }
        }
        else
        {
            typeAnnotations.add(annotation);
        }
    }
}
项目:deltaspike    文件:BeanUtils.java   
/**
 * @param annotated element to search in
 * @param targetType target type to search for
 * @param <T> type of the Annotation which get searched
 * @return annotation instance extracted from the annotated member
 */
public static <T extends Annotation> T extractAnnotation(Annotated annotated, Class<T> targetType)
{
    T result = annotated.getAnnotation(targetType);

    if (result == null)
    {
        for (Annotation annotation : annotated.getAnnotations())
        {
            result = annotation.annotationType().getAnnotation(targetType);

            if (result != null)
            {
                break;
            }
        }
    }

    return result;
}
项目:Mastering-Java-EE-Development-with-WildFly    文件:BankFactory.java   
@Produces
@BankProducer
public Bank createBank(@Any Instance<Bank> instance, InjectionPoint injectionPoint) {

    Annotated annotated = injectionPoint.getAnnotated();
    BankType bankTypeAnnotation = annotated.getAnnotation(BankType.class);
    Class<? extends Bank> bankType = bankTypeAnnotation.value().getBankType();
    return instance.select(bankType).get();
}
项目:weld-junit    文件:MockResourceInjectionServices.java   
private Resource getResourceAnnotation(InjectionPoint injectionPoint) {
    Annotated annotated = injectionPoint.getAnnotated();
    if (annotated instanceof AnnotatedParameter<?>) {
        annotated = ((AnnotatedParameter<?>) annotated).getDeclaringCallable();
    }
    return annotated.getAnnotation(Resource.class);
}
项目:payara-micro-docker-starter-kit    文件:ConfigProducer.java   
@Produces
@IConfig
public Config produce(InjectionPoint injectionPoint) throws IOException {
    Annotated annotated = injectionPoint.getAnnotated();
    IConfig iConfig = annotated.getAnnotation(IConfig.class);
    String key = iConfig.value();
    if (!configs.containsKey(key)) {
        Config config = new Config();
        config.load(key);
        configs.put(key, config);
    }
    return configs.get(key);
}
项目:cito    文件:BodyProducerExtensionTest.java   
@Test
public void captureProducerTypes() {
    final ProcessInjectionPoint<?, ?> pip = mock(ProcessInjectionPoint.class);
    final InjectionPoint ip = mock(InjectionPoint.class);
    when(pip.getInjectionPoint()).thenReturn(ip);
    final Annotated annotated = mock(Annotated.class);
    when(ip.getAnnotated()).thenReturn(annotated);
    when(annotated.isAnnotationPresent(Body.class)).thenReturn(true);
    when(ip.getType()).thenReturn(COLLECTION.getClass());
    @SuppressWarnings("unchecked")
    final InjectionTarget<Object> injectionTarget = mock(InjectionTarget.class);
    when(this.beanManager.createInjectionTarget(Mockito.any())).thenReturn(injectionTarget);
    final Member member = mock(Member.class);
    when(ip.getMember()).thenReturn(member);

    final List<Bean<?>> found = ReflectionUtil.get(this.extension, "found");
    assertTrue(found.isEmpty());

    this.extension.captureProducerTypes(pip, this.beanManager);

    assertEquals(1, found.size());

    verify(pip, times(2)).getInjectionPoint();
    verify(ip).getAnnotated();
    verify(annotated).isAnnotationPresent(Body.class);
    verify(ip).getType();
    verify(ip).getMember();
    verify(member).getName();
    verify(ip).getQualifiers();
    verify(injectionTarget).getInjectionPoints();
    verify(this.beanManager).createInjectionTarget(Mockito.any());
    verifyNoMoreInteractions(pip, ip, annotated, injectionTarget, member);
}
项目:jug-material    文件:InjectionPointTest.java   
@SuppressWarnings("serial")
@Test
public void injectedClassShouldBeOfSpecificTypeAndAnnotations() throws Exception {
    InjectionPoint injectionPoint = generator.getLatest();
    Annotated annotated = injectionPoint.getAnnotated();
    // you can infer the requested type for injection (for generic inception or for specific interfaces)
    assertThat(annotated.getBaseType()).isEqualTo(AddUserCommand.class);

    // you can get the annotations of the injected-to-be field/parameter
    Set<Annotation> annotations = annotated.getAnnotations();
    assertThat(isAnnotationPresentInSet(new AnnotationLiteral<ConfiguredForTest>(){}, annotations))
        .as("Annotation " + ConfiguredForTest.class.getSimpleName() + " should be present in injection point")
        .isTrue();

}
项目:property-inject    文件:PropertyResourceProducerBean.java   
@Produces
@Dependent
@PropertyResource
public Properties produceProperties(InjectionPoint point) {
    final Annotated annotated = point.getAnnotated();

    if (point.getType() != Properties.class) {
        throw new InjectionException(Properties.class + " can not be injected to type " + point.getType());
    }

    final Class<?> beanType = point.getBean().getBeanClass();
    final ClassLoader loader = beanType.getClassLoader();
    final PropertyResource annotation = annotated.getAnnotation(PropertyResource.class);
    final PropertyResourceFormat format = annotation.format();

    String locator = annotation.url();

    if (locator.isEmpty()) {
        locator = beanType.getName().replace('.', '/') + ".properties";
    }

    try {
        return factory.getProperties(loader, locator, format);
    } catch (Exception e) {
        throw new InjectionException(e);
    }
}
项目:zanata-mt    文件:EnvVariableProducerTest.java   
@Before
public void beforeTest() {
    ip = Mockito.mock(InjectionPoint.class);
    Annotated annotated = Mockito.mock(Annotated.class);
    envVariable = Mockito.mock(EnvVariable.class);

    when(ip.getAnnotated()).thenReturn(annotated);
    when(annotated.getAnnotation(EnvVariable.class))
            .thenReturn(envVariable);

    producer = new EnvVariableProducer();
}
项目:weld-vertx    文件:RouteExtension.java   
private WebRoute[] getWebRoutes(Annotated annotated) {
    WebRoute webRoute = annotated.getAnnotation(WebRoute.class);
    if (webRoute != null) {
        return new WebRoute[] { webRoute };
    }
    Annotation container = annotated.getAnnotation(WebRoutes.class);
    if (container != null) {
        WebRoutes webRoutes = (WebRoutes) container;
        return webRoutes.value();
    }
    return new WebRoute[] {};
}
项目:wildfly-swarm    文件:SeMetricName.java   
@Override
public String of(InjectionPoint ip) {
    Annotated annotated = ip.getAnnotated();
    if (annotated instanceof AnnotatedMember) {
        return of((AnnotatedMember<?>) annotated);
    } else if (annotated instanceof AnnotatedParameter) {
        return of((AnnotatedParameter<?>) annotated);
    } else {
        throw new IllegalArgumentException("Unable to retrieve metric name for injection point [" + ip + "], only members and parameters are supported");
    }
}
项目:octopus-jsr375    文件:CdiUtils.java   
public static <A extends Annotation> Optional<A> getAnnotation(BeanManager beanManager, Annotated annotated, Class<A> annotationType) {

        annotated.getAnnotation(annotationType);

        if (annotated.getAnnotations().isEmpty()) {
            return empty();
        }

        if (annotated.isAnnotationPresent(annotationType)) {
            return Optional.of(annotated.getAnnotation(annotationType));
        }

        Queue<Annotation> annotations = new LinkedList<>(annotated.getAnnotations());

        while (!annotations.isEmpty()) {
            Annotation annotation = annotations.remove();

            if (annotation.annotationType().equals(annotationType)) {
                return Optional.of(annotationType.cast(annotation));
            }

            if (beanManager.isStereotype(annotation.annotationType())) {
                annotations.addAll(
                        beanManager.getStereotypeDefinition(
                                annotation.annotationType()
                        )
                );
            }
        }

        return empty();
    }
项目:Camel    文件:CdiCamelExtension.java   
private boolean shouldDeployDefaultCamelContext(Set<Bean<?>> beans) {
    return beans.stream()
        // Is there a Camel bean with the @Default qualifier?
        // Excluding internal components...
        .filter(bean -> !bean.getBeanClass().getPackage().equals(getClass().getPackage()))
        .filter(hasType(CamelContextAware.class).or(hasType(Component.class))
            .or(hasType(RouteContainer.class).or(hasType(RoutesBuilder.class))))
        .map(Bean::getQualifiers)
        .flatMap(Set::stream)
        .filter(isEqual(DEFAULT))
        .findAny()
        .isPresent()
        // Or a bean with Camel annotations?
        || concat(camelBeans.stream().map(AnnotatedType::getFields),
                  camelBeans.stream().map(AnnotatedType::getMethods))
        .flatMap(Set::stream)
        .map(Annotated::getAnnotations)
        .flatMap(Set::stream)
        .filter(isAnnotationType(Consume.class).and(a -> ((Consume) a).context().isEmpty())
            .or(isAnnotationType(BeanInject.class).and(a -> ((BeanInject) a).context().isEmpty()))
            .or(isAnnotationType(EndpointInject.class).and(a -> ((EndpointInject) a).context().isEmpty()))
            .or(isAnnotationType(Produce.class).and(a -> ((Produce) a).context().isEmpty()))
            .or(isAnnotationType(PropertyInject.class).and(a -> ((PropertyInject) a).context().isEmpty())))
        .findAny()
        .isPresent()
        // Or an injection point for Camel primitives?
        || beans.stream()
        // Excluding internal components...
        .filter(bean -> !bean.getBeanClass().getPackage().equals(getClass().getPackage()))
        .map(Bean::getInjectionPoints)
        .flatMap(Set::stream)
        .filter(ip -> getRawType(ip.getType()).getName().startsWith("org.apache.camel"))
        .map(InjectionPoint::getQualifiers)
        .flatMap(Set::stream)
        .filter(isAnnotationType(Uri.class).or(isAnnotationType(Mock.class)).or(isEqual(DEFAULT)))
        .findAny()
        .isPresent();
}
项目:Camel    文件:CdiSpiHelper.java   
static Set<Annotation> getQualifiers(Annotated annotated, BeanManager manager) {
    return annotated.getAnnotations().stream()
        .filter(annotation -> manager.isQualifier(annotation.annotationType()))
        .collect(collectingAndThen(toSet(),
            qualifiers -> {
                if (qualifiers.isEmpty()) {
                    qualifiers.add(DEFAULT);
                }
                qualifiers.add(ANY);
                return qualifiers;
            })
        );
}
项目:porcupine    文件:ExecutorServiceExposer.java   
String getPipelineName(InjectionPoint ip) {
    Annotated annotated = ip.getAnnotated();
    Dedicated dedicated = annotated.getAnnotation(Dedicated.class);
    String name;
    if (dedicated != null && !Dedicated.DEFAULT.equals(dedicated.value())) {
        name = dedicated.value();
    } else {
        name = ip.getMember().getName();
    }
    return name;
}
项目:octopus-jsr375    文件:CdiUtils.java   
public static <A extends Annotation> Optional<A> getAnnotation(BeanManager beanManager, Annotated annotated, Class<A> annotationType) {

        annotated.getAnnotation(annotationType);

        if (annotated.getAnnotations().isEmpty()) {
            return empty();
        }

        if (annotated.isAnnotationPresent(annotationType)) {
            return Optional.of(annotated.getAnnotation(annotationType));
        }

        Queue<Annotation> annotations = new LinkedList<>(annotated.getAnnotations());

        while (!annotations.isEmpty()) {
            Annotation annotation = annotations.remove();

            if (annotation.annotationType().equals(annotationType)) {
                return Optional.of(annotationType.cast(annotation));
            }

            if (beanManager.isStereotype(annotation.annotationType())) {
                annotations.addAll(
                        beanManager.getStereotypeDefinition(
                                annotation.annotationType()
                        )
                );
            }
        }

        return empty();
    }
项目:ocelot    文件:TopicsMessagesObserversTest.java   
/**
 * Test of sendObjectToTopic method, of class TopicsMessagesBroadcaster.
 *
 * @throws org.ocelotds.marshalling.exceptions.JsonMarshallingException
 * @throws org.ocelotds.marshalling.exceptions.JsonMarshallerException
 */
@Test
public void testSendObjectToTopicWithMarshaller() throws JsonMarshallingException, JsonMarshallerException {
    System.out.println("sendObjectToTopic");
    EventMetadata metadata = mock(EventMetadata.class);
    InjectionPoint injectionPoint = mock(InjectionPoint.class);
    Annotated annotated = mock(Annotated.class);
    JsTopicEvent jte = mock(JsTopicEvent.class);
    JsonMarshaller jm = mock(JsonMarshaller.class);

    when(metadata.getInjectionPoint()).thenReturn(injectionPoint);
    when(injectionPoint.getAnnotated()).thenReturn(annotated);
    when(annotated.getAnnotation(JsTopicEvent.class)).thenReturn(jte);
    when(annotated.getAnnotation(JsonMarshaller.class)).thenReturn(jm);
    when(jte.value()).thenReturn(TOPIC);
    when(argumentServices.getJsonResultFromSpecificMarshaller(eq(jm), eq(PAYLOAD))).thenReturn("MARSHALLED");

    // JsTopicEvent, no marshaller
    instance.sendObjectToTopic(PAYLOAD, metadata);

    ArgumentCaptor<MessageToClient> captureMtC = ArgumentCaptor.forClass(MessageToClient.class);
    ArgumentCaptor<Object> captureObject = ArgumentCaptor.forClass(Object.class);
    verify(topicsMessagesBroadcaster).sendMessageToTopic(captureMtC.capture(), captureObject.capture());

    assertThat(captureMtC.getValue().getJson()).isEqualTo("MARSHALLED");
    assertThat(captureObject.getValue()).isEqualTo(PAYLOAD);
}
项目:ocelot    文件:LoggerProducer.java   
/**
 *
 * @param injectionPoint : argument injected
 * @return
 */
@Produces
@OcelotLogger
public Logger getLogger(InjectionPoint injectionPoint) {
    Annotated annotated = injectionPoint.getAnnotated();
    OcelotLogger annotation = annotated.getAnnotation(OcelotLogger.class);
    String loggerName = annotation.name();
    if(loggerName.isEmpty()) {
        loggerName = injectionPoint.getMember().getDeclaringClass().getName();
    }
    return LoggerFactory.getLogger(loggerName);
}
项目:hawkular-metrics    文件:ConfigurableProducerTest.java   
private InjectionPoint configureInjectionPoint(ConfigurationKey configurationKey) {
    Annotated annotated = mock(Annotated.class);
    ConfigurationProperty configurationProperty = mock(ConfigurationProperty.class);
    when(configurationProperty.value()).thenReturn(configurationKey);
    when(annotated.getAnnotation(eq(ConfigurationProperty.class))).thenReturn(configurationProperty);
    InjectionPoint injectionPoint = mock(InjectionPoint.class);
    when(injectionPoint.getAnnotated()).thenReturn(annotated);
    return injectionPoint;
}
项目:hawkular-metrics    文件:ConfigurableProducerTest.java   
@Test
public void shouldThrowIllegalArgumentExceptionIfAnnotationIsMissing() throws Exception {
    // Override default: simulate a missing config property annotation
    Annotated annotated = mock(Annotated.class);
    when(annotated.getAnnotation(eq(ConfigurationProperty.class))).thenReturn(null);
    InjectionPoint injectionPoint = mock(InjectionPoint.class);
    when(injectionPoint.getAnnotated()).thenReturn(annotated);

    expectedException.expect(IllegalArgumentException.class);
    String message = "Any field or parameter annotated with @Configurable "
                     + "must also be annotated with @ConfigurationProperty";
    expectedException.expectMessage(message);
    configurableProducer.getConfigurationPropertyAsString(injectionPoint);
}