Search in sources :

Example 1 with Dependent

use of javax.enterprise.context.Dependent in project Payara by payara.

the class ConfigPropertyProducer method getGenericProperty.

/**
 * General producer method for injecting a property into a field annotated
 * with the @ConfigProperty annotation.
 * Note this does not have @Produces annotation as a synthetic bean using this method
 * is created in teh CDI Extension.
 * @param ip
 * @return
 */
@ConfigProperty
@Dependent
public static final Object getGenericProperty(InjectionPoint ip) {
    Object result = null;
    ConfigProperty property = ip.getAnnotated().getAnnotation(ConfigProperty.class);
    PayaraConfig config = (PayaraConfig) ConfigProvider.getConfig();
    String name = property.name();
    if (name.isEmpty()) {
        // derive the property name from the injection point
        Class beanClass = null;
        Bean bean = ip.getBean();
        if (bean == null) {
            Member member = ip.getMember();
            beanClass = member.getDeclaringClass();
        } else {
            beanClass = bean.getBeanClass();
        }
        StringBuilder sb = new StringBuilder(beanClass.getCanonicalName());
        sb.append('.');
        sb.append(ip.getMember().getName());
        name = sb.toString();
    }
    Type type = ip.getType();
    if (type instanceof Class) {
        result = config.getValue(name, property.defaultValue(), (Class<?>) type);
    } else if (type instanceof ParameterizedType) {
        result = config.getValue(name, (Class<?>) ((ParameterizedType) type).getRawType());
    }
    if (result == null) {
        throw new DeploymentException("Microprofile Config Property " + property.name() + " can not be found");
    }
    return result;
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) DeploymentException(javax.enterprise.inject.spi.DeploymentException) PayaraConfig(fish.payara.nucleus.microprofile.config.spi.PayaraConfig) Member(java.lang.reflect.Member) Bean(javax.enterprise.inject.spi.Bean) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) Dependent(javax.enterprise.context.Dependent)

Example 2 with Dependent

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

the class TopologyWebAppDeploymentProducer method deployment.

@Produces
@Dependent()
Archive deployment() {
    String context = TopologyWebAppFraction.DEFAULT_CONTEXT;
    if (this.contextPath != null) {
        context = this.contextPath;
    }
    if (fraction.exposeTopologyEndpoint()) {
        WARArchive war = ShrinkWrap.create(WARArchive.class, "topology-webapp.war");
        war.addAsWebInfResource(new StringAsset(getWebXml(fraction)), "web.xml");
        war.addClass(TopologySSEServlet.class);
        war.addModule("swarm.application");
        war.addModule("org.wildfly.swarm.topology");
        war.addAsWebResource(new ClassLoaderAsset("topology.js", this.getClass().getClassLoader()), "topology.js");
        war.setContextRoot(context);
        war.as(TopologyArchive.class);
        return war;
    }
    return null;
}
Also used : StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) ClassLoaderAsset(org.jboss.shrinkwrap.api.asset.ClassLoaderAsset) WARArchive(org.wildfly.swarm.undertow.WARArchive) Produces(javax.enterprise.inject.Produces) Dependent(javax.enterprise.context.Dependent)

Example 3 with Dependent

use of javax.enterprise.context.Dependent in project core by weld.

the class BeanConfiguratorExtension method afterBeanDiscovery.

void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager manager) {
    event.addBean().scope(Dependent.class).addType(String.class).addQualifier(Juicy.Literal.INSTANCE).produceWith((i) -> {
        InjectionPoint ip = i.select(InjectionPoint.class).get();
        assertNotNull(ip);
        assertNotNull(ip.getBean());
        return ip.getBean().getBeanClass().getName();
    });
    event.addBean().scope(ApplicationScoped.class).addType(Map.class).addQualifier(Juicy.Literal.INSTANCE).produceWith((i) -> {
        try {
            i.select(InjectionPoint.class).get();
            fail("Cannot inject injection point metadata into non-dependent bean");
        } catch (IllegalArgumentException expected) {
        }
        return new HashMap<>();
    });
}
Also used : InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) HashMap(java.util.HashMap) Dependent(javax.enterprise.context.Dependent) ApplicationScoped(javax.enterprise.context.ApplicationScoped) IllegalArgumentException(org.jboss.weld.exceptions.IllegalArgumentException)

Example 4 with Dependent

use of javax.enterprise.context.Dependent in project core by weld.

the class InstanceImpl method destroy.

@Override
public void destroy(T instance) {
    checkNotNull(instance);
    // Attempt to destroy instance which is either a client proxy or a dependent session bean proxy
    if (instance instanceof ProxyObject) {
        ProxyObject proxy = (ProxyObject) instance;
        if (proxy.getHandler() instanceof ProxyMethodHandler) {
            ProxyMethodHandler handler = (ProxyMethodHandler) proxy.getHandler();
            Bean<?> bean = handler.getBean();
            if (isSessionBeanProxy(instance) && Dependent.class.equals(bean.getScope())) {
                // Destroy internal reference to a dependent session bean
                destroyDependentInstance(instance);
                return;
            } else {
                // Destroy contextual instance of a normal-scoped bean
                Context context = getBeanManager().getContext(bean.getScope());
                if (context instanceof AlterableContext) {
                    AlterableContext alterableContext = (AlterableContext) context;
                    alterableContext.destroy(bean);
                    return;
                } else {
                    throw BeanLogger.LOG.destroyUnsupported(context);
                }
            }
        }
    }
    // Attempt to destroy dependent instance which is neither a client proxy nor a dependent session bean proxy
    destroyDependentInstance(instance);
}
Also used : Context(javax.enterprise.context.spi.Context) CreationalContext(javax.enterprise.context.spi.CreationalContext) WeldCreationalContext(org.jboss.weld.contexts.WeldCreationalContext) AlterableContext(javax.enterprise.context.spi.AlterableContext) ProxyObject(org.jboss.weld.bean.proxy.ProxyObject) Dependent(javax.enterprise.context.Dependent) AlterableContext(javax.enterprise.context.spi.AlterableContext) ProxyMethodHandler(org.jboss.weld.bean.proxy.ProxyMethodHandler)

Example 5 with Dependent

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

the class DefaultConfigPropertyProducer method produceConfigSupplier.

@Produces
@Dependent
@ConfigProperty(name = "ignore")
public <C> Supplier<C> produceConfigSupplier(InjectionPoint injectionPoint) {
    ConfigProperty configProperty = getAnnotation(injectionPoint, ConfigProperty.class);
    if (configProperty == null) {
        throw new IllegalStateException("producer method called without @ConfigProperty being present!");
    }
    final Type injectionPointType = injectionPoint.getType();
    Type ipClass = null;
    if (injectionPointType instanceof ParameterizedType && ((ParameterizedType) injectionPointType).getActualTypeArguments().length == 1) {
        ipClass = ((ParameterizedType) injectionPointType).getActualTypeArguments()[0];
    } else {
        throw new IllegalStateException("Supplier for Configuration must be a Parameterized Type");
    }
    ConfigResolver.TypedResolver<C> resolver = asResolver(configProperty.name(), configProperty.defaultValue(), ipClass, configProperty.converter(), configProperty.parameterizedBy(), configProperty.projectStageAware(), configProperty.evaluateVariables());
    if (configProperty.cacheFor() > 0) {
        resolver.cacheFor(configProperty.cacheUnit(), configProperty.cacheFor());
    }
    return () -> resolver.getValue();
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ConfigResolver(org.apache.deltaspike.core.api.config.ConfigResolver) ConfigProperty(org.apache.deltaspike.core.api.config.ConfigProperty) Produces(javax.enterprise.inject.Produces) ConfigProperty(org.apache.deltaspike.core.api.config.ConfigProperty) 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