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;
}
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;
}
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<>();
});
}
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);
}
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();
}
Aggregations