use of org.jboss.weld.bootstrap.api.ServiceRegistry in project core by weld.
the class AdditionalServiceTest method testOverridingService.
@Test
public void testOverridingService() {
try (WeldContainer container = createWeld().addServices(new ExecutorServices2()).initialize()) {
ServiceRegistry registry = BeanManagerProxy.unwrap(container.getBeanManager()).getServices();
ExecutorServices executorServices = registry.get(ExecutorServices.class);
Assert.assertNotNull(executorServices);
Assert.assertTrue(executorServices instanceof ExecutorServices2);
}
}
use of org.jboss.weld.bootstrap.api.ServiceRegistry in project core by weld.
the class AdditionalServiceTest method testAdditionalServiceWithMultipleInterfaces.
@Test
public void testAdditionalServiceWithMultipleInterfaces() {
try (WeldContainer container = createWeld().addServices(new BravoImpl()).initialize()) {
ServiceRegistry registry = BeanManagerProxy.unwrap(container.getBeanManager()).getServices();
Bravo1Service bravo1 = registry.get(Bravo1Service.class);
Bravo2Service bravo2 = registry.get(Bravo2Service.class);
BravoImpl bravo3 = registry.get(BravoImpl.class);
assertNotNull(bravo1);
assertNotNull(bravo2);
assertNotNull(bravo3);
assertTrue(bravo1 == bravo2);
assertTrue(bravo2 == bravo3);
}
}
use of org.jboss.weld.bootstrap.api.ServiceRegistry in project core by weld.
the class AdditionalServiceTest method testSimpleAdditionalService.
@Test
public void testSimpleAdditionalService() {
try (WeldContainer container = createWeld().addServices(new AlphaImpl()).initialize()) {
ServiceRegistry registry = BeanManagerProxy.unwrap(container.getBeanManager()).getServices();
assertNotNull(registry.get(AlphaService.class));
assertTrue(registry.get(AlphaService.class) instanceof AlphaImpl);
assertNull(registry.get(AlphaImpl.class));
}
}
use of org.jboss.weld.bootstrap.api.ServiceRegistry in project core by weld.
the class VerifyingExtension method init.
void init(@Observes BeforeBeanDiscovery event, BeanManager manager) throws Exception {
ServiceRegistry services = BeanManagerProxy.unwrap(manager).getServices();
this.classFileServices = services.get(ClassFileServices.class);
this.resolver = new FastProcessAnnotatedTypeResolver(services.get(GlobalObserverNotifierService.class).getAllObserverMethods());
this.notifier = BeanManagerProxy.unwrap(manager).getGlobalLenientObserverNotifier();
this.discovery = services.get(RequiredAnnotationDiscovery.class);
this.transformer = services.get(ClassTransformer.class);
}
use of org.jboss.weld.bootstrap.api.ServiceRegistry in project wildfly by wildfly.
the class WeldDeployment method createAndRegisterAdditionalBeanDeploymentArchive.
protected BeanDeploymentArchiveImpl createAndRegisterAdditionalBeanDeploymentArchive(Module module, Class<?> beanClass) {
String id = null;
if (module == null) {
id = BOOTSTRAP_CLASSLOADER_BDA_ID;
} else {
id = module.getIdentifier() + ADDITIONAL_CLASSES_BDA_SUFFIX;
}
BeanDeploymentArchiveImpl newBda = new BeanDeploymentArchiveImpl(Collections.singleton(beanClass.getName()), Collections.singleton(beanClass.getName()), BeansXml.EMPTY_BEANS_XML, module, id, BeanArchiveType.SYNTHETIC, false);
WeldLogger.DEPLOYMENT_LOGGER.beanArchiveDiscovered(newBda);
newBda.addBeanClass(beanClass);
ServiceRegistry newBdaServices = newBda.getServices();
for (Entry<Class<? extends Service>, Service> entry : serviceRegistry.entrySet()) {
// Do not overwrite existing services
if (!newBdaServices.contains(entry.getKey())) {
newBdaServices.add(entry.getKey(), Reflections.cast(entry.getValue()));
}
}
if (module == null) {
// For bootstrapClassLoaderBeanDeploymentArchive always use the parent ResourceLoader
newBdaServices.add(ResourceLoader.class, serviceRegistry.get(ResourceLoader.class));
}
if (module != null && eeModuleDescriptors.containsKey(module.getIdentifier())) {
newBda.getServices().add(EEModuleDescriptor.class, eeModuleDescriptors.get(module.getIdentifier()));
}
// handle BDAs visible from the new BDA
for (BeanDeploymentArchiveImpl bda : beanDeploymentArchives) {
if (newBda.isAccessible(bda)) {
newBda.addBeanDeploymentArchive(bda);
}
}
// handle visibility of the new BDA from other BDAs
for (BeanDeploymentArchiveImpl bda : beanDeploymentArchives) {
if (bda.isAccessible(newBda)) {
bda.addBeanDeploymentArchive(newBda);
}
}
// make the top-level deployment BDAs visible from the additional archive
newBda.addBeanDeploymentArchives(rootBeanDeploymentModule.getBeanDeploymentArchives());
// Ignore beans loaded by the bootstrap class loader. This should only be JDK classes in most cases.
// See getBeanDeploymentArchive(final Class<?> beanClass), per the JavaDoc this is mean to archive which
// contains the bean class.
final ClassLoader cl = beanClass.getClassLoader();
if (cl != null) {
additionalBeanDeploymentArchivesByClassloader.put(cl, newBda);
}
beanDeploymentArchives.add(newBda);
return newBda;
}
Aggregations