Search in sources :

Example 11 with Dependent

use of javax.enterprise.context.Dependent in project deltaspike by apache.

the class JsfMessageProducer method createJsfMessage.

@Produces
@Dependent
public <M> JsfMessage<M> createJsfMessage(InjectionPoint injectionPoint, MessageBundleInvocationHandler invocationHandler) {
    if (!(injectionPoint.getType() instanceof ParameterizedType)) {
        throw new IllegalArgumentException("JsfMessage must be used as generic type");
    }
    ParameterizedType paramType = (ParameterizedType) injectionPoint.getType();
    Type[] actualTypes = paramType.getActualTypeArguments();
    if (actualTypes.length != 1) {
        throw new IllegalArgumentException("JsfMessage must have the MessageBundle as generic type parameter");
    }
    try {
        @SuppressWarnings("unchecked") Class<M> type = (Class<M>) actualTypes[0];
        return createJsfMessageFor(injectionPoint, type, invocationHandler);
    } catch (ClassCastException e) {
        throw new IllegalArgumentException("Incorrect class found when trying to convert to parameterized type", e);
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Produces(javax.enterprise.inject.Produces) Dependent(javax.enterprise.context.Dependent)

Example 12 with Dependent

use of javax.enterprise.context.Dependent in project wildfly-swarm by wildfly-swarm.

the class ConfigurationValueProducer method produceOptionalConfigValue.

@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));
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ConfigurationValue(org.wildfly.swarm.spi.runtime.annotations.ConfigurationValue) Produces(javax.enterprise.inject.Produces) Dependent(javax.enterprise.context.Dependent)

Aggregations

Dependent (javax.enterprise.context.Dependent)12 Produces (javax.enterprise.inject.Produces)7 ParameterizedType (java.lang.reflect.ParameterizedType)4 Type (java.lang.reflect.Type)4 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 PayaraConfig (fish.payara.nucleus.microprofile.config.spi.PayaraConfig)1 Member (java.lang.reflect.Member)1 Method (java.lang.reflect.Method)1 DecimalFormat (java.text.DecimalFormat)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 EJBHome (javax.ejb.EJBHome)1 EJBLocalHome (javax.ejb.EJBLocalHome)1 RemoveException (javax.ejb.RemoveException)1 SessionBean (javax.ejb.SessionBean)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 AlterableContext (javax.enterprise.context.spi.AlterableContext)1 Context (javax.enterprise.context.spi.Context)1 CreationalContext (javax.enterprise.context.spi.CreationalContext)1