use of javax.enterprise.inject.spi.Bean in project Activiti by Activiti.
the class BusinessProcessContext method get.
@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> arg1) {
Bean<T> bean = (Bean<T>) contextual;
String variableName = bean.getName();
BusinessProcess businessProcess = getBusinessProcess();
Object variable = businessProcess.getVariable(variableName);
if (variable != null) {
if (logger.isDebugEnabled()) {
if (businessProcess.isAssociated()) {
logger.debug("Getting instance of bean '{}' from Execution[{}]", variableName, businessProcess.getExecutionId());
} else {
logger.debug("Getting instance of bean '{}' from transient bean store", variableName);
}
}
return (T) variable;
} else {
if (logger.isDebugEnabled()) {
if (businessProcess.isAssociated()) {
logger.debug("Creating instance of bean '{}' in business process context representing Execution[{}]", variableName, businessProcess.getExecutionId());
} else {
logger.debug("Creating instance of bean '{}' in transient bean store", variableName);
}
}
T beanInstance = bean.create(arg1);
businessProcess.setVariable(variableName, beanInstance);
return beanInstance;
}
}
use of javax.enterprise.inject.spi.Bean in project aries by apache.
the class Phase_Publish method processRequirementDefinedServices.
private void processRequirementDefinedServices(BeanManagerImpl beanManagerImpl) {
Collection<ServiceModel> serviceModels = _bc.getServiceModels();
for (ServiceModel serviceModel : serviceModels) {
try {
Class<?> beanClass = _bc.loadClass(serviceModel.getBeanClass());
Set<Bean<?>> beans = beanManagerImpl.getBeans(beanClass, AnyLiteral.INSTANCE);
if (beans.isEmpty()) {
_log.error("CDIe - MANIFEST service processing cannot find bean for class {}", serviceModel.getBeanClass());
continue;
}
Bean<?> bean = beanManagerImpl.resolve(beans);
CreationalContext<?> creationalContext = beanManagerImpl.createCreationalContext(bean);
List<String> provides = serviceModel.getProvides();
List<Class<?>> interfaces = new ArrayList<>();
for (String provide : provides) {
try {
interfaces.add(_bc.loadClass(provide));
} catch (Exception e) {
_log.error("CDIe - Failure loading provided interface for service {}", provide);
}
}
ServiceDeclaration serviceDeclaration = new ServiceDeclaration(ServiceLiteral.from(interfaces.toArray(new Class<?>[interfaces.size()]), serviceModel.getProperties()), bean, creationalContext);
processServiceDeclaration(serviceDeclaration);
} catch (ClassNotFoundException cnfe) {
_log.error("CDIe - MANIFEST service processing cannot load class {}", serviceModel.getBeanClass(), cnfe);
}
}
}
use of javax.enterprise.inject.spi.Bean in project aries by apache.
the class OSGiBeanDescriptorTests method testReferences.
@SuppressWarnings("serial")
public void testReferences() throws Exception {
Bundle tb1Bundle = installBundle("tb1.jar");
Bundle tb2Bundle = installBundle("tb2.jar");
CdiContainer cdiContainer = waitForCdiContainer(tb1Bundle.getBundleId());
try {
BeanManager beanManager = cdiContainer.getBeanManager();
Set<Bean<?>> beans = beanManager.getBeans("beanimpl");
Bean<?> bean = beanManager.resolve(beans);
CreationalContext<?> ctx = beanManager.createCreationalContext(bean);
BeanService<?> beanService = (BeanService<?>) beanManager.getReference(bean, new TypeLiteral<BeanService<?>>() {
}.getType(), ctx);
assertNotNull(beanService);
assertEquals("POJO-IMPLBEAN-IMPL", beanService.doSomething());
} finally {
tb2Bundle.uninstall();
tb1Bundle.uninstall();
}
}
use of javax.enterprise.inject.spi.Bean in project aries by apache.
the class ConfigurationTests method testNamedConfiguration.
@SuppressWarnings({ "unchecked", "serial" })
public void testNamedConfiguration() throws Exception {
Bundle tb3Bundle = installBundle("tb3.jar");
Configuration configurationA = null, configurationB = null;
try {
configurationA = configurationAdmin.getConfiguration("configA", "?");
Dictionary<String, Object> properties = new Hashtable<>();
properties.put("ports", new int[] { 12, 4567 });
configurationA.update(properties);
configurationB = configurationAdmin.getConfiguration("configB", "?");
properties = new Hashtable<>();
properties.put("color", "green");
properties.put("ports", new int[] { 80 });
configurationB.update(properties);
Filter filter = bundleContext.createFilter("(&(objectClass=" + CdiContainer.class.getName() + ")(service.bundleid=" + tb3Bundle.getBundleId() + ")(" + CdiConstants.CDI_CONTAINER_STATE + "=CREATED))");
ServiceTracker<CdiContainer, CdiContainer> st = new ServiceTracker<>(bundleContext, filter, null);
st.open();
CdiContainer container = st.waitForService(timeout);
assertNotNull(container);
int t = st.getTrackingCount();
BeanManager beanManager = container.getBeanManager();
Set<Bean<?>> beans = beanManager.getBeans("configB");
assertNotNull(beans);
Bean<? extends Object> bean = beanManager.resolve(beans);
CreationalContext<?> ctx = beanManager.createCreationalContext(bean);
Map<String, Object> config = (Map<String, Object>) beanManager.getReference(bean, new TypeLiteral<Map<String, Object>>() {
}.getType(), ctx);
assertNotNull(config);
assertEquals("green", config.get("color"));
assertArrayEquals(new int[] { 80 }, (int[]) config.get("ports"));
configurationA.delete();
while (t == st.getTrackingCount()) {
Thread.sleep(10);
}
assertTrue(st.isEmpty());
st.close();
filter = bundleContext.createFilter("(&(objectClass=" + CdiContainer.class.getName() + ")(service.bundleid=" + tb3Bundle.getBundleId() + ")(" + CdiConstants.CDI_CONTAINER_STATE + "=" + CdiEvent.Type.WAITING_FOR_CONFIGURATIONS + "))");
st = new ServiceTracker<>(bundleContext, filter, null);
st.open();
assertFalse(st.isEmpty());
} finally {
if (configurationB != null) {
try {
configurationB.delete();
} catch (Exception e) {
// ignore
}
}
tb3Bundle.uninstall();
}
}
use of javax.enterprise.inject.spi.Bean in project aries by apache.
the class EventsTests method testEventsGetSent.
public void testEventsGetSent() throws Exception {
BeanManager beanManager = cdiContainer.getBeanManager();
assertNotNull(beanManager);
@SuppressWarnings("serial") Set<Bean<?>> beans = beanManager.getBeans(Object.class, new AnnotationLiteral<CdiEventObserverQualifier>() {
});
Bean<?> bean = beanManager.resolve(beans);
CreationalContext<?> ctx = beanManager.createCreationalContext(bean);
Object bcb = beanManager.getReference(bean, Object.class, ctx);
assertNotNull(bcb);
@SuppressWarnings("unchecked") BeanService<List<CdiEvent>> bti = (BeanService<List<CdiEvent>>) bcb;
List<CdiEvent> list = bti.get();
assertNotNull(list);
assertEquals(3, list.size());
}
Aggregations