/** * Gets the {@link BeanManager} linked to the root bean deployment archive. This BeanManager has access to all beans in a * deployment * * @throws IllegalStateException if the container is not running */ public BeanManagerImpl getBeanManager() { if (!started) { throw WeldLogger.ROOT_LOGGER.notStarted("WeldContainer"); } return bootstrap.getManager(rootBeanDeploymentArchive); }
/** * Gets the {@link BeanManager} for a given bean deployment archive id. * * @throws IllegalStateException if the container is not running * @throws IllegalArgumentException if the bean deployment archive id is not found */ public BeanManagerImpl getBeanManager(String beanArchiveId) { if (!started) { throw WeldLogger.ROOT_LOGGER.notStarted("WeldContainer"); } BeanDeploymentArchive beanDeploymentArchive = beanDeploymentArchives.get(beanArchiveId); if (beanDeploymentArchive == null) { throw WeldLogger.ROOT_LOGGER.beanDeploymentNotFound(beanArchiveId); } return bootstrap.getManager(beanDeploymentArchive); }
private void firePITEvent(WeldBootstrap bootstrap, BeanDeploymentArchive bda, Class<?> bdaClazz) { //Fix for issue GLASSFISH-17464 //The PIT event should not be fired for interfaces if(bdaClazz.isInterface()){ return; } AnnotatedType<?> at = bootstrap.getManager(bda).createAnnotatedType(bdaClazz); InjectionTarget<?> it = bootstrap.getManager(bda).fireProcessInjectionTarget(at); ((BeanDeploymentArchiveImpl)bda).putInjectionTarget(at, it); }
/** * Gets the {@link BeanManager} linked to the additional classes bean deployment archive. This BeanManager has access to all * beans in a deployment * * @throws IllegalStateException if the container is not running */ public BeanManager getBeanManager() { if (!started) { throw WeldMessages.MESSAGES.notStarted("WeldContainer"); } return bootstrap.getManager(deployment.getAdditionalBeanDeploymentArchive()); }
/** * Gets the {@link BeanManager} for a given bean deployment archive id. * * @throws IllegalStateException if the container is not running * @throws IllegalArgumentException if the bean deployment archive id is not found */ public BeanManager getBeanManager(String beanArchiveId) { if (!started) { throw WeldMessages.MESSAGES.notStarted("WeldContainer"); } BeanDeploymentArchive beanDeploymentArchive = beanDeploymentArchives.get(beanArchiveId); if (beanDeploymentArchive == null) { throw WeldMessages.MESSAGES.beanDeploymentNotFound(beanArchiveId); } return bootstrap.getManager(beanDeploymentArchive); }
@SuppressWarnings("unchecked") public void decorate(T webComponent, WebModule wm) { if (wm.getWebBundleDescriptor().hasExtensionProperty(WeldDeployer.WELD_EXTENSION)) { DeploymentContext deploymentContext = wm.getWebModuleConfig().getDeploymentContext(); WeldBootstrap weldBootstrap = deploymentContext.getTransientAppMetaData( WeldDeployer.WELD_BOOTSTRAP, org.jboss.weld.bootstrap.WeldBootstrap.class); DeploymentImpl deploymentImpl = deploymentContext.getTransientAppMetaData( WeldDeployer.WELD_DEPLOYMENT, DeploymentImpl.class); Collection<BeanDeploymentArchive> deployments = deploymentImpl.getBeanDeploymentArchives(); BeanDeploymentArchive beanDeploymentArchive = deployments.iterator().next(); BeanManager beanManager = weldBootstrap.getManager(beanDeploymentArchive); // PENDING : Not available in this Web Beans Release CreationalContext<T> ccontext = beanManager.createCreationalContext(null); @SuppressWarnings("rawtypes") Class<T> clazz = (Class<T>) webComponent.getClass(); AnnotatedType<T> annotatedType = beanManager.createAnnotatedType(clazz); InjectionTarget<T> injectionTarget = beanManager.createInjectionTarget(annotatedType); injectionTarget.inject(webComponent, ccontext); } } }
/** * Perform 299 style injection on the <code>managedObject</code> argument. * @param managedObject the managed object * @param bundle the bundle descriptor */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void injectManagedObject(Object managedObject, BundleDescriptor bundle) { BundleDescriptor topLevelBundleDesc = (BundleDescriptor) bundle.getModuleDescriptor().getDescriptor(); // First get BeanDeploymentArchive for this ejb BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(topLevelBundleDesc); //BeanDeploymentArchive bda = getBDAForBeanClass(topLevelBundleDesc, managedObject.getClass().getName()); WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication()); BeanManager beanManager = bootstrap.getManager(bda); AnnotatedType annotatedType = beanManager.createAnnotatedType(managedObject.getClass()); InjectionTarget it = beanManager.createInjectionTarget(annotatedType); CreationalContext cc = beanManager.createCreationalContext(null); it.inject(managedObject, cc); }
WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication()); beanManager = bootstrap.getManager(bda);
private void createBeanManager() { bootstrap = new WeldBootstrap(); BundleDeployment deployment = new BundleDeployment(getBundle(), bootstrap, getContextClassLoader()); BeanDeploymentArchive beanDeploymentArchive = deployment.getBeanDeploymentArchive(); pause(); String contextId = getBundle().getSymbolicName() + ":" + getBundle().getBundleId(); ExternalConfigurationBuilder configurationBuilder = new ExternalConfigurationBuilder() // Use relaxed construction by default .add(ConfigurationKey.RELAXED_CONSTRUCTION.get(), true) .add(ConfigurationKey.CONCURRENT_DEPLOYMENT.get(), false); deployment.getServices() .add(ExternalConfiguration.class, configurationBuilder.build()); bootstrap.startContainer(contextId, OsgiEnvironment.getInstance(), deployment); // Add the ProxyServices service: we rely on the BeanManager to use its annotated // types cache to discover type closures which is required for proxied beans // whose type closures span multiple bundles deployment.getServices() .add(ProxyServices.class, new OsgiProxyService( bootstrap.getManager(beanDeploymentArchive), getContextClassLoader())); bootstrap.startInitialization(); bootstrap.deployBeans(); bootstrap.validateBeans(); manager = bootstrap.getManager(beanDeploymentArchive); resume(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) public <T> JCDIInjectionContext<T> createManagedObject(Class<T> managedClass, BundleDescriptor bundle, boolean invokePostConstruct) { Object managedObject = null; BundleDescriptor topLevelBundleDesc = (BundleDescriptor) bundle.getModuleDescriptor().getDescriptor(); // First get BeanDeploymentArchive for this ejb BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(topLevelBundleDesc); WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication()); BeanManager beanManager = bootstrap.getManager(bda); AnnotatedType annotatedType = beanManager.createAnnotatedType(managedClass); if (!invokePostConstruct) { annotatedType = new NoPostConstructPreDestroyAnnotatedType(annotatedType); } InjectionTarget it = ((BeanDeploymentArchiveImpl)bda).getInjectionTarget(annotatedType); if (it == null) { it = ( ( WeldManager ) beanManager ).fireProcessInjectionTarget( annotatedType ); } CreationalContext cc = beanManager.createCreationalContext(null); managedObject = it.produce(cc); it.inject(managedObject, cc); if( invokePostConstruct ) { it.postConstruct(managedObject); } return new JCDIInjectionContextImpl(it, cc, managedObject); }
WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication()); beanManager = bootstrap.getManager(bda);
@Before public void setup() throws Exception { Deployment deployment = createDeployment(Service.class, Cat.class, CatService.class, Dog.class, DogService.class); bootstrap = new WeldBootstrap(); bootstrap.startContainer(Environments.SE, deployment, new ConcurrentHashMapBeanStore()) .startInitialization() .deployBeans() .validateBeans() .endInitialization(); manager = bootstrap.getManager(deployment.getBeanDeploymentArchives().iterator().next()); enricher = new CDIInjectionEnricher() { protected BeanManager lookupBeanManager() { return manager; } }; }
WeldManager weldManager = bootstrap.getManager(bda);
.endInitialization(); WeldManager manager = bootstrap.getManager(beanArchive);
WeldManager beanManager = bootstrap.getManager(bda);