Java Code Examples for javax.enterprise.inject.spi.InjectionPoint

The following examples show how to use javax.enterprise.inject.spi.InjectionPoint. These examples are extracted from open source projects. 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
public static SubscriptionPublisherInjectionWrapper createInvocationHandler(Bean<?> bean, BeanManager beanManager) {
    SubscriptionPublisherProducer subscriptionPublisherProducer = getSubscriptionPublisherProducerReference(beanManager);
    Class proxiedInterface = SubscriptionPublisherInjection.class;
    Class subscriptionPublisherClass = null;
    Class beanClass = bean.getBeanClass();
    for (InjectionPoint injectionPoint : bean.getInjectionPoints()) {
        if (!injectionPoint.getQualifiers().contains(SUBSCRIPTION_PUBLISHER_ANNOTATION_LITERAL)) {
            continue;
        }
        Type baseType = injectionPoint.getAnnotated().getBaseType();
        if (baseType instanceof Class && SubscriptionPublisher.class.isAssignableFrom((Class) baseType)) {
            subscriptionPublisherClass = (Class) baseType;
            break;
        }
    }
    logger.debug("Found injector {} and publisher {} classes.", proxiedInterface, subscriptionPublisherClass);
    if (subscriptionPublisherClass == null || proxiedInterface == null) {
        throw new JoynrIllegalStateException("Cannot create subscription publisher injection wrapper proxy for bean which doesn't inject a concrete SubscriptionPublisher.");
    }
    return new SubscriptionPublisherInjectionWrapper(proxiedInterface,
                                                     subscriptionPublisherClass,
                                                     subscriptionPublisherProducer,
                                                     beanClass);
}
 
Example 2
Source Project: thorntail   Source File: ConfigurationValueProducer.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@ConfigurationValue("")
@Dependent
@Produces
<T> Optional<T> produceOptionalConfigValue(InjectionPoint injectionPoint) {
    Type type = injectionPoint.getAnnotated().getBaseType();
    final Class<T> valueType;
    if (type instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) type;

        Type[] typeArguments = parameterizedType.getActualTypeArguments();
        valueType = unwrapType(typeArguments[0]);
    } else {
        valueType = (Class<T>) String.class;
    }
    return Optional.ofNullable(resolve(injectionPoint, valueType));
}
 
Example 3
Source Project: smallrye-jwt   Source File: RawClaimTypeProducer.java    License: Apache License 2.0 6 votes vote down vote up
@Produces
@Claim("")
Long getClaimAsLong(InjectionPoint ip) {
    CDILogging.log.getClaimAsLong(ip);
    if (currentToken == null) {
        return null;
    }

    String name = getName(ip);
    Optional<Object> optValue = currentToken.claim(name);
    Long returnValue = null;
    if (optValue.isPresent()) {
        Object value = optValue.get();
        if (value instanceof JsonNumber) {
            JsonNumber jsonValue = (JsonNumber) value;
            returnValue = jsonValue.longValue();
        } else {
            returnValue = Long.parseLong(value.toString());
        }
    }
    return returnValue;
}
 
Example 4
Source Project: tomee   Source File: CheckInjectionPointUsage.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void validate(final EjbModule ejbModule) {
    if (ejbModule.getBeans() == null) {
        return;
    }

    try {
        for (final Field field : ejbModule.getFinder().findAnnotatedFields(Inject.class)) {
            if (!field.getType().equals(InjectionPoint.class) || !HttpServlet.class.isAssignableFrom(field.getDeclaringClass())) {
                continue;
            }

            final Annotation[] annotations = field.getAnnotations();
            if (annotations.length == 1 || (annotations.length == 2 && field.getAnnotation(Default.class) != null)) {
                throw new DefinitionException("Can't inject InjectionPoint in " + field.getDeclaringClass());
            } // else we should check is there is no other qualifier than @Default but too early
        }
    } catch (final NoClassDefFoundError noClassDefFoundError) {
        // ignored: can't check but maybe it is because of an optional dep so ignore it
        // not important to skip it since the failure will be reported elsewhere
        // this validator doesn't check it
    }
}
 
Example 5
Source Project: deltaspike   Source File: CustomConfigPropertyProducer.java    License: Apache License 2.0 6 votes vote down vote up
@Produces
@Dependent
@Location
public LocationId produceLocationId(InjectionPoint injectionPoint)
{
    String configuredValue = getStringPropertyValue(injectionPoint);

    /*
    //alternative to @ConfigProperty#defaultValue
    if (configuredValue == null)
    {
        return LocationId.LOCATION_X;
    }
    */
    return LocationId.valueOf(configuredValue.trim().toUpperCase());
}
 
Example 6
Source Project: datawave   Source File: DatawaveConfigPropertyProducer.java    License: Apache License 2.0 6 votes vote down vote up
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public List<Double> produceDoubleListConfiguration(InjectionPoint injectionPoint) {
    String propertyValue = getStringPropertyValue(injectionPoint);
    String[] values = StringUtils.split(propertyValue, ",");
    
    ArrayList<Double> list = new ArrayList<>();
    if (values != null) {
        for (String value : values) {
            try {
                list.add(Double.parseDouble(value));
            } catch (NumberFormatException nfe) {
                ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class);
                throw new RuntimeException("Error while converting Double property '" + configProperty.name() + "' value: " + value + " of "
                                + propertyValue + " happening in bean " + injectionPoint.getBean(), nfe);
            }
            
        }
    }
    return list;
}
 
Example 7
Source Project: smallrye-config   Source File: ConfigExtension.java    License: Apache License 2.0 6 votes vote down vote up
protected void registerCustomBeans(@Observes AfterBeanDiscovery abd, BeanManager bm) {
    Set<Class<?>> customTypes = new HashSet<>();
    for (InjectionPoint ip : injectionPoints) {
        Type requiredType = ip.getType();
        if (requiredType instanceof ParameterizedType) {
            ParameterizedType type = (ParameterizedType) requiredType;
            // TODO We should probably handle all parameterized types correctly
            if (type.getRawType().equals(Provider.class) || type.getRawType().equals(Instance.class)) {
                // These injection points are satisfied by the built-in Instance bean 
                Type typeArgument = type.getActualTypeArguments()[0];
                if (typeArgument instanceof Class && !isClassHandledByConfigProducer(typeArgument)) {
                    customTypes.add((Class<?>) typeArgument);
                }
            }
        } else if (requiredType instanceof Class
                && !isClassHandledByConfigProducer(requiredType)) {
            // type is not produced by ConfigProducer
            customTypes.add((Class<?>) requiredType);
        }
    }

    for (Class<?> customType : customTypes) {
        abd.addBean(new ConfigInjectionBean(bm, customType));
    }
}
 
Example 8
Source Project: javamoney-lib   Source File: MonetaryProducer.java    License: Apache License 2.0 5 votes vote down vote up
@Produces @Dependent
public static MonetaryAmountFactory amountFactory(InjectionPoint ip){
    Amount specAnnot = ip.getAnnotated()!=null?ip.getAnnotated().getAnnotation(Amount.class):null;
    if(specAnnot!=null){
        return Monetary.getAmountFactory(createAmountQuery(specAnnot));
    }
    return Monetary.getDefaultAmountFactory();
}
 
Example 9
@Produces
@Dependent
public GroupedConversation getGroupedConversation(InjectionPoint injectionPoint, BeanManager beanManager)
{
    ConversationKey conversationKey =
        ConversationUtils.convertToConversationKey(injectionPoint.getBean(), beanManager);
    return new InjectableGroupedConversation(conversationKey, getGroupedConversationManager());
}
 
Example 10
Source Project: quarkus   Source File: ErasedGenericTest.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
@Claim("")
public Optional<String> getStringValue(InjectionPoint ip) {
    String name = getName(ip);
    Optional<String> value = Optional.of(name);
    return value;
}
 
Example 11
Source Project: smallrye-jwt   Source File: OptionalClaimTypeProducer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Produces an Optional claim value wrapping a Boolean.
 *
 * @param ip reference to the injection point
 * @return an optional claim value
 */
@Produces
@Claim("")
public Optional<Boolean> getOptionalBoolean(InjectionPoint ip) {
    CDILogging.log.getOptionalBoolean(ip);
    if (currentToken == null) {
        return Optional.empty();
    }
    return Optional.ofNullable((Boolean) JsonUtils.convert(Boolean.class, currentToken.getClaim(getName(ip))));
}
 
Example 12
Source Project: deltaspike   Source File: HttpParams.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
@HttpParam("")
String getParamValue(InjectionPoint ip)
{
    ServletRequest request = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    return request.getParameter(ip.getAnnotated().getAnnotation(HttpParam.class).value());
}
 
Example 13
Source Project: weld-junit   Source File: MockEjbInjectionServices.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ResourceReferenceFactory<Object> registerEjbInjectionPoint(InjectionPoint injectionPoint) {
    return new ResourceReferenceFactory<Object>() {
        @Override
        public ResourceReference<Object> createResource() {
            return new SimpleResourceReference<Object>(ejbFactory.apply(injectionPoint));
        }
    };
}
 
Example 14
Source Project: deltaspike   Source File: DefaultConfigPropertyProducer.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
@Dependent
@ConfigProperty(name = "ignored") // we actually don't need the name
public Boolean produceBooleanConfiguration(InjectionPoint injectionPoint)
{
    return getPropertyWithException(injectionPoint, Boolean.class);
}
 
Example 15
Source Project: smallrye-jwt   Source File: RawClaimTypeProducer.java    License: Apache License 2.0 5 votes vote down vote up
static String getName(InjectionPoint ip) {
    String name = null;
    for (Annotation ann : ip.getQualifiers()) {
        if (ann instanceof Claim) {
            Claim claim = (Claim) ann;
            name = claim.standard() == Claims.UNKNOWN ? claim.value() : claim.standard().name();
        }
    }
    return name;
}
 
Example 16
Source Project: smallrye-config   Source File: ConfigProducerUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static <T> T getValue(InjectionPoint injectionPoint, Config config) {
    String name = getName(injectionPoint);
    if (name == null) {
        return null;
    }
    final SmallRyeConfig src = (SmallRyeConfig) config;
    Converter<T> converter = resolveConverter(injectionPoint, src);
    String rawValue = getRawValue(name, src);
    if (rawValue == null) {
        rawValue = getDefaultValue(injectionPoint);
    }
    T converted;
    if (rawValue == null) {
        // convert an empty value
        try {
            converted = converter.convert("");
        } catch (IllegalArgumentException ignored) {
            throw InjectionMessages.msg.propertyNotFound(name);
        }
    } else {
        converted = converter.convert(rawValue);
    }
    if (converted == null) {
        throw InjectionMessages.msg.propertyNotFound(name);
    }
    return converted;
}
 
Example 17
Source Project: javamoney-lib   Source File: MonetaryProducer.java    License: Apache License 2.0 5 votes vote down vote up
@Produces @Dependent
public static CurrencyUnit currencyUnit(InjectionPoint ip){
    AmountCurrency specAnnot = ip.getAnnotated()!=null?
            ip.getAnnotated().getAnnotation(AmountCurrency.class):
            null;
    if(specAnnot==null){
        java.util.Currency jdkDefault = java.util.Currency.getInstance(Locale.getDefault());
        if(jdkDefault!=null) {
            return Monetary.getCurrency(jdkDefault.getCurrencyCode());
        }else{
            throw new MonetaryException("No default currency found.");
        }
    }
    return Monetary.getCurrency(createCurrencyQuery(specAnnot));
}
 
Example 18
Source Project: deltaspike   Source File: DefaultConfigPropertyProducer.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
@Dependent
@ConfigProperty(name = "ignored") // we actually don't need the name
public Class produceClassConfiguration(InjectionPoint injectionPoint)
{
    return getPropertyWithException(injectionPoint, Class.class);
}
 
Example 19
Source Project: incubator-batchee   Source File: BatchProducerBean.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
@BatchProperty
public Pattern producePatternProperty(final InjectionPoint injectionPoint) {
    final String v = produceProperty(injectionPoint);
    if (v != null) {
        return DependencyInjections.convertTo(v, Pattern.class, Pattern.class);
    }
    return null;
}
 
Example 20
Source Project: smallrye-config   Source File: ConfigProducerUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static ConfigValue getConfigValue(InjectionPoint injectionPoint, Config config) {
    String name = getName(injectionPoint);
    if (name == null) {
        return null;
    }

    ConfigValue configValue = ((SmallRyeConfig) config).getConfigValue(name);
    if (configValue.getValue() == null) {
        configValue = configValue.withValue(getDefaultValue(injectionPoint));
    }

    return configValue;
}
 
Example 21
Source Project: smallrye-config   Source File: ConfigExtension.java    License: Apache License 2.0 5 votes vote down vote up
protected void validate(@Observes AfterDeploymentValidation adv) {
    Config config = ConfigProvider.getConfig(getContextClassLoader());
    Set<String> configNames = StreamSupport.stream(config.getPropertyNames().spliterator(), false).collect(toSet());
    for (InjectionPoint injectionPoint : injectionPoints) {
        Type type = injectionPoint.getType();

        // We don't validate the Optional / Provider / Supplier / ConfigValue for defaultValue.
        if (type instanceof Class && ConfigValue.class.isAssignableFrom((Class<?>) type)
                || type instanceof Class && OptionalInt.class.isAssignableFrom((Class<?>) type)
                || type instanceof Class && OptionalLong.class.isAssignableFrom((Class<?>) type)
                || type instanceof Class && OptionalDouble.class.isAssignableFrom((Class<?>) type)
                || type instanceof ParameterizedType
                        && (Optional.class.isAssignableFrom((Class<?>) ((ParameterizedType) type).getRawType())
                                || Provider.class.isAssignableFrom((Class<?>) ((ParameterizedType) type).getRawType())
                                || Supplier.class.isAssignableFrom((Class<?>) ((ParameterizedType) type).getRawType()))) {
            return;
        }

        ConfigProperty configProperty = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
        String name = ConfigProducerUtil.getConfigKey(injectionPoint, configProperty);

        // Check if the name is part of the properties first. Since properties can be a subset, then search for the actual property for a value.
        if (!configNames.contains(name) && ConfigProducerUtil.getRawValue(name, (SmallRyeConfig) config) == null) {
            if (configProperty.defaultValue().equals(ConfigProperty.UNCONFIGURED_VALUE)) {
                adv.addDeploymentProblem(InjectionMessages.msg.noConfigValue(name));
            }
        }

        try {
            // Check if there is a Converter registed for the injected type
            Converter<?> resolvedConverter = ConfigProducerUtil.resolveConverter(injectionPoint, (SmallRyeConfig) config);

            // Check if the value can be converted. The TCK checks this, but this requires to get the value eagerly.
            // This should not be required!
            SecretKeys.doUnlocked(() -> ((SmallRyeConfig) config).getOptionalValue(name, resolvedConverter));
        } catch (IllegalArgumentException e) {
            adv.addDeploymentProblem(e);
        }
    }
}
 
Example 22
Source Project: datawave   Source File: DatawaveConfigPropertyProducer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Alternative
@Specializes
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public String produceStringConfiguration(InjectionPoint injectionPoint) {
    return super.produceStringConfiguration(injectionPoint);
}
 
Example 23
Source Project: datawave   Source File: DatawaveConfigPropertyProducer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Alternative
@Specializes
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public Long produceLongConfiguration(InjectionPoint injectionPoint) {
    return super.produceLongConfiguration(injectionPoint);
}
 
Example 24
Source Project: camunda-bpm-platform   Source File: ProcessVariables.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @since 7.3
 */
@Produces
@ProcessVariableLocalTyped
protected TypedValue getProcessVariableLocalTyped(InjectionPoint ip) {
  String processVariableName = getVariableLocalTypedName(ip);

  if (logger.isLoggable(Level.FINE)) {
    logger.fine("Getting local typed process variable '" + processVariableName + "' from ProcessInstance[" + businessProcess.getProcessInstanceId() + "].");
  }

  return businessProcess.getVariableLocalTyped(processVariableName);
}
 
Example 25
Source Project: weld-junit   Source File: MockResourceInjectionServices.java    License: Apache License 2.0 5 votes vote down vote up
private Resource getResourceAnnotation(InjectionPoint injectionPoint) {
    Annotated annotated = injectionPoint.getAnnotated();
    if (annotated instanceof AnnotatedParameter<?>) {
        annotated = ((AnnotatedParameter<?>) annotated).getDeclaringCallable();
    }
    return annotated.getAnnotation(Resource.class);
}
 
Example 26
Source Project: smallrye-config   Source File: ConfigProducerUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String getName(InjectionPoint injectionPoint) {
    for (Annotation qualifier : injectionPoint.getQualifiers()) {
        if (qualifier.annotationType().equals(ConfigProperty.class)) {
            ConfigProperty configProperty = ((ConfigProperty) qualifier);
            return getConfigKey(injectionPoint, configProperty);
        }
    }
    return null;
}
 
Example 27
@Produces
@Config("")
public String exposeConfig(InjectionPoint injectionPoint) {
    final Config config = injectionPoint.getAnnotated().getAnnotation(Config.class);
    if (config != null)
        return properties.getProperty(config.value());
    return null;
}
 
Example 28
Source Project: quarkus   Source File: BeanOnlyInTestCase.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBeanIsInjected() {
    assertNotNull(unusedBean);
    InjectionPoint injectionPoint = unusedBean.getInjectionPoint();
    assertNotNull(injectionPoint);
    assertEquals(UnusedBean.class, injectionPoint.getType());
    assertEquals(1, injectionPoint.getQualifiers().size());
    assertEquals(Default.class, injectionPoint.getQualifiers().iterator().next().annotationType());
    assertTrue(injectionPoint.getMember() instanceof Field);
    assertTrue(injectionPoint.getAnnotated().isAnnotationPresent(Inject.class));
}
 
Example 29
Source Project: incubator-batchee   Source File: BatchProducerBean.java    License: Apache License 2.0 5 votes vote down vote up
@Produces
@BatchProperty
public Date produceDateProperty(final InjectionPoint injectionPoint) {
    final String v = produceProperty(injectionPoint);
    if (v != null) {
        return DependencyInjections.convertTo(v, Date.class, Date.class);
    }
    return null;
}
 
Example 30
Source Project: portals-pluto   Source File: PortletParamProducer.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}