javax.enterprise.inject.spi.Annotated Java Examples
The following examples show how to use
javax.enterprise.inject.spi.Annotated.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BeanUtils.java From deltaspike with Apache License 2.0 | 6 votes |
/** * @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; }
Example #2
Source File: AnnotatedTypeBuilder.java From deltaspike with Apache License 2.0 | 6 votes |
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); } } }
Example #3
Source File: EnvironmentPropertyProducer.java From vraptor4 with Apache License 2.0 | 6 votes |
@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); }
Example #4
Source File: MessageHandlingBeanDefinition.java From cdi with Apache License 2.0 | 6 votes |
static Optional<MessageHandlingBeanDefinition> inspect(Bean<?> bean, Annotated annotated) { if (!(annotated instanceof AnnotatedType)) { return Optional.empty(); } AnnotatedType at = (AnnotatedType) annotated; boolean isEventHandler = CdiUtilities.hasAnnotatedMethod(at, EventHandler.class); boolean isQueryHandler = CdiUtilities.hasAnnotatedMethod(at, QueryHandler.class); boolean isCommandHandler = CdiUtilities.hasAnnotatedMethod(at, CommandHandler.class); if (isEventHandler || isQueryHandler || isCommandHandler) { return Optional.of(new MessageHandlingBeanDefinition(bean, isEventHandler, isQueryHandler, isCommandHandler)); } return Optional.empty(); }
Example #5
Source File: PortletParamProducer.java From portals-pluto with Apache License 2.0 | 5 votes |
@Dependent @PortletParam @Produces public Integer getIntegerParam(ClientDataRequest clientDataRequest, PortletResponse portletResponse, InjectionPoint injectionPoint) { String value = getStringParam(clientDataRequest, portletResponse, injectionPoint); if (value == null) { return null; } Annotated field = injectionPoint.getAnnotated(); Annotation[] fieldAnnotations = _getFieldAnnotations(field); ParamConverter<Integer> paramConverter = _getParamConverter(Integer.class, field.getBaseType(), fieldAnnotations); if (paramConverter != null) { try { return paramConverter.fromString(value); } catch (IllegalArgumentException iae) { _addBindingError(fieldAnnotations, iae.getMessage(), value); return null; } } if (LOG.isWarnEnabled()) { LOG.warn("Unable to find a ParamConverterProvider for type Integer"); } return null; }
Example #6
Source File: DefaultMockFilter.java From deltaspike with Apache License 2.0 | 5 votes |
protected boolean isMockSupportEnabled(Annotated annotated) { if ((annotated instanceof AnnotatedMethod || annotated instanceof AnnotatedField) && annotated.getAnnotation(Produces.class) != null) { return TestBaseConfig.MockIntegration.ALLOW_MOCKED_PRODUCERS; } else { return TestBaseConfig.MockIntegration.ALLOW_MOCKED_BEANS; } }
Example #7
Source File: SeMetricName.java From metrics-cdi with Apache License 2.0 | 5 votes |
@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"); }
Example #8
Source File: JMS2CDIExtension.java From tomee with Apache License 2.0 | 5 votes |
private Key newKey(final InjectionPoint ip) { final Annotated annotated = ip.getAnnotated(); final JMSConnectionFactory jmsConnectionFactory = annotated.getAnnotation(JMSConnectionFactory.class); final JMSSessionMode sessionMode = annotated.getAnnotation(JMSSessionMode.class); final JMSPasswordCredential credential = annotated.getAnnotation(JMSPasswordCredential.class); final String jndi = "openejb:Resource/" + (jmsConnectionFactory == null ? findAnyConnectionFactory() : findMatchingConnectionFactory(jmsConnectionFactory.value())); return new Key( jndi, credential != null ? credential.userName() : null, credential != null ? credential.password() : null, sessionMode != null ? sessionMode.value() : null); }
Example #9
Source File: PortletParamProducer.java From portals-pluto with Apache License 2.0 | 5 votes |
@Dependent @PortletParam @Produces public Long getLongParam(ClientDataRequest clientDataRequest, PortletResponse portletResponse, InjectionPoint injectionPoint) { String value = getStringParam(clientDataRequest, portletResponse, injectionPoint); if (value == null) { return null; } Annotated field = injectionPoint.getAnnotated(); Annotation[] fieldAnnotations = _getFieldAnnotations(field); ParamConverter<Long> paramConverter = _getParamConverter(Long.class, field.getBaseType(), fieldAnnotations); if (paramConverter != null) { try { return paramConverter.fromString(value); } catch (IllegalArgumentException iae) { _addBindingError(fieldAnnotations, iae.getMessage(), value); return null; } } if (LOG.isWarnEnabled()) { LOG.warn("Unable to find a ParamConverterProvider for type Long"); } return Long.valueOf(value); }
Example #10
Source File: PortletParamProducer.java From portals-pluto with Apache License 2.0 | 5 votes |
@Dependent @PortletParam @Produces public Float getFloatParam(ClientDataRequest clientDataRequest, PortletResponse portletResponse, InjectionPoint injectionPoint) { String value = getStringParam(clientDataRequest, portletResponse, injectionPoint); if (value == null) { return null; } Annotated field = injectionPoint.getAnnotated(); Annotation[] fieldAnnotations = _getFieldAnnotations(field); ParamConverter<Float> paramConverter = _getParamConverter(Float.class, field.getBaseType(), fieldAnnotations); if (paramConverter != null) { try { return paramConverter.fromString(value); } catch (IllegalArgumentException iae) { _addBindingError(fieldAnnotations, iae.getMessage(), value); return null; } } if (LOG.isWarnEnabled()) { LOG.warn("Unable to find a ParamConverterProvider for type Float"); } return null; }
Example #11
Source File: PortletParamProducer.java From portals-pluto with Apache License 2.0 | 5 votes |
@Dependent @PortletParam @Produces public Double getDoubleParam(ClientDataRequest clientDataRequest, PortletResponse portletResponse, InjectionPoint injectionPoint) { String value = getStringParam(clientDataRequest, portletResponse, injectionPoint); if (value == null) { return null; } Annotated field = injectionPoint.getAnnotated(); Annotation[] fieldAnnotations = _getFieldAnnotations(field); ParamConverter<Double> paramConverter = _getParamConverter(Double.class, field.getBaseType(), fieldAnnotations); if (paramConverter != null) { try { return paramConverter.fromString(value); } catch (IllegalArgumentException iae) { _addBindingError(fieldAnnotations, iae.getMessage(), value); return null; } } if (LOG.isWarnEnabled()) { LOG.warn("Unable to find a ParamConverterProvider for type Double"); } return null; }
Example #12
Source File: PortletParamProducer.java From portals-pluto with Apache License 2.0 | 5 votes |
@Dependent @PortletParam @Produces public Date getDateParam(ClientDataRequest clientDataRequest, PortletResponse portletResponse, InjectionPoint injectionPoint) { String value = getStringParam(clientDataRequest, portletResponse, injectionPoint); if (value == null) { return null; } Annotated field = injectionPoint.getAnnotated(); Annotation[] fieldAnnotations = _getFieldAnnotations(field); ParamConverter<Date> paramConverter = _getParamConverter(Date.class, field.getBaseType(), fieldAnnotations); if (paramConverter != null) { try { return paramConverter.fromString(value); } catch (IllegalArgumentException iae) { _addBindingError(fieldAnnotations, iae.getMessage(), value); return null; } } if (LOG.isWarnEnabled()) { LOG.warn("Unable to find a ParamConverterProvider for type Date"); } return null; }
Example #13
Source File: PortletParamProducer.java From portals-pluto with Apache License 2.0 | 5 votes |
@Dependent @PortletParam @Produces public Boolean getBooleanParam(ClientDataRequest clientDataRequest, PortletResponse portletResponse, InjectionPoint injectionPoint) { String value = getStringParam(clientDataRequest, portletResponse, injectionPoint); if (value == null) { return null; } Annotated field = injectionPoint.getAnnotated(); Annotation[] fieldAnnotations = _getFieldAnnotations(field); ParamConverter<Boolean> paramConverter = _getParamConverter(Boolean.class, field.getBaseType(), fieldAnnotations); if (paramConverter != null) { try { return paramConverter.fromString(value); } catch (IllegalArgumentException iae) { _addBindingError(fieldAnnotations, iae.getMessage(), value); return null; } } if (LOG.isWarnEnabled()) { LOG.warn("Unable to find a ParamConverterProvider for type Boolean"); } return null; }
Example #14
Source File: ConfigurableProducerTest.java From hawkular-metrics with Apache License 2.0 | 5 votes |
@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); }
Example #15
Source File: ExecutorServiceExposer.java From porcupine with Apache License 2.0 | 5 votes |
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; }
Example #16
Source File: ConfigInjectionBean.java From smallrye-config with Apache License 2.0 | 5 votes |
@Override public T create(CreationalContext<T> context) { InjectionPoint ip = (InjectionPoint) bm.getInjectableReference(new InjectionPointMetadataInjectionPoint(), context); Annotated annotated = ip.getAnnotated(); ConfigProperty configProperty = annotated.getAnnotation(ConfigProperty.class); String key = ConfigProducerUtil.getConfigKey(ip, configProperty); String defaultValue = configProperty.defaultValue(); if (annotated.getBaseType() instanceof ParameterizedType) { ParameterizedType paramType = (ParameterizedType) annotated.getBaseType(); Type rawType = paramType.getRawType(); // handle Provider<T> and Instance<T> if (rawType instanceof Class && (((Class<?>) rawType).isAssignableFrom(Provider.class) || ((Class<?>) rawType).isAssignableFrom(Instance.class)) && paramType.getActualTypeArguments().length == 1) { Class<?> paramTypeClass = (Class<?>) paramType.getActualTypeArguments()[0]; return (T) getConfig().getValue(key, paramTypeClass); } } else { Class annotatedTypeClass = (Class) annotated.getBaseType(); if (defaultValue == null || defaultValue.length() == 0) { return (T) getConfig().getValue(key, annotatedTypeClass); } else { Config config = getConfig(); Optional<T> optionalValue = config.getOptionalValue(key, annotatedTypeClass); if (optionalValue.isPresent()) { return optionalValue.get(); } else { return (T) ((SmallRyeConfig) config).convert(defaultValue, annotatedTypeClass); } } } throw InjectionMessages.msg.unhandledConfigProperty(); }
Example #17
Source File: SeMetricName.java From smallrye-metrics with Apache License 2.0 | 5 votes |
@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 SmallRyeMetricsMessages.msg.unableToRetrieveMetricNameForInjectionPoint(ip); } }
Example #18
Source File: MockResourceInjectionServices.java From weld-junit with Apache License 2.0 | 5 votes |
private Resource getResourceAnnotation(InjectionPoint injectionPoint) { Annotated annotated = injectionPoint.getAnnotated(); if (annotated instanceof AnnotatedParameter<?>) { annotated = ((AnnotatedParameter<?>) annotated).getDeclaringCallable(); } return annotated.getAnnotation(Resource.class); }
Example #19
Source File: RouteExtension.java From weld-vertx with Apache License 2.0 | 5 votes |
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[] {}; }
Example #20
Source File: ConfigurableProducerTest.java From hawkular-metrics with Apache License 2.0 | 5 votes |
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; }
Example #21
Source File: ProviderWrapperTest.java From joynr with Apache License 2.0 | 4 votes |
@SuppressWarnings("rawtypes") private ProviderWrapper createSubject(BeanManager beanManager) { Injector injector = mock(Injector.class); JoynrMessageCreator joynrMessageCreator = mock(JoynrMessageCreator.class); when(injector.getInstance(eq(JoynrMessageCreator.class))).thenReturn(joynrMessageCreator); when(joynrMessageCreator.getMessageCreatorId()).thenReturn(USERNAME); Bean<?> joynrCallingPrincipalBean = mock(Bean.class); when(beanManager.getBeans(JoynrCallingPrincipal.class)).thenReturn(new HashSet<Bean<?>>(Arrays.asList(joynrCallingPrincipalBean))); when(beanManager.getReference(eq(joynrCallingPrincipalBean), eq(JoynrCallingPrincipal.class), Mockito.<CreationalContext> any())).thenReturn(joynrCallingPincipal); Bean<?> bean = mock(Bean.class); doReturn(TestServiceImpl.class).when(bean).getBeanClass(); doReturn(new TestServiceImpl()).when(beanManager).getReference(bean, TestServiceInterface.class, null); JoynrMessageMetaInfo joynrMessageContext = mock(JoynrMessageMetaInfo.class); when(injector.getInstance(eq(JoynrMessageMetaInfo.class))).thenReturn(joynrMessageContext); when(joynrMessageContext.getMessageContext()).thenReturn(expectedMessageContext); Bean<?> joynrMessageContextBean = mock(Bean.class); when(beanManager.getBeans(JoynrJeeMessageMetaInfo.class)).thenReturn(new HashSet<Bean<?>>(Arrays.asList(joynrMessageContextBean))); when(beanManager.getReference(eq(joynrMessageContextBean), eq(JoynrJeeMessageMetaInfo.class), Mockito.any())).thenReturn(joynrJeeMessageContext); // Setup mock SubscriptionPublisherProducer instance in mock bean manager Bean<?> subscriptionPublisherProducerBean = mock(Bean.class); doReturn(new HashSet<Bean<?>>(Arrays.asList(subscriptionPublisherProducerBean))).when(beanManager) .getBeans(eq(SubscriptionPublisherProducer.class)); when(beanManager.getReference(eq(subscriptionPublisherProducerBean), eq(SubscriptionPublisherProducer.class), any())).thenReturn(subscriptionPublisherProducer); // Setup mock meta data so that subscription publisher can be injected InjectionPoint subscriptionPublisherInjectionPoint = mock(InjectionPoint.class); when(bean.getInjectionPoints()).thenReturn(new HashSet<InjectionPoint>(Arrays.asList(subscriptionPublisherInjectionPoint))); when(subscriptionPublisherInjectionPoint.getQualifiers()).thenReturn(new HashSet<Annotation>(Arrays.asList((Annotation) SUBSCRIPTION_PUBLISHER_ANNOTATION_LITERAL))); Annotated annotated = mock(Annotated.class); when(subscriptionPublisherInjectionPoint.getAnnotated()).thenReturn(annotated); when(annotated.getBaseType()).thenReturn(MySubscriptionPublisher.class); ProviderWrapper subject = new ProviderWrapper(bean, beanManager, injector); return subject; }
Example #22
Source File: ImmutableInjectionPoint.java From deltaspike with Apache License 2.0 | 4 votes |
public Annotated getAnnotated() { return annotated; }
Example #23
Source File: ConfigInjectionBean.java From smallrye-config with Apache License 2.0 | 4 votes |
@Override public Annotated getAnnotated() { return null; }
Example #24
Source File: InjectionPointWrapper.java From deltaspike with Apache License 2.0 | 4 votes |
@Override public Annotated getAnnotated() { return wrapped.getAnnotated(); }
Example #25
Source File: Annotateds.java From deltaspike with Apache License 2.0 | 4 votes |
/** * Compares two annotated elements to see if they have the same annotations */ private static boolean compareAnnotated(Annotated a1, Annotated a2) { return a1.getAnnotations().equals(a2.getAnnotations()); }
Example #26
Source File: AnnotatedDecorator.java From smallrye-metrics with Apache License 2.0 | 4 votes |
AnnotatedDecorator(Annotated decorated, Set<Annotation> annotations) { this.decorated = decorated; this.annotations = annotations; }
Example #27
Source File: DefaultMockFilter.java From deltaspike with Apache License 2.0 | 4 votes |
@Override public boolean isMockedImplementationSupported(BeanManager beanManager, Annotated annotated) { if (!isMockSupportEnabled(annotated)) { return false; } Class origin = null; if (annotated instanceof AnnotatedType) { origin = ((AnnotatedType)annotated).getJavaClass(); Set<Annotation> annotations = new HashSet<Annotation>(); annotations.addAll(annotated.getAnnotations()); for (AnnotatedMethod annotatedMethod : (Set<javax.enterprise.inject.spi.AnnotatedMethod>)((AnnotatedType) annotated).getMethods()) { annotations.addAll(annotatedMethod.getAnnotations()); } if (isEjbOrAnnotatedTypeWithInterceptorAnnotation( beanManager, annotations, origin.getName())) { return false; } } else if (annotated instanceof AnnotatedMember) { Member member = ((AnnotatedMember)annotated).getJavaMember(); origin = member.getDeclaringClass(); if (isEjbOrAnnotatedTypeWithInterceptorAnnotation( beanManager, annotated.getAnnotations(), member.toString())) { return false; } } if (origin != null && origin.getPackage() == null) { LOG.warning("Please don't use the default-package for " + origin.getName()); return true; } return origin != null && !isInternalPackage(origin.getPackage().getName()); }
Example #28
Source File: ConfigReader.java From dashbuilder with Apache License 2.0 | 4 votes |
public @Produces @Config String readConfig(InjectionPoint p) { // Read from specific bean String beanKey = p.getMember().getDeclaringClass().getName(); Properties beanProperties = beanPropertyMap.get(beanKey); if (beanProperties == null) { beanPropertyMap.put(beanKey, beanProperties = new Properties()); try { InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/" + beanKey + ".config"); if (is != null) beanProperties.load(is); } catch (IOException ex) { throw new RuntimeException(ex); } } // Read from the bean config String configKey = p.getMember().getName(); String configValue = beanProperties.getProperty(configKey); if (configValue != null) return configValue; // Read from global - by the fully qualified class name and field name for (Type type : p.getBean().getTypes()) { configKey = ((Class)type).getName() + "." + p.getMember().getName(); configValue = globalProperties.getProperty(configKey); if (configValue != null) return configValue; // Try class name from System.properties configValue = System.getProperty(configKey); if (configValue != null) { log.info(String.format("System property: %s=%s", configKey, configValue)); return configValue; } // Try class simple name from System.properties configKey = ((Class)type).getSimpleName() + "." + p.getMember().getName(); configValue = System.getProperty(configKey); if (configValue != null) { log.info(String.format("System property: %s=%s", configKey, configValue)); return configValue; } } // Read from global - only by the field name configKey = p.getMember().getName(); configValue = globalProperties.getProperty(configKey); if (configValue != null) return configValue; // Return the default value if any. Annotated annotated = p.getAnnotated(); Config config = annotated.getAnnotation(Config.class); if (config != null) return config.value(); return null; }
Example #29
Source File: AnnotatedDecorator.java From metrics-cdi with Apache License 2.0 | 4 votes |
AnnotatedDecorator(Annotated decorated, Set<Annotation> annotations) { this.decorated = decorated; this.annotations = annotations; }
Example #30
Source File: CurrentInjectionPointProvider.java From quarkus with Apache License 2.0 | 4 votes |
@Override public Annotated getAnnotated() { return annotated; }